def format_proceedings(self, e):
     template = toplevel [
         first_of [
             # there are editors
             optional [
                 join(' ')[
                     sentence(capfirst=True) [tag('b') [self.format_title(e, 'title')]],
                     Symbol('br'),
                     self.format_editor(e),
                     #self.format_btitle(e, 'title', as_sentence=False),
                     Symbol('br'),
                     self.format_volume_and_series(e, as_sentence=False),
                     self.format_address_organization_publisher_date(e),
                     Symbol('br'),
                 ],
             ],
             # there is no editor
             optional_field('organization'),
             sentence [
                 self.format_btitle(e, 'title', as_sentence=False),
                 self.format_volume_and_series(e, as_sentence=False),
                 #self.format_address_organization_publisher_date(e, include_organization=False),
             ],
         ],
         #sentence(capfirst=False) [ optional_field('note') ],
         #self.format_web_refs(e),
     ]
     return template.format_data(e)
 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_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)
    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)
Beispiel #5
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
 def format_pages(text):
     dash_re = re.compile(r'-+')
     pages = Text(Symbol('ndash')).join(
         re.split(dash_re, six.text_type(text)))
     if re.search('[-‒–—―]', six.text_type(text)):
         return Text("pp.", Symbol('nbsp'), pages)
     return Text("p.", Symbol('nbsp'), pages)
Beispiel #7
0
 def test__getitem__(self):
     symbol = Symbol('nbsp')
     assert symbol[0] == Symbol('nbsp')
     assert symbol[0:] == Symbol('nbsp')
     assert symbol[0:5] == Symbol('nbsp')
     assert symbol[1:] == String()
     assert symbol[1:5] == String()
     assert_raises(IndexError, lambda: symbol[1])
Beispiel #8
0
    def test__eq__(self):
        assert Symbol('nbsp') == Symbol('nbsp')
        assert not Symbol('nbsp') != Symbol('nbsp')

        assert not Symbol('nbsp') == Symbol('ndash')
        assert Symbol('nbsp') != Symbol('ndash')

        assert Text(nbsp, nbsp) == Text(Symbol('nbsp'), Symbol('nbsp'))
Beispiel #9
0
    def test__getitem__(self):
        symbol = Symbol('nbsp')
        assert symbol[0] == Symbol('nbsp')
        assert symbol[0:] == Symbol('nbsp')
        assert symbol[0:5] == Symbol('nbsp')
        assert symbol[1:] == String()
        assert symbol[1:5] == String()

        with pytest.raises(IndexError):
            symbol[1]
 def format_unpublished(self, e):
     template = toplevel [
         self.format_title(e, 'title'),
         Symbol('br'),
         self.format_names('author'),
         Symbol('br'),
         field('note'),
             #optional[ date ]
         #Symbol('br'),
         #self.format_web_refs(e),
     ]
     return template.format_data(e)
Beispiel #11
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 #12
0
    def format_article(self, entry):
        context = entry["entry"]
        ret = Text("")
        ret = make_author(ret, context)
        ret = make_title(ret, context)
        ret += context.fields["journal"]
        if "volume" in context.fields:
            ret += Symbol("nbsp") + context.fields["volume"]
        if "number" in context.fields:
            ret += Symbol("nbsp") + "(" + context.fields["number"] + ")"
        if "pages" in context.fields:
            ret = ret + ":" + context.fields["pages"]

        ret = make_year(ret, context)
        ret = make_links(ret, context)
        return Tag("li", ret)
Beispiel #13
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 format_phdthesis(self, e):
     template = toplevel [
         tag('pubtitle') [self.format_btitle(e, 'title')],
         Symbol('br'),
         sentence [self.format_names('author')],
         Symbol('br'),
         sentence[
             'PhD thesis',
             field('school'),
             optional_field('address'),
             date,
         ],
         sentence(capfirst=False) [ optional_field('note') ],
         Symbol('br'),
         #self.format_web_refs(e),
     ]
     return template.format_data(e)
Beispiel #15
0
    def format_article(self, e):
        text = super(CoSMoRefStyle, self).format_article(e)

        summary = e.fields.get('cosmomvpa-summary', None)
        if summary is not None:
            summary_text = Tag('emph', Text('[ %s ]' % summary))
            text.extend([Symbol('newblock'), summary_text])

        return text
Beispiel #16
0
 def get_inproceedings_template(self, e):
     template = toplevel[
         self.format_bold_title(e, 'title'),
         Symbol('newline'),
         sentence[self.format_names('author')],
         Symbol('newline'),
         words[
             'In',
             sentence[
                 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_address_organization_publisher_date(e),
         ],
         sentence[optional_field('note')],
         self.format_web_refs(e),
     ]
     return template
Beispiel #17
0
 def format_inproceedings(self, entry):
     context = entry["entry"]
     ret = Text("")
     ret = make_author(ret, context)
     ret = make_title(ret, context)
     ret += Text("In ") + enrich(context.fields["booktitle"])
     if "volume" in context.fields:
         ret += Symbol("nbsp") + context.fields["volume"]
     if "number" in context.fields:
         ret += Symbol("nbsp") + "(" + context.fields["number"] + ")"
     if "pages" in context.fields:
         ret = ret + ":" + context.fields["pages"]
     if "address" in context.fields:
         ret = ret + Text(", ") + enrich(context.fields["address"])
     if "note" in context.fields:
         ret = ret + Text(", ") + context.fields["note"]
     ret = make_year(ret, context)
     ret = make_links(ret, context)
     return Tag("li", ret)
 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)
Beispiel #19
0
    def test__init__(self):
        assert unicode(Text('a', '', 'c')) == 'ac'
        assert unicode(Text('a', Text(), 'c')) == 'ac'

        text = Text(Text(), Text('mary ', 'had ', 'a little lamb'))
        assert unicode(text) == 'mary had a little lamb'

        text = unicode(Text('a', Text('b', 'c'), Tag('em', 'x'), Symbol('nbsp'), 'd'))
        assert text == 'abcx<nbsp>d'

        assert_raises(ValueError, Text, {})
        assert_raises(ValueError, Text, 0, 0)
Beispiel #20
0
 def get_techreport_template(self, e):
     template = toplevel[
         self.format_bold_title(e, 'title'),
         Symbol('newline'),
         sentence[self.format_names('author')],
         Symbol('newline'),
         sentence[
             words[
                 first_of[
                     optional_field('type'),
                     'Technical Report',
                 ],
                 optional_field('number'),
             ],
             field('institution'),
             optional_field('address'),
             date,
         ],
         sentence[optional_field('note')],
         self.format_web_refs(e),
     ]
     return template
Beispiel #21
0
    def test__init__(self):
        assert six.text_type(Text('a', '', 'c')) == 'ac'
        assert six.text_type(Text('a', Text(), 'c')) == 'ac'

        text = Text(Text(), Text('mary ', 'had ', 'a little lamb'))
        assert six.text_type(text) == 'mary had a little lamb'

        text = six.text_type(Text('a', Text('b', 'c'), Tag('em', 'x'), Symbol('nbsp'), 'd'))
        assert text == 'abcx<nbsp>d'

        with pytest.raises(ValueError):
            Text({})

        with pytest.raises(ValueError):
            Text(0, 0)
 def format_techreport(self, e):
     template = toplevel [
         self.format_title(e, 'title'),
         Symbol('br'),
         sentence [self.format_names('author')],
         Symbol('br'),
         sentence [
             words[
                 first_of [
                     optional_field('type'),
                     'Technical Report:',
                 ],
                 optional_field('number')
             ],
             #Symbol('br'),
             #field('institution'),
             #optional_field('address'),
             #date,
         ],
         Symbol('br'),
         sentence(capfirst=False) [ optional_field('note') ],
         #self.format_web_refs(e),
     ]
     return template.format_data(e)
Beispiel #23
0
    def format_article(self, e):
        text = super(CoSMoRefStyle, self).format_article(e)

        summary = e.fields.get('cosmomvpa-summary', None)
        if summary is not None:
            summary_text = Tag('emph', Text('[ %s ]' % summary))

            summary_symbol = [Symbol('newblock'), summary_text]
            if hasattr(text, 'extend'):
                target_to_extend = text
            elif hasattr(text, 'parts'):
                target_to_extend = text.parts
            else:
                raise ValueError('Unsupported type %s', type(text))

            target_to_extend.extend(summary_symbol)

        return text
Beispiel #24
0
def dashify(text):
    dash_re = re.compile(r'-+')
    return Text(Symbol('ndash')).join(dash_re.split(text))
Beispiel #25
0
def toplevel(children, data):
    return join(sep=Symbol('newblock')) [children].format_data(data)
Beispiel #26
0
def dashify(text):
    dash_re = re.compile(r"-+")
    return Text(Symbol("ndash")).join(text.split(dash_re))