Beispiel #1
0
 def format_journal(self, e):
     if 'doi' not in e.fields:
         return field('journal')
     else:
         return href[join['https://doi.org/',
                          field('doi', raw=True)],
                     field('journal')]
 def get_article_template(self, e):
     # Required fields: author, title, journal, year
     # Optional fields: volume, number, pages, month, note, key
     volume_and_pages = first_of[
         # Volume and pages, with optional issue number
         optional[
             join[
                 self.format_volume(e, for_article=True),
                 optional[', ', field('pages')]
             ],
         ],
         # Pages only
         pages,
     ]
     template = toplevel[
         self.format_names('author'),
         sentence[
             join["(", date, ")"]
         ],
         self.format_title(e, 'title'),
         sentence[
             tag('em')[field('journal')],
             optional[volume_and_pages],
         ],
         sentence[optional_field('note')],
         self.format_web_refs(e),
     ]
     return template
Beispiel #3
0
 def format_volume_and_series(self, e, as_sentence=True):
     # FIXME: evaluate the field 'language' and translate
     volume_and_series = optional [
         words [
             'volume', field('volume'), optional [
                 words ['of', field('series')]
             ]
         ]
     ]
     number_and_series = optional [
         words [
             join(sep=Symbol('nbsp')) ['number', field('number')],
             optional [
                 words ['in', field('series')]
             ]
         ]
     ]
     series = optional_field('series')
     result = first_of [
             volume_and_series,
             number_and_series,
             series,
         ]
     if as_sentence:
         return sentence(capfirst=True) [result]
     else:
         return result
 def get_inbook_template(self, e):
     # Required fields: author/editor, title, chapter/pages, publisher, year
     # Optional fields: volume, series, address, edition, month, note, key
     return toplevel[
         sentence(sep=' ')[
             self.format_names('author'),
             join["(", date, ")"]
         ],
         self.format_title(e, 'title'),
         sentence(sep=' ')[
             optional[
                 "In ",
                 editor_names(),
                 ","
             ],
             self.format_btitle(e, 'booktitle', as_sentence=False),
             optional[
                 join[
                     "(",
                     sentence(add_period=False)[
                         optional[field('edition'), ' ed.'],
                         self.format_volume(e),
                         pages,
                     ],
                     ")"
                 ]
             ]
         ],
         sentence(sep=': ')[
             optional_field('address'),
             field('publisher'),
         ],
         sentence[optional_field('note')],
     ]
 def format_inbook(self, e):
     template = toplevel [
         tag('pubtitle') [tag('b') [field('title')]],
         Symbol('br'),
         sentence [self.format_names('author')],
         self.format_volume_and_series(e),
         Symbol('br'),
         words [
             sentence(capfirst=True) [
                 self.format_chapter_and_pages(e),
                 #optional[ self.format_editor(e, as_sentence=False) ],
                 self.format_btitle(e, 'booktitle', as_sentence=False),
                 #self.format_volume_and_series(e, as_sentence=False),
                 #self.format_chapter_and_pages(e),
             ],
         Symbol('br'),
         sentence [
             field('publisher'),
             optional_field('address'),
             optional [
                 words [field('edition'), 'edition']
             ],
             #date,
             #Symbol('br'),
             #optional_field('note'),
             ],
         ],
         Symbol('br'),
         sentence [
             optional_field('note'),
         ],
         Symbol('br'),
         #self.format_web_refs(e),
     ]
     return template.format_data(e)
 def format_patent(self, e):
     template = toplevel [
         self.format_names('author'),
         self.format_title(e, 'title'),
         join [tag('emph') [field('number')], ' ', '(', field('year'), ')']
     ]
     return template.format_data(e)
 def format_article(self, e):
     volume_and_pages = first_of [
         # volume and pages, with optional issue number
         optional [
             join [
                 field('volume'),
                 optional['(', field('number'),')'],
                 ':', pages
             ],
         ],
         # pages only
         words ['pages', pages],
     ]
     template = toplevel [
         self.format_title(e, 'title'),
         Symbol('br'),
         self.format_names('author'),
         Symbol('br'),
         tag('journal') [tag('b') [field('journal')]],
         optional[ volume_and_pages ], 
         Symbol('br'),
         optional [
             words [
                 field('note'),
                 Symbol('br')  
             ]
         ],
         #self.format_web_refs(e),
         #sentence(capfirst=False) [ optional_field('note') ],
     ]
     return template.format_data(e)
Beispiel #8
0
 def format_volume(self, e, for_article=False):
     prefix = "Vol."
     if for_article:
         return optional[tag('em')[field('volume')],
                         optional['(', field('number'), ')'], ]
     else:
         return optional[together[prefix, field('volume')]]
Beispiel #9
0
 def format_volume_and_series(self, e, as_sentence=True):
     volume_and_series = optional [
         words [
             'volume', field('volume'), optional [
                 words ['of', field('series')]
             ]
         ]
     ]
     number_and_series = optional [
         words [
             join(sep=Symbol('nbsp')) ['number', field('number')],
             optional [
                 words ['in', field('series')]
             ]
         ]
     ]
     series = optional_field('series')
     result = first_of [
             volume_and_series,
             number_and_series,
             series,
         ]
     if as_sentence:
         return sentence(capfirst=False) [result]
     else:
         return result
Beispiel #10
0
 def get_article_template(self, e):
     volume_and_pages = first_of[
         # volume and pages, with optional issue number
         optional[
             join[
                 field('volume'),
                 optional['(', field('number'), ')'],
                 ':', pages
             ],
         ],
         # pages only
         words['pages', pages],
     ]
     template = toplevel[
         self.format_bold_title(e, 'title'),
         Symbol('newline'),
         self.format_names('author'),
         Symbol('newline'),
         sentence[
             tag('em')[field('journal')],
             optional[volume_and_pages],
             date],
         sentence[optional_field('note')],
         self.format_web_refs(e),
     ]
     return template
Beispiel #11
0
 def format_pages(self, e):
     if 'eprint' not in e.fields:
         return field('pages', apply_func=dashify)
     else:
         return href[join['https://arxiv.org/abs/',
                          field('eprint', raw=True)],
                     field('pages', apply_func=dashify)]
Beispiel #12
0
 def format_book(self, e):
     template = toplevel [
         self.format_author_or_editor(e),
         tag('emph') [sentence [field('title')]],
         self.format_volume_and_series(e),
         sentence [field('publisher'), date],
     ]
     return template.format_data(e)
Beispiel #13
0
 def format_url(self, e):
     # based on urlbst format.url
     return href [
         field('url'),
         join(' ') [
             'URL:',
             field('url')
             ]
         ]
Beispiel #14
0
 def format_url(self, e):
     # Based on urlbst format.url
     return words[
         'URL:',
         href[
             field('url', raw=True),
             field('url', raw=True)
         ]
     ]
 def format_url(self, e):
     # based on urlbst format.url
     return href [
         field('url'),
         join(' ') [
             'URL:',
             field('url')
             ]
         ]
Beispiel #16
0
 def format_chapter_and_pages(self, e):
     return join(sep=', ') [
         field('title', apply_func=dquote),
         words [
             optional [words ['chapter', field('chapter'), 'of']],
             tag('emph') [field('booktitle')]
         ],
         optional [words ['pages', pages]],
     ]
Beispiel #17
0
 def format_dsa(self, e):
     # based on urlbst format.dsa
     return words['DSA:',
                  href[join['https://datasheet.datasheetarchive.com/',
                            field('dsa'), '.pdf'],
                       field('dsa', apply_func=lambda x: x.split('/')[-1])],
                  join[sentence(capfirst=False, add_period=False)[
                      '(PDF',
                      optional_field('dsasize'),
                      optional_field('dsadate'), ], ')']]
Beispiel #18
0
 def format_doi(self, e):
   return href [
     join [
       'https://doi.org/',
       field('doi')
     ],
     join [
       'doi:',
       field('doi')
     ]
   ]
Beispiel #19
0
 def format_patent(self, e):
     template = toplevel [
         self.format_title(e, 'title'),
         sentence(capfirst=False) [ date, ],
         href [
             field('howpublished'),
             sentence(capfirst=False) [ field('note') ],
         ],
         self.format_web_refs(e),
     ]
     return template.format_data(e)
 def format_article(self, e):
     template = toplevel [
         self.format_names('author'),
         self.format_title(e, 'title'),
         join [tag('emph') [field('journal')], ' ',
             tag('strong')[field('volume')], ', ', unsrt.pages,
             ' (', field('year'), ')'],
         sentence(capfirst=False) [ optional_field('note') ],
         self.format_web_refs(e),
         ]
     return template.format_data(e)
Beispiel #21
0
 def get_book_template(self, e):
     template = toplevel[self.format_author_or_editor(e),
                         self.format_btitle(e, 'title'),
                         self.format_volume_and_series(e),
                         sentence[join[field('publisher'),
                                       optional[', ',
                                                field('address')], ' (',
                                       field('year'), ')']],
                         optional[sentence[self.format_isbn(e)]],
                         self.format_web_refs(e), ]
     return template
Beispiel #22
0
 def get_inbook_template(self, e):
     template = toplevel[self.format_author_or_editor(e), sentence[
         self.format_btitle(e, 'title', as_sentence=False),
         self.format_chapter_and_pages(e), ],
                         self.format_volume_and_series(e),
                         sentence[field('publisher'),
                                  optional_field('address'),
                                  optional[words[field('edition'),
                                                 'edition']], date,
                                  optional_field('note'), ],
                         self.format_web_refs(e), ]
     return template
Beispiel #23
0
 def format_doi(self, e):
     # Based on urlbst format.doi
     return href[
         join[
             'https://doi.org/',
             field('doi', raw=True)
         ],
         join[
             'doi:',
             field('doi', raw=True)
         ]
     ]
Beispiel #24
0
 def format_oclc(self, e):
     # based on numbst format.oclc
     return words [
         'OCLC:',
         href [
             join [
                 'https://www.worldcat.org/oclc/',
                 field('oclc')
                 ],
             field('oclc')
             ]
         ]
Beispiel #25
0
 def format_url(self, e):
     # based on urlbst format.url
     return words [
         'URL:',
         href [
             field('url'),
             field('url')
             ],
         join [
             optional [ '(', field('urldate'), ')' ]
             ]
         ]
Beispiel #26
0
 def format_isbn13(self, e):
     # based on numbst format.isbn13
     return words [
         'ISBN-13:',
         href [
             join [
                 'https://www.gettextbooks.com/isbn/',
                 field('isbn13')
                 ],
             field('isbn13')
             ]
         ]
Beispiel #27
0
    def format_entries(self, entries):
        """Override for appending links before yielding ``FormattedEntries``.
        :param entries: `BibliographyData` entries
        :type entries:  BibliographyData
        """
        if 'groupby' in plugin_data:
            sorter = plugin_data['groupby']
            group_name_dict = plugin_data.get('mapping_%s' % sorter, {})
            grouped_entries = group_entries_by_key(entries, sorter,
                                                   group_name_dict)
        else:
            grouped_entries = {'ALL': list(entries)}

        for group_name, group in grouped_entries.items():
            sorted_entries = self.sort(group)
            labels = list(self.format_labels(sorted_entries))
            for label, entry in zip(labels, sorted_entries):
                for persons in entry.persons.itervalues():
                    for person in persons:
                        person.text = self.format_name(person,
                                                       self.abbreviate_names)

                f = getattr(self, "format_" + entry.type)
                text = f(entry)

                bib = optional[join[
                    '[',
                    tag('tt')[href[field('publipy_biburl', raw=True),
                                   'bib']], ']']]

                pdf = optional[join[
                    '[',
                    tag('tt')[href[field('publipy_pdfurl', raw=True),
                                   'pdf']], ']']]

                abstract = optional[join[
                    '[',
                    tag('tt')[href[field('publipy_abstracturl', raw=True),
                                   'abstract']], ']']]

                www = join['[',
                           tag('tt')[href[field('url_home', raw=True), 'www']],
                           ']']

                text += ' '  # make some space
                if entry.fields['url_home']:
                    text += join(sep=' ')[bib, pdf, abstract,
                                          www].format_data(entry)
                else:
                    text += join(sep=' ')[bib, pdf,
                                          abstract].format_data(entry)

                yield group_name, FormattedEntry(entry.key, text, label)
Beispiel #28
0
 def format_article(self, e):
     volume_and_pages = first_of [
         join [field('volume'), optional [':', pages]],
         words ['pages', optional [pages]]
     ]
     template = toplevel [
         self.format_names('author'),
         sentence [field('title')],
         sentence [
             tag('emph') [field('journal')], volume_and_pages, date],
     ]
     return template.format_data(e)
Beispiel #29
0
 def format_doi(self, e):
     # based on urlbst format.doi
     return href [
         join [
             'http://dx.doi.org/',
             field('doi')
             ],
         join [
             'doi:',
             field('doi')
             ]
         ]
Beispiel #30
0
 def format_doi(self, e):
     # based on urlbst format.doi
     return href [
         join [
             'http://dx.doi.org/',
             field('doi')
             ],
         join [
             'doi:',
             field('doi')
             ]
         ]
Beispiel #31
0
 def format_pubmed(self, e):
     # based on urlbst format.pubmed
     return href [
         join [
             'http://www.ncbi.nlm.nih.gov/pubmed/',
             field('pubmed')
             ],
         join [
             'PMID:',
             field('pubmed')
             ]
         ]
Beispiel #32
0
 def format_pubmed(self, e):
     # based on urlbst format.pubmed
     return href [
         join [
             'http://www.ncbi.nlm.nih.gov/pubmed/',
             field('pubmed')
             ],
         join [
             'PMID:',
             field('pubmed')
             ]
         ]
Beispiel #33
0
 def format_inbook(self, e):
     template = toplevel[sentence[self.format_names('author')],
                         sentence[self.format_btitle(e, 'title'),
                                  self.format_chapter_and_pages(e), ],
                         self.format_volume_and_series(e),
                         sentence[field('publisher'),
                                  optional_field('address'),
                                  optional[words[field('edition'),
                                                 'edition']], date,
                                  optional_field('note'), ],
                         self.format_web_refs(e), ]
     return template.format_data(e)
Beispiel #34
0
 def format_eprint(self, e):
     # based on urlbst format.eprint
     return href [
         join [
             'http://arxiv.org/abs/',
             field('eprint')
             ],
         join [
             'arXiv:',
             field('eprint')
             ]
         ]
Beispiel #35
0
 def format_ghd(self, e):
     # based on urlbst format.ghd
     return words['GDR-HC Download:', href[
         join['https://hc-ddr.hucki.net/wiki/lib/exe/fetch.php/',
              field('ghd')],
         field('ghd',
               apply_func=lambda x: x.split('/')[-1].split('.', 1)[0])],
                  join['(',
                       sentence(capfirst=False, add_period=False)[
                           optional_field('ghdtype'),
                           optional_field('ghdsize'),
                           optional_field('ghddate')], ')']]
Beispiel #36
0
 def format_lpns(self, e):
     # based on urlbst format.dsa
     return words['Li-Pro.Net Store:', href[
         join['http://store.li-pro.net/',
              field('lpns')],
         field('lpns',
               apply_func=lambda x: x.split('/')[-1].split('.', 1)[0])],
                  join['(',
                       sentence(capfirst=False, add_period=False)[
                           optional_field('lpnstype'),
                           optional_field('lpnssize'),
                           optional_field('lpnsdate')], ')']]
Beispiel #37
0
 def format_eprint(self, e):
     # based on urlbst format.eprint
     return href [
         join [
             'http://arxiv.org/abs/',
             field('eprint')
             ],
         join [
             'arXiv:',
             field('eprint')
             ]
         ]
Beispiel #38
0
    def get_article_template(self, e):
        volume_and_pages = first_of[optional[join[tag('b')[field('volume')],
                                                  ', ', pages], ],
                                    words['pages', pages], ]
        template = toplevel[join[self.format_names('author'), ", "],
                            join[tag('em')[field('journal')], " ",
                                 optional[volume_and_pages], " (",
                                 field('year'), ")"], ]
        return template

        def format_web_refs(self, e):
            # we just leave the doi
            return optional[join['doi:', field('doi', raw=True)]]
Beispiel #39
0
 def format_gsc(self, e):
     # based on urlbst format.gsc
     return words['GDR-Semiconductor:', href[join[
         'https://www-user.tu-chemnitz.de/~heha/basteln/Konsumg%C3%BCter/DDR-Halbleiter/',
         field('gsc')],
                                             field('gsc',
                                                   apply_func=lambda x: x.
                                                   split('/')[-1].split(
                                                       '.', 1)[0])],
                  join['(',
                       sentence(capfirst=False, add_period=False)[
                           optional_field('gsctype'),
                           optional_field('gscsize'),
                           optional_field('gscdate')], ')']]
Beispiel #40
0
 def format_article(self, e):
     volume_and_pages = first_of [
         join [ optional [ 'vol. ', field('volume'), ', '],
                optional [ words [ 'no.', field('number') ] ],
                optional [': ', pages] ],
         optional [ words ['pages', pages] ]
     ]
     template = toplevel [
         self.format_names('author'),
         sentence [field('title', apply_func=dquote)],
         sentence [
             tag('emph') [field('journal')], volume_and_pages, date],
     ]
     return template.format_data(e)
Beispiel #41
0
 def format_article(self, entry):
     #author = entry.fields['author']
     if 'volume' in entry.fields:
         volume_and_pages = join [field('volume'), optional [':', 'pages']]
     else:
         volume_and_pages = words ['pages', optional ['pages']]
     #import pdb
     #pdb.set_trace()
     template = toplevel [
         self.format_name(entry.persons['author'][0]),
         sentence [field('title')],
         sentence [
             tag('emph') [field('journal')], volume_and_pages, field('year')],
     ]
     return template.format_data(entry)
Beispiel #42
0
 def get_article_template(self, e):
     template = toplevel[
         first_name('author'),
         field('title'), '/',
         names('author', sep=', '), '//',
         sentence(sep='. – ')[
             tag('em')[field('journal')],
             date,
             optional[join[words['V.', field('volume')],
                           optional[words[', Is.', field('number')]],
                           optional[words['. – P.', pages]]]]],
         sentence(sep=' ')[optional[self.format_doi(e)],
                           optional[join['(', field('note'), ')']]]
     ]
     return template
Beispiel #43
0
 def format_address_organization_publisher_date(
     self, e, include_organization=True):
     """Format address, organization, publisher, and date.
     Everything is optional, except the date.
     """
     # small difference from unsrt.bst here: unsrt.bst
     # starts a new sentence only if the address is missing;
     # for simplicity here we always start a new sentence
     if include_organization:
         organization = optional_field('organization')
     else:
         organization = None
     return first_of[
         # this will be rendered if there is an address
         optional [
             join(sep=' ') [
                 sentence[
                     field('address'),
                     date,
                 ],
                 sentence[
                     organization,
                     optional_field('publisher'),
                 ],
             ],
         ],
         # if there is no address then we have this
         sentence[
             organization,
             optional_field('publisher'),
             date,
         ],
     ]
Beispiel #44
0
 def format_inbook(self, e):
     template = toplevel [
         sentence [self.format_names('author')],
         sentence [self.format_chapter_and_pages(e)],
         self.format_volume_and_series(e),
         sentence [
             field('publisher'),
             optional_field('address'),
             optional [
                 words [field('edition'), 'edition']
             ],
             date,
             optional_field('note'),
         ]
     ]
     return template.format_data(e)
Beispiel #45
0
 def format_misc(self, e):
     template = toplevel [
          sentence [self.format_names('author')],
          sentence [field('title')],
          sentence [date]
     ]
     return template.format_data(e)
Beispiel #46
0
    def format_title(self, e, which_field, as_sentence=True):

        def protected_capitalize(x):
            """Capitalize string, but protect {...} parts."""

            result = Text()
            level = 0
            for pos, c in enumerate(x):
                if c == '{':
                    level += 1
                    c = ''
                elif c == '}':
                    level -= 1
                    c = ''
                elif pos == 0:
                    c = c.upper()
                elif level <= 0:
                    c = c.lower()

                result += c

            return result

        formatted_title = field(
            which_field, apply_func=protected_capitalize)
        if as_sentence:
            return sentence(capfirst=False) [ formatted_title ]
        else:
            return formatted_title
Beispiel #47
0
 def format_edition(self, e):
     return optional [
         words [
             field('edition', apply_func=lambda x: x.lower()),
             'edition',
         ]
     ]
    def format_inproceedings(self, e):
        template = toplevel [
            tag('b') [self.format_title(e, 'title')],
            Symbol('br'),
            self.format_names('author'),
            Symbol('br'),
            words [
                # 'In',
                # optional[ self.format_editor(e, as_sentence=False) ],
                # tag('conference') [self.format_btitle(e, 'booktitle', as_sentence=False)],
                tag('conference') [self.format_btitle(e, 'shorttitle', as_sentence=False)],
                # self.format_volume_and_series(e, as_sentence=False),
                # optional[ words [pages] ], 
                # optional[ field('pages') ],
                # optional_field('pages',apply_func=dashify) # ABC ERROR
                #self.format_address_organization_publisher_date(e),
                Symbol('br'),
            ],
            optional [
                words [
                    field('note'),
                    Symbol('br')  
                ]
            ],
            #self.format_web_refs(e),
        ]
        # print field('pages',apply_func=dashify) # ABC error

        return template.format_data(e)
    def format_title(self, e, which_field, as_sentence=False):

        def protected_capitalize(x):
            """Capitalize string, but protect {...} parts."""
            result = ""
            level = 0
            for pos, c in enumerate(x):
                if c == '{':
                    level += 1
                elif c == '}':
                    level -= 1
                elif pos == 0:
                    c = c.upper()
                elif level <= 0:
                    c = c.lower()
                result += c
            return result

        # formatted_title = field(which_field)

        formatted_title = tag('pubtitle') [ tag('b') [field(which_field)]]

        # formatted_title = field(  ABC ERROR
            # which_field, apply_func=protected_capitalize)

        

        if as_sentence:
            return sentence(capfirst=False) [tag('b') [ formatted_title ]]
        else:
            return formatted_title
Beispiel #50
0
 def format_url(self, e):
     # based on urlbst format.url
     return href [
         field('url'),
         join(' ') [
             'http',
             ]
         ]
Beispiel #51
0
 def format_title(self, e, which_field, as_sentence=True):
     formatted_title = field(
         which_field, apply_func=lambda text: text.capitalize()
     )
     if as_sentence:
         return sentence [ formatted_title ]
     else:
         return formatted_title
Beispiel #52
0
 def format_url(self, e):
     return together [
         '[',
         href [
             field('url'),
             'PAPER'
             ],
         ']'
     ]
Beispiel #53
0
 def format_repo(self, e):
     return together [
         '[',
         href [
             field('repo'),
             'REPO'
             ],
         ']'
     ]
Beispiel #54
0
    def format_title(self, e, which_field, as_sentence=True):
        from pybtex.bibtex.utils import change_case

        formatted_title = field(
            which_field, apply_func=lambda text: change_case(text, 't'))
        if as_sentence:
            return sentence(capitalize=False) [ formatted_title ]
        else:
            return formatted_title
Beispiel #55
0
 def format_unpublished(self, e):
     template = toplevel [
         sentence [self.format_names('author')],
         self.format_title(e, 'title'),
         sentence(capfirst=False) [
             field('note'),
             optional[ date ]
         ],
     ]
     return template.format_data(e)
Beispiel #56
0
 def format_misc(self, e):
     template = toplevel [
         optional[ sentence [self.format_names('author')] ],
         optional[ self.format_title(e, 'title') ],
         sentence[
             optional[ field('howpublished') ],
             optional[ date ],
         ],
         sentence(capfirst=False) [ optional_field('note') ],
     ]
     return template.format_data(e)
 def format_misc(self, e):
     template = toplevel [
         tag('pubtitle') [tag('b') [field('title')]],
         Symbol('br'),
         optional[ sentence [self.format_names('author')] ],
         Symbol('br'),
         optional [
             words [
                 sentence [ field('note')],
                 Symbol('br')  
             ]
         ],
         #sentence[
             #optional[ field('howpublished') ],
             #optional[ date ],
         #],
         #sentence(capfirst=False) [ optional_field('note') ],
         #self.format_web_refs(e),
     ]
     return template.format_data(e)