Beispiel #1
0
  def to_html(self,style={}):
    """
    Converts the item to html format with the given style The style is a pair (before,
    after) surrounding the corresponding field (except for authors)
    """

    fields = ['title', 'author', 'journal', 'volume','number', 'month', 'booktitle', 'chapter',
                     'address', 'edition', 'howpublished','school', 'institution', 'organization',
                     'publisher', 'series','firstpage','lastpage', 'note', 'crossref', 'issn','isbn',
                     'year', 'keywords' ,'annote', '_code', 'doi',  'url',  'abstract']

    st= dict(self.html_style)
    st.update(style)
    if not st.has_key('fields'): st['fields'] = fields 

    # Format the title
    title = self.get_field('title','')
    title= helper.handle_math(title)
    title= helper.removebraces(title)
    if title != '' and st.get('title',['','']) !=  None:
      title= title.strip().join(st.get('title',['','']))
    else:
      title = ''

    # Format authors
    if self.has_key('author') and st.get('author')!= None:
      form_aut=''
      list_aut= self.get_authorsList()
      if len(list_aut) > 10:
        list_aut=list_aut[:10]
        list_aut.append('<i>et al</i>')
      for a in list_aut:
        form_aut += '<span class="author">'+ a +'</span>, '
      form_aut= form_aut[:-2]
      autores= form_aut.join(st.get('author',['','']))
    
    # Put all fields together
    s = ''
    for field in st['fields']:
      if field == 'author':  value = autores
      elif field == 'title':  value = title
      elif self.get_field(field,'') != '' and st.get(field,(' ',' ')) != None:
        value= helper.handle_math(self.get_field(field,'').strip())
        value= helper.removebraces(value).join(st.get(field,[' ',' ']))
      else: value = ''
      s+= value

    # Aca agrego algo al principio y al final del item completo (por ejemplo '<li>' )
    if st.get('_type',['','']) !=  None:
      s= s.strip().join(st.get('_type',['','']))

    s= s.decode('latex','replace')  # Convert from latex some characters using encoding
    return unicode(s)
Beispiel #2
0
    def to_html(self, style={}):
        """
    Converts the item to html format with the given style The style is a pair (before,
    after) surrounding the corresponding field (except for authors)
    """
        # textfields= ['journal','booktitle','series','school','volume','number','publisher','firstpage','lastpage','year','_code','url','doi','abstract']
        textualfields = [
            'journal', 'volume', 'number', 'month', 'booktitle', 'chapter',
            'address', 'edition', 'howpublished', 'school', 'institution',
            'organization', 'publisher', 'series', 'firstpage', 'lastpage',
            'note', 'crossref', 'issn', 'isbn', 'year', 'keywords', 'annote',
            '_code', 'doi', 'url', 'abstract'
        ]

        st = dict(self.html_style)
        st.update(style)
        tipo = self.get('_type', 'article')
        title = helper.handle_math(self.get_field('title', ''))
        title = bibparse.helper.capitalizestring(title)
        if 'mastersthesis' == tipo: title = 'Master Thesis. ' + title
        elif 'phdthesis' == tipo: title = 'Phd Thesis. ' + title

        s = ''
        if title != '' and st.get('title', ['', '']) != None:
            s += title.strip().join(st.get('title', ['', '']))

        if self.has_key('author') and st.get('author') != None:
            form_aut = ''
            list_aut = self.get_authorsList()
            if len(list_aut) > 10:
                list_aut = list_aut[:10]
                list_aut.append('<i>et al</i>')
            for a in list_aut:
                form_aut += '<span class="author">' + a + '</span>, '
            form_aut = form_aut[:-2]
            s += form_aut.join(st.get('author', ['', '']))

        for field in textualfields:
            if self.get_field(field, '') != '' and st.get(field,
                                                          (' ', ' ')) != None:
                value = helper.handle_math(self.get_field(field, '').strip())
                value = bibparse.helper.removebraces(value)
                s += value.join(st.get(field, [' ', ' ']))

        if st.get('_type', ['', '']) != None:
            s = s.strip().join(st.get('_type', ['', '']))

        s = s.decode(
            'latex',
            'replace')  # Convert from latex some characters using encoding
        return unicode(s)
Beispiel #3
0
  def to_latex(self,style={}):
    """
    As its name indicates, it converts bibtex data to a latex bibitem
    """

    fields= ['_code', 'title', 'author', 'journal','booktitle','school','volume','number','firstpage','lastpage','year','url','doi','abstract']

    st=dict(self.latex_style)
    st.update(style)
    if not st.has_key('fields'): st['fields'] = fields 

    # if st.get('_code') !=  None:
    #   code= self.get('_code').join(st['_code'])

    if self.get('title','') != '' and st.get('title') !=  None:
      title= self.get('title').join(st['title'])
    
    if self.get('author','') != '' and st.get('author') != None:
      autores= ', '.join(self.get_authorsList()).join(st['author'])

    s=''
    for field in st['fields']:
      if field == 'author':  value = autores
      elif field == 'title':  value = title
      elif self.get_field(field,'') != '' and st.get(field,(' ',' ')) != None:
        value= helper.handle_math(self.get_field(field,'').strip())
        value=bibparse.helper.removebraces(value).join(st.get(field,[' ',' ']))
      else: value = ''
      s += value
      # if self.get_field(field,'') != '' and st.get(field) != None:
      #   s+= self.get_field(field,'').strip().join(st[field])
    return s
Beispiel #4
0
  def to_xml(self,p='',indent=2):
    """
    Converts the item to xml format. The prefix is added to each entry
    """
    sp= indent
    spc=indent*' '
    s='%s<%sentry id="%s">\n' %(sp*spc,p,self.get_field('_code',''))
    sp += 1
    s+='%s<%s%s>\n' %(sp*spc,p,self.get('_type',''))

    for k,e in self.iteritems():
      if k == 'author':
        sp+=1
        space=sp*spc+'\n'
        v= space.join(['%s<%sauthor>%s</%sauthor>'%(sp*spc,p,x,p) for x in self.get_authorsList()])
        v= helper.removebraces(v)
        v= helper.replace_tags(v,'other')
        sp-=1
        s+= '%s<%s%s>\n%s\n%s</%s%s>\n' %(sp*spc,p,'authors',v,sp*spc,p,'authors')
      else:
        if helper.is_string_like(e):
          v= helper.replace_tags(e,'xml')
          v= helper.handle_math(v)
        if k=='title':
          v=helper.capitalizestring(v)
          v= helper.removebraces(v)
          v= helper.replace_tags(v,'other')
        s+= '%s<%s%s>%s</%s%s>\n' %(sp*spc,p,k,v,p,k)

    sp-=1
    s+= '%s</%s%s>\n' %(sp*spc,p,self.get('_type',''))
    s+= '%s</%sentry>\n' %(sp*spc,p)
    return s
Beispiel #5
0
def parsedata(page):
  """
  Parse the results from ADS and store the list of references in a dictionary.
  """
  biblist={}

  page= helper.handle_math(page,1)  
  s= reg_begin.split(page)[1:] # The first item is empty, we take it out

  for paper in s:
    item= parseentry(paper)
    if item.has_key('author'):
      biblist[item['_code']]= dict(item)
  if biblist == {}: return None
  return biblist
Beispiel #6
0
def parsedata(page):
    """
  Parse the results from ADS and store the list of references in a dictionary.
  """
    biblist = {}

    page = helper.handle_math(page, 1)
    s = reg_begin.split(page)[1:]  # The first item is empty, we take it out

    for paper in s:
        item = parseentry(paper)
        if item.has_key("author"):
            biblist[item["_code"]] = dict(item)
    if biblist == {}:
        return None
    return biblist