Commit 7318fcce authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update Automatons and controller to remove depency to format_author_fr.

parent e22f1a62
......@@ -10,8 +10,6 @@ from harvest_tools import (build_harvester_tool,
CheckAndFix,
CheckException,
DRY_RUN,
format_author_fr,
family_name_fr,
search_synonym,
ToolException)
from invenio_tools import (load_record,
......@@ -158,12 +156,12 @@ def edit_insert():
# authors
try:
check.authors(record)
check.format_authors(record, format_author_fr)
check.format_authors(record, fmt="F. Last")
check.my_affiliation(
record, selector.id_projects, selector.id_teams)
check.get_my_authors(record, cmpFct=family_name_fr)
check.get_my_authors(record, sort=True)
except CheckException:
pass
......
harvest_tools.base.format_author_fr
===================================
.. currentmodule:: harvest_tools.base
.. autofunction:: format_author_fr
\ No newline at end of file
......@@ -50,7 +50,6 @@ Helper functions
:toctree: generated/
~base.family_name_fr
~base.format_author_fr
~base.learn_my_authors
~base.search_synonym
......
......@@ -11,7 +11,6 @@ from base import (DRY_RUN,
MSG_NO_ENTRY,
MSG_TOOMANY_SYNONYM,
family_name_fr,
format_author_fr,
search_synonym)
from automaton import Automaton
......
......@@ -6,9 +6,7 @@ import traceback
from automaton import Automaton
from base import (family_name_fr,
format_author_fr,
learn_my_authors,
from base import (learn_my_authors,
MSG_CRASH,
MSG_FIX_ORIGIN,
MSG_IN_DB,
......@@ -63,8 +61,8 @@ class Articles(Automaton):
self.check.submitted(record)
self.check.year(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -3,7 +3,6 @@
"""
from exception import ToolException
from invenio_tools import REG_AUTHOR
from plugin_dbui import get_id, UNDEF_ID
......@@ -31,59 +30,6 @@ def family_name_fr(full_name):
return full_name[full_name.find(' ') + 1:]
def format_author_fr(name):
"""Format the author name according to French typographic rules.
Note:
The name stays unchanged when the formatting failed.
Args:
name (unicode): full name. Possible patterns are:
* ``Family, L``
* ``Family, L.``
* ``Family, P L``
* ``Family, P.L.``
* ``Family, P.-L.``
* ``Family, M -H``
* ``Family Name, J``
* ``Family-Name, J``
* ``Family, F Name``
* ``Family, First``
* ...
Returns:
unicode: the author name encode as ``J.-P. Doe``.
"""
# protection
if name == '' or name is None:
return name
# decode the name Family, First + many variant
# group(1) family name
# group(2) first name
# group(3) second part of the first name
match = REG_AUTHOR.match(name)
# reformat the name as L. Family
# or keep it as it is
if match:
if match.group(3):
tpl = (match.group(2)[0], match.group(3)[0], match.group(1))
result = '%s.-%s. %s' % tpl
else:
result = '%s. %s' % (match.group(2)[0], match.group(1))
else:
result = name
# avoid author name in upper case (R. LE FOO --> R. Le Foo)
result = result.title()
return result
def learn_my_authors(db,
authors=None,
id_project=None,
......
......@@ -6,7 +6,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from plugin_dbui import UNDEF_ID
......@@ -36,8 +36,8 @@ class Notes(Automaton):
self.check.submitted(record)
self.check.year(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -6,7 +6,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from invenio_tools import RecordConf, RecordThesis
from plugin_dbui import UNDEF_ID
......@@ -59,8 +59,8 @@ class Preprints(Automaton):
self.check.submitted(record)
self.check.year(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -6,7 +6,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from plugin_dbui import UNDEF_ID
......@@ -45,8 +45,8 @@ class Proceedings(Automaton):
self.check.publisher(record)
self.check.paper_reference(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -6,7 +6,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from plugin_dbui import get_id, UNDEF_ID, UNKNOWN
......@@ -43,8 +43,8 @@ class Reports(Automaton):
self.check.submitted(record)
self.check.year(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......@@ -80,9 +80,7 @@ class Reports(Automaton):
# allow undefined institute authors
try:
self.check.my_authors(record,
reference=self._my_author_list(record),
cmpFct=family_name_fr)
self.check.get_my_authors(record, sort=True)
authors_institute = record.my_authors
except CheckException:
......
......@@ -6,7 +6,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from plugin_dbui import UNDEF_ID
......@@ -40,8 +40,8 @@ class Talks(Automaton):
self.check.submitted(record)
self.check.year(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -7,7 +7,7 @@ import traceback
from automaton import Automaton
from base import family_name_fr, format_author_fr, MSG_CRASH, MSG_LOAD
from base import MSG_CRASH, MSG_LOAD
from checkandfix import CheckException
from invenio_tools import RecordThesis
from plugin_dbui import get_id, UNDEF_ID
......@@ -40,8 +40,8 @@ class Thesis(Automaton):
self.check.year(record)
self.check.format_universities(record)
self.check.format_authors(record, format_author_fr)
self.check.get_my_authors(record, family_name_fr)
self.check.format_authors(record, fmt="F. Last")
self.check.get_my_authors(record, sort=True)
except CheckException as e:
self.logs[-1].reject(e, record=record)
......
......@@ -6,7 +6,7 @@ import pytest
from gluon import current
from harvest_tools import format_author_fr, search_synonym, ToolException
from harvest_tools import search_synonym, ToolException
from invenio_tools import load_record
......@@ -20,36 +20,13 @@ def test_author_type():
assert type(author) == unicode
@pytest.mark.parametrize("value, expected", [
(u"Aaij, Roel", u"R. Aaij"),
(u"Le Gac, Renaud", u"R. Le Gac"),
(u"Le Gac, R.", u"R. Le Gac"),
(u"Le Gac, R", u"R. Le Gac"),
(u"Perrin-Terrin, Mathieu", u"M. Perrin-Terrin"),
(u"Perrin-Terrin, M.", u"M. Perrin-Terrin"),
(u"Perrin-Terrin, M", u"M. Perrin-Terrin"),
(u"Schune, Marie-Hélène", u"M.-H. Schune"),
(u"Schune, Marie-Helene", u"M.-H. Schune"),
(u"Schune, Marie Helene", u"M.-H. Schune"),
(u"Schune, M.H.", u"M.-H. Schune"),
(u"Schune, M.-H.", u"M.-H. Schune"),
(u"Schune, M. -H.", u"M.-H. Schune"),
(u"Schune, M-H", u"M.-H. Schune"),
(u"Schune, M -H", u"M.-H. Schune")
])
def test_format_author(value, expected):
print value
assert type(value) == unicode
assert format_author_fr(value) == expected
def test_search_synonym():
db = current.db
# collaboration ANTARES, TANAMI (should not be defined as a synonym)
# collaboration ANTARES, TANAMI (defined as synonym in the db)
record = load_record("inspirehep.net", 1342250)
with pytest.raises(ToolException):
search_synonym(db.collaborations, "collaboration", record.collaboration())
colid = search_synonym(db.collaborations, "collaboration", record.collaboration())
assert colid == 2
# collaboration = ANTARES (defined as synonym in the db))
record = load_record("inspirehep.net", 718872)
......
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