Package Pyblio :: Package Format :: Module Person
[hide private]
[frames] | no frames]

Source Code for Module Pyblio.Format.Person

 1  import re 
 2   
 3  from Pyblio.Format.DSL import lazy 
 4   
 5   
6 -def maybe (value, prefix = '', postfix = '', default = ''):
7 if value: return prefix + value + postfix 8 return default
9
10 -def _lastFirst(record, authors):
11 return [ '%s%s' % (x.last, maybe (x.first, prefix = ', ')) 12 for x in authors(record) ]
13 14 lastFirst = lazy (_lastFirst) 15
16 -def _firstLast (record, authors):
17 return [ '%s%s' % (maybe (x.first, postfix = ' '), x.last) 18 for x in authors(record) ]
19 20 firstLast = lazy (_firstLast) 21 22 _ini_re = re.compile (r'([.-]|\s+)') 23
24 -def initials (name):
25 """ Normalizes a first name as an initial """ 26 27 if not name: 28 return None 29 30 # if the name is full upper, we assume it is already the 31 # contracted initials form. 32 if (name.upper() == name and 33 len(name) < 4 and 34 _ini_re.search(name) is None): 35 return '.'.join(name) + '.' 36 37 res = [] 38 39 for p in _ini_re.split (name): 40 if not p.strip () or p == '.': continue 41 42 if p != '-': p = p [0] + '.' 43 44 res.append (p) 45 46 return ''.join (res)
47
48 -def _initialLast (record, authors):
49 return [ '%s%s' % (maybe (initials (x.first), postfix = ' '), x.last) 50 for x in authors(record) ]
51 52 initialLast = lazy (_initialLast) 53