Commit 8a8147e4 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Remove the obsolete module invenio_tools/iterauthors.py.

parent 11d01d97
......@@ -28,11 +28,6 @@ from exception import (CdsException,
XmlException)
from inveniostore import InvenioStore
from iterauthors import (iter_author_affiliations,
iter_author_affiliation_keys,
iter_author_fields,
iter_author_items,
iter_author_names)
from iterrecord import IterRecord, REG_INT
from marc12 import Marc12
from record import Record
......
# -*- coding: utf-8 -*-
""" invenio_tools.iterauthors
"""
from base import REG_AUTHOR
from itertools import chain, imap, izip_longest
def to_list(x):
return (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:
An author can have several affiliations.
Args:
field (dict): author field
Returns:
itertools.imap
"""
if "u" not in field:
return ()
key_u, key_v = to_list(field["u"]), []
if "v" in field:
key_v = to_list(field["v"])
# transform [u1, u2, u3], [v1, v2] into [(u1, v1), (u2, v2), (u3, "")]
iter_uv = izip_longest(key_u, key_v, fillvalue="")
# concatenate (u1,v1) into u1v1
return imap(lambda x: u"%s%s" % x, iter_uv)
def author_item(field):
"""Extract the item from the author field.
The author item is a tuple containing the author name and an iterator
on the author affiliation keys.
Args:
field (dict): author field
Returns:
tuple: (author name, affiliation keys iterator)
"""
if "a" not in field:
return (u"", u"")
return (field["a"], affiliation_keys(field))
def author_name(field):
"""Extract the name from the author field.
Note:
In most of the case the author is a string
but it can be a list, e.g inspirehep.net/1386663:
[u"Zuniga, J.", u"(the A.N.T.ARES. Collaboration)"]
Args:
field (dict): author field
Returns:
str:
"""
name = (field["a"] if "a" in field else u"")
if isinstance(name, list):
for elt in name:
if REG_AUTHOR.match(elt):
return elt
return name
def iter_author_fields(record):
"""Iterator over the author field.
The author are spread over the 100 and 700 field. The function takes into
cases where the first author is defined in 100 but not in 700, first author
is defined in 100 and in 700 or no author in 100.
Args:
record (Record): MARC record for the publication
Returns:
iterator: either a itertools.chain or a list. The list is empty
when the author field does not exist.
"""
if u"100" in record and u"700" in record:
u100, u700 = record[u"100"], record[u"700"]
if isinstance(u100, dict) and isinstance(u700, list):
if "a" in u100 and "a" in u700[0] and u100["a"] == u700[0]["a"]:
return to_list(u700)
elif isinstance(u100, dict) and isinstance(u700, dict):
if "a" in u100 and "a" in u700 and u100["a"] == u700["a"]:
return to_list(u100)
return chain(to_list(u100), to_list(u700))
elif u"100" in record:
return to_list(record[u"100"])
elif u"700" in record:
return to_list(record[u"700"])
else:
return ()
def iter_author_affiliations(record):
"""Iterator over the author affiliations.
The affiliation is defined by the "u" key of the author field.
Note:
An author can have several affiliations.
Args:
record (Record): MARC record for the publication
Returns:
itertools.imap
"""
ftpl = lambda x: (tuple(x) if isinstance(x, (list, tuple)) else (x,))
func = lambda x: (ftpl(x["u"]) if "u" in x else ())
return imap(func, iter_author_fields(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:
An author can have several affiliations.
Args:
record (Record): MARC record for the publication
Returns:
itertools.imap
"""
return imap(affiliation_keys, iter_author_fields(record))
def iter_author_items(record):
"""Iterator over the author items.
The author item is a tuple containing the author name and an iterator
on the author affiliation keys.
Args:
record (Record): MARC record for the publication
Returns:
itertools.imap
"""
return imap(author_item, iter_author_fields(record))
def iter_author_names(record):
"""Iterator over the author names.
Args:
record (Record): MARC record for the publication
Returns:
itertools.imap
"""
return imap(author_name, iter_author_fields(record))
......@@ -10,13 +10,8 @@ from base import (ARXIV,
REG_ARXIV_NUMBER,
REG_YEAR)
from filters import CLEAN_COLLABORATION
from iterauthors import (iter_author_affiliations,
iter_author_affiliation_keys,
iter_author_items,
iter_author_names)
from itertools import ifilter, imap
from numpy import NaN
from pandas import concat, DataFrame, merge
from pandas import concat, DataFrame
from plugin_dbui import as_list, CLEAN_SPACES
from record import Record
......
......@@ -4,8 +4,6 @@
"""
from base import THESIS_DIR
from filters import CLEAN_THESIS_DEFENSE
from iterauthors import author_name, iter_author_fields
from itertools import ifilter, ifilterfalse, imap
from recordpubli import RecordPubli
......
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