Commit 9988269d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update RecordPubli.find_affiliation and find_authors_by_affiliation to...

Update RecordPubli.find_affiliation and find_authors_by_affiliation to concatenate the u and v keys.
parent 3aab30f6
......@@ -98,7 +98,8 @@ class CheckAndFix(object):
def _get_reg_institute(self):
"""
Returns:
unicode: the regular expression defining my institute
unicode: the regular expression defining the affiliation
of my institute.
"""
# alias
......
......@@ -141,9 +141,13 @@ 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.
Args:
pattern (unicode): regular expression defining the
affiliation names.
affiliation keys.
Returns:
unicode:
......@@ -165,12 +169,25 @@ class RecordPubli(Record):
if "u" not in di:
continue
li = di["u"]
if isinstance(li, unicode):
li = [li]
key_u = di["u"]
if isinstance(key_u, unicode):
if "v" in di:
keys = ["%s%s" % (key_u, di["v"])]
else:
keys = [key_u]
for affiliation in li:
if reg_affiliation.search(affiliation):
# affiliation can be list
# we assume the same length for the u and v field.
else:
keys = key_u
if "v" in di:
keys_v = di["v"]
for i in xrange(len(keys)):
keys[i] = "%s%s" % (keys[i], keys_v[i])
for affiliation in keys:
if reg_affiliation.match(affiliation):
return affiliation
return u""
......@@ -200,9 +217,13 @@ class RecordPubli(Record):
"""Find authors belonging to a given institute(s) defined by a regular
expression.
Note:
Affiliation keys are obtained by concatenating the field 100u
(700u) with 100v (700v) when the latter exists.
Args:
pattern (unicode): regular expression defining the
institute name(s)
pattern (unicode): regular expression defining the affiliation keys
for the institute(s).
cmpFct (reference): function to compare author names.
The comparison function takes two items and returns -1, 0, or 1
......@@ -241,12 +262,21 @@ class RecordPubli(Record):
if 'u' not in di:
continue
affiliations = di['u']
if isinstance(affiliations, list):
affiliations = u", ".join(affiliations)
keys = di['u']
if isinstance(keys, list):
if "v" in di:
keys_v = di["v"]
for i in xrange(len(keys)):
keys[i] = "%s%s" % (keys[i], keys_v[i])
keys = u", ".join(keys)
else:
if "v" in di["v"]:
keys = "%s%s" % (keys, di["v"])
# affiliation match
if regex.search(affiliations):
if regex.search(keys):
if "a" in di:
authors.append(di["a"])
......
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