Commit 0551b587 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the method _is_synonym and publisher in the class CheckAndFix.

parent 89b705f9
......@@ -58,6 +58,7 @@ MSG_NO_COUNTRY = "Reject invalid country"
MSG_NO_CONF_DATE = "Reject no conference date"
MSG_NO_DATE = "Reject no submission date"
MSG_NO_MY_AUTHOR = "Reject no authors of my institute"
MSG_NO_PUBLISHER = "Reject invalid publisher"
MSG_NO_REF = "Reject incomplete paper reference"
MSG_NO_YEAR = "Reject no publication year"
......@@ -216,6 +217,26 @@ class CheckAndFix(object):
return self.__reference
def _is_synonym(self, tablename, value):
"""Check that the synonym field contains *value*.
Args:
tablename (unicode): name of the database table
value (unicode): value to be searched
Returns:
bool: ``True`` if *one* row is found, ``False`` otherwise.
"""
db = self.db
table = db[tablename]
query = table.synonyms.contains(value)
if db(query).count() == 1:
return True
return False
def _recover_submitted(self, record):
"""Recover submitted date using conference, preprint or thesis
information.
......@@ -350,38 +371,55 @@ class CheckAndFix(object):
record[k] = record[k][0]
def collaboration(self, record):
"""Check that the collaboration is well formed.
"""Check the collaboration.
Have a look to the synonyms when the collaboration is not well formed.
Args:
record (RecordPubli): record describing a publication.
Raises:
CheckException: when the collaboration value is not well formed.
CheckException: when the collaboration value is not well formed
and not entered as a synonym.
"""
val = record.collaboration()
if val and not REG_COLLABORATION.match(val):
raise CheckException(MSG_WELL_FORMED_COLLABORATION)
if not val:
return
if REG_COLLABORATION.match(val):
return
if self._is_synonym("collaboration", val):
return
raise CheckException(MSG_WELL_FORMED_COLLABORATION)
def country(self, record):
"""Check conference country.
Have a look to the synonyms when the country does not exist.
Args:
record (RecordConf): record describing a talk or a proceeding.
Raises:
CheckException: when the country is not defined in the database.
CheckException: when the country is not defined
and not entered as a synonym.
"""
# conference information are available, i.e proceeding
if not isinstance(record, RecordConf):
return
# check country information (all valid countries have been enter once)
db = self.db
id_country = get_id(db.countries, country=record.conference_country())
if not id_country:
raise CheckException(MSG_NO_COUNTRY)
val = record.conference_country()
id_country = get_id(db.countries, country=val)
if id_country:
return
if self._is_synonym("countries", val):
return
raise CheckException(MSG_NO_COUNTRY)
def conference_date(self, record):
"""Check conference date.
......@@ -748,6 +786,36 @@ class CheckAndFix(object):
self._repair_paper_reference(record)
return
def publisher(self, record):
"""Check publisher.
Have a look to the synonyms when the publisher does not exist.
Args:
record (RecordPubli): record describing a publication.
Raises:
CheckException: when the publisher is not defined
and not entered as a synonym.
"""
db = self.db
val = record.paper_editor()
if not val:
return
# erratum -- check the first entry
if isinstance(list):
val = val[0]
id_publisher = get_id(db.publishers, abbreviation=val)
if id_publisher:
return
if self._is_synonym("publishers", val):
return
raise CheckException(MSG_NO_PUBLISHER)
def recover_oai(self, record, host):
"""Recover the OAI identifier when it is not defined
or not well form.
......
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