Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99289249
Person.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jan 23, 03:11
Size
1 KB
Mime Type
text/x-python
Expires
Sat, Jan 25, 03:11 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
23768258
Attached To
R3596 pybliographer
Person.py
View Options
import
re
from
Pyblio.Format.DSL
import
lazy
def
maybe
(
value
,
prefix
=
''
,
postfix
=
''
,
default
=
''
):
if
value
:
return
prefix
+
value
+
postfix
return
default
def
_lastFirst
(
record
,
authors
):
return
[
'
%s%s
'
%
(
x
.
last
,
maybe
(
x
.
first
,
prefix
=
', '
))
for
x
in
authors
(
record
)
]
lastFirst
=
lazy
(
_lastFirst
)
def
_firstLast
(
record
,
authors
):
return
[
'
%s%s
'
%
(
maybe
(
x
.
first
,
postfix
=
' '
),
x
.
last
)
for
x
in
authors
(
record
)
]
firstLast
=
lazy
(
_firstLast
)
_ini_re
=
re
.
compile
(
r'([.-]|\s+)'
)
def
initials
(
name
):
""" Normalizes a first name as an initial """
if
not
name
:
return
None
# if the name is full upper, we assume it is already the
# contracted initials form.
if
(
name
.
upper
()
==
name
and
len
(
name
)
<
4
and
_ini_re
.
search
(
name
)
is
None
):
return
'.'
.
join
(
name
)
+
'.'
res
=
[]
for
p
in
_ini_re
.
split
(
name
):
if
not
p
.
strip
()
or
p
==
'.'
:
continue
if
p
!=
'-'
:
p
=
p
[
0
]
+
'.'
res
.
append
(
p
)
return
''
.
join
(
res
)
def
_initialLast
(
record
,
authors
):
return
[
'
%s%s
'
%
(
maybe
(
initials
(
x
.
first
),
postfix
=
' '
),
x
.
last
)
for
x
in
authors
(
record
)
]
initialLast
=
lazy
(
_initialLast
)
Event Timeline
Log In to Comment