Commit 398eef6d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Polish code documentations and comments.

parent 921aa615
......@@ -11,9 +11,11 @@ to_list = lambda x: (x if isinstance(x, list) else [x])
def affiliation_keys(field):
"""Extract affiliation key(s) from the author field.
The affiliation keys are obtained by concatenating the "u" and "v"
keys of the author field.
Note:
The affiliation keys are obtained by concatenating the "u" and "v"
keys. Keep in mind that an author can have several affiliations.
An author can have several affiliations.
Args:
field (dict): author field
......@@ -29,10 +31,10 @@ def affiliation_keys(field):
if "v" in field:
key_v = to_list(field["v"])
# tuple with u and v key
# transform [u1, u2, u3], [v1, v2] into [(u1, v1), (u2, v2), (u3, "")]
iter_uv = izip_longest(key_u, key_v, fillvalue="")
# concatenate u and v key
# concatenate (u1,v1) into u1v1
return imap(lambda x: u"%s%s" % x, iter_uv)
......@@ -60,7 +62,7 @@ def author_name(field):
Note:
In most of the case the author is a string
but it can be a list, e.g inspirehep.net/138663:
but it can be a list, e.g inspirehep.net/1386663:
[u'Zuniga, J.', u'(the A.N.T.ARES. Collaboration)']
Args:
......@@ -122,9 +124,10 @@ def iter_author_fields(record):
def iter_author_affiliations(record):
"""Iterator over the author affiliations.
The affiliation is defined by the "u" key of the author field.
Note:
The affiliation is defined by the "u" key.
Keep in mind that an author can have several affiliations.
An author can have several affiliations.
Args:
record (Record): MARC record for the publication
......@@ -141,9 +144,11 @@ def iter_author_affiliations(record):
def iter_author_affiliation_keys(record):
"""Iterator over the author affiliation keys.
The affiliation keys are obtained by concatenating the "u" and "v" keys
of the author field.
Note:
The affiliation keys are obtained by concatenating the "u" and "v"
keys. Keep in mind that an author can have several affiliations.
An author can have several affiliations.
Args:
record (Record): MARC record for the publication
......
......@@ -100,9 +100,8 @@ class RecordPubli(Record):
def find_affiliation(self, pattern):
"""Find affiliation matching the regular expression *pattern*.
Note:
Affiliation keys are obtained by concatenating the field 100u
(700u) with 100v (700v) when the latter exists.
Affiliation keys are obtained by concatenating the "u" and "v"
keys of the author field 100 and 700.
Args:
pattern (unicode): regular expression defining the
......@@ -116,6 +115,7 @@ class RecordPubli(Record):
"""
regex = re.compile(pattern)
# NOTE: an author can have several affiliations
for iter_key in iter_author_affiliation_keys(self):
li = list(ifilter(regex.match, iter_key))
......@@ -144,9 +144,8 @@ class RecordPubli(Record):
"""Find authors belonging to a given institute(s) defined by a regular
expression. The search is performed on the affiliation keys.
Note:
Affiliation keys are obtained by concatenating the field 100u
(700u) with 100v (700v) when the latter exists.
Affiliation keys are obtained by concatenating the "u" and "v" keys
of the author field 100 and 700.
Args:
pattern (unicode): regular expression defining the affiliation keys
......@@ -197,7 +196,8 @@ class RecordPubli(Record):
"""The institute(s) associated to the first author.
Note:
Search is performed via the affiliation key 100(700)u.
Search is performed via the affiliation defined by the "u" key
of the author field.
Returns:
unicode:
......@@ -211,7 +211,8 @@ class RecordPubli(Record):
"""The list of institute signing the publication.
Note:
Name of institute are given by the affiliation key 100(700)u.
Name of institute are given by the affiliation defined by
the "u" key of the author field.
Returns:
list: the list is sort in alphabetic order.
......
......@@ -34,8 +34,8 @@ class RecordThesis(RecordPubli):
list: the list is empty when authors are not defined.
"""
# for a thesis, the author field 700 can contains names of director.
# they have to be removed.
# for a thesis, the author field 700 contains names of director
# which have to be removed.
iter_filter = ifilterfalse(is_thesis_dir, iter_author_fields(self))
return list(imap(author_name, iter_filter))
......@@ -76,8 +76,8 @@ class RecordThesis(RecordPubli):
* Empty string when it is not defined.
"""
# for a thesis, the author field 700 field can contains
# names of the director.
# for a thesis, the author field 700 field contains
# names of the director as well as the name of authors
iter_filter = ifilter(is_thesis_dir, iter_author_fields(self))
return u", ".join(list(imap(author_name, iter_filter)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment