Example #1
0
def create_entrycode(b={}):
  """
  Creates a 'hopefully unique' entry key from a bibtex item
  """
  len_aut=7  # Length of the author surname used
  try:
    aut= helper.capitalizestring('%s%s'%(b['author'][0][0],b['author'][0][1]))
  except:
    print b['author']
    print b['_code']
  aut=helper.oversimplify(aut)
  if len(aut) > len_aut:
    bibid=aut[:len_aut]
  else:
    bibid=aut.strip()

  bibid +=  b.get('year','')
  bibid += b.get('journal_abbrev','')

  if b['_type'] == 'mastersthesis':   bibid+= 'MT'
  elif b['_type'] == 'phdthesis':    bibid+= 'PHD'
  elif b['_type'] in ['book','incollection','proceedings','conference','misc','techreport']:
    if b.has_key('booktitle'):
      bibid+= helper.create_initials(b['booktitle'])
    elif b.has_key('series'):
      bibid+= helper.create_initials(b['series'])

    if b.has_key('title'):
      bibid+= '_'+helper.create_initials(b.get('title','').upper())[:3]

  if 'thesis' not in b['_type']:
    if b.has_key('firstpage'):   bibid+= 'p'+b['firstpage'].strip()
    elif b.has_key('volume'):    bibid+= 'v'+b['volume'].strip()
  return helper.oversimplify(bibid)
Example #2
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
Example #3
0
def parseentry(source):
  """
  Reads an item in bibtex form from a string 
  """
  try:
    source+' '
  except:
    raise TypeError
  # Transform Latex symbols and strip newlines and multiple spaces 
  
  source= source.decode('latex+utf8','ignore')
  source.replace('\n',' ')
  source= re.sub('\s+',' ',source)

  entry={}
  st= None
  s=source.partition('{')

  if s[1]=='':
    return None,None

  arttype= s[0].strip()[1:].lower()

  if arttype == 'string':
    # Split string name and definition, removing outer "comillas" and put them in a list
    name, defin = s[2].strip().split("=")
    defin= defin.replace('"','').strip()
    if defin.startswith('{'):
      defin=defin[1:-1]
    return {name.strip():defin.strip()},None

  elif arttype in helper.alltypes:
    # Then it is a publication that we want to keep
    p = re.match('([^,]+),', s[2] ) # Look for the key followed by a comma
    entry['_type']= arttype
    entry['_code']= p.group()[:-1]

    ff= get_fields(s[2][p.end():])
    for n,d in ff:
      if n == 'author' or n == 'editor':
        entry[n]= bibtexauthor(d)
      elif n == 'title' or n == 'abstract':
        entry[n]= helper.capitalizestring(d)
      elif n== 'pages':
        entry['firstpage'],entry['lastpage']= process_pages(d)
      elif n == 'year':
        entry[n]= d.strip('.')
      else:
        entry[n]=d
    return None,entry

  elif arttype == 'comment' or arttype == 'preamble':
    # Do nothing (for now)
    return None,None
  else:
    return None,None
Example #4
0
def create_entrycode(b={}):
    """
  Creates a 'hopefully unique' entry key from a bibtex item
  """
    len_aut = 7  # Length of the author surname used
    try:
        aut = helper.capitalizestring('%s%s' %
                                      (b['author'][0][0], b['author'][0][1]))
    except:
        raise BibAuthorError(b['_code'])
    aut = helper.oversimplify(aut)
    if len(aut) > len_aut:
        bibid = aut[:len_aut]
    else:
        bibid = aut.strip()

    bibid += b.get('year', '')
    bibid += b.get('journal_abbrev', '')

    if b['_type'] == 'mastersthesis': bibid += 'MT'
    elif b['_type'] == 'phdthesis': bibid += 'PHD'
    elif b['_type'] in [
            'book', 'incollection', 'proceedings', 'conference', 'misc',
            'techreport'
    ]:
        if b.has_key('booktitle'):
            bibid += helper.create_initials(b['booktitle'])
        elif b.has_key('series'):
            bibid += helper.create_initials(b['series'])

    if b.has_key('title'):
        bibid += '_' + helper.create_initials(b.get('title', '').upper())[:3]

    if 'thesis' not in b['_type']:
        if b.has_key('firstpage'):
            if not b['firstpage'] == None:
                bibid += 'p' + b['firstpage'].strip()
        elif b.has_key('volume'):
            if not b['volume'] == None:
                bibid += 'v' + b['volume'].strip()
    return helper.oversimplify(bibid)