Commit 7bd56619 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the class Institute and the function is_institute in invenio_tools.

parent adc62693
......@@ -3,14 +3,19 @@
@note: details on the invenio API at U{http://invenio-software.org/}
"""
from base import OAI_URL, REG_OAI, REG_YEAR
from base import (is_institute,
OAI_URL,
REG_OAI,
REG_YEAR)
from exception import (CdsException,
CheckException,
InstituteException,
Marc12Exception,
RecordException,
XmlException)
from checkandfix import CheckAndFix
from institute import Institute
from inveniostore import InvenioStore
from marc12 import Marc12
from record import Record
......
......@@ -8,3 +8,25 @@ OAI_URL = "http://%s/record/%s"
REG_OAI = re.compile('oai:([a-z\.]+):([\d]+)')
REG_YEAR = re.compile("(\d{4})")
def is_institute(record):
""" True when the record describe an institute.
Args:
record (Record):
Return:
bool: true when the MARC record describes an institute
"""
# u'980': [{'b': [u'CK90', u'HEP200', u'PDGLIST', u'PPF', u'TOP500', u'WEB']},
# {'a': u'INSTITUTION'},
# {'a': u'CORE'}]}
if u"980" in record:
for di in record[u"980"]:
for k, v in di.iteritems():
if k == "a" and v == u"INSTITUTION":
return True
return False
\ No newline at end of file
......@@ -16,6 +16,7 @@ class ExceptionUTF8(Exception):
class CdsException(ExceptionUTF8): pass
class CheckException(ExceptionUTF8): pass
class InstituteException(ExceptionUTF8): pass
class Marc12Exception(ExceptionUTF8): pass
class RecordException(ExceptionUTF8): pass
class XmlException(ExceptionUTF8): pass
# -*- coding: utf-8 -*-
""" invenio_tools.institute
"""
from base import is_institute
from exception import InstituteException
from record import Record
MSG_INVALID_ARG = "Invalid argument record"
MSG_INVALID_HOST = "Invalid record host"
MSG_INVALID_RECORD = "Invalid record, it is not describing an institute"
class Institute(dict):
"""MARC record representing an institute. More information on MARC
standard at U{http://www.loc.gov/marc/bibliographic/}).
The relation between methods and MARC field is the following::
| INSPIREHEP |
----------------------+-------------+
institute identifier | 110 u |
future institute id | 110 t |
name | 110 b |
type of record | 980 a |
----------------------+-------------+
"""
def __init__(self, record):
"""Constructor from a decoded MARC12 record
Args:
record (Record):
"""
if not isinstance(record, Record):
raise InstituteException(MSG_INVALID_ARG)
if not is_institute(record):
raise InstituteException(MSG_INVALID_RECORD)
if record.host() != 'inspirehep.net':
raise InstituteException(MSG_INVALID_INSTITUTE)
dict.__init__(self, record)
def future_id(self):
"""
Returns:
unicode: the future inspirehep id.
"""
return self[u"110"]["t"]
def id(self):
"""
Returns:
unicode: the inspirehep id.
"""
return self[u"110"]["u"]
def name(self):
"""
Returns:
unicode: the name of the institute.
"""
return self[u"110"]["b"]
def rex(self):
"""
Returns:
unicode: the regular expression to search author by institute
in cds.cern.ch or inspirehep.net store
"""
return r"%s|%s" % (self[u"110"]["u"], self[u"110"]["t"])
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