Commit 9b4a0fdb authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Redesing the base function is_conference, is_institute, is_thesis.

parent 5a7bf40d
...@@ -31,64 +31,81 @@ REG_YEAR = re.compile(r"(\d{4})") ...@@ -31,64 +31,81 @@ REG_YEAR = re.compile(r"(\d{4})")
THESIS_DIR = "dir." THESIS_DIR = "dir."
def is_conference(record): def is_conference(recjson):
"""True when the record describes a publication related to a conference. """True when the record describes a publication related to a conference.
Args: Args:
record (Record): MARC12 record associated to a publication recjson (dict):
or to and institute. record associated to a publication or to and institute.
Return: Return:
bool: ``True`` when the MARC record describes a publication related bool:
``True`` when the record describes a publication related
to a conference. to a conference.
""" """
if "111" in record: # ConferencePaper in collection
# find proceeding in both stores
if "collection" in recjson:
data = recjson["collection"]
data = (data if isinstance(data, list) else [data])
value = "ConferencePaper"
li = [di for di in data if "primary" in di and di["primary"] == value]
if len(li) > 0:
return True
# try to identify talk in cds
# look for a conference key or for a subject equal to Talk
found = \
("aleph_linking_page" in recjson) or \
("subject" in recjson
and "term" in recjson["subject"]
and recjson["subject"]["term"] == u"Talk")
if found:
return True return True
# try with the conference key # try to identify talk in inspirehep
# the location of this values depends on the store # look for a conference key
# cds.cern.ch (962, n) and inspirehep.net (773,w). found = \
if record.host().startswith("cds"): ("publication_info" in recjson
field, subfield = "962", "n" and "cnum" in recjson["publication_info"])
else:
field, subfield = "773", "w" if found:
return True
return len(record._get(field, subfield)) > 0 return False
def is_institute(record): def is_institute(recjson):
"""True when the record describes an institute. """True when the record describes an institute.
Args: Args:
record (Record): MARC12 record associated to a publication recjson (dict):
or to and institute. record associated to a publication or to and institute.
Return: Return:
bool: ``True`` when the MARC record describes an institute. bool:
``True`` when the record describes an institute.
""" """
# "980": [ # INSTITUTION in collection
# {"b": ["CK90", "HEP200", "PDGLIST", "PPF", "TOP500", "WEB"]}, if "collection" in recjson:
# {"a": "INSTITUTION"}, data = recjson["collection"]
# {"a": "CORE"} data = (data if isinstance(data, list) else [data])
# ]
if "980" in record: value = "INSTITUTION"
li = [di for di in data if "primary" in di and di["primary"] == value]
if isinstance(record["980"], list):
for di in record["980"]: if len(li) > 0:
for k, v in di.items(): return True
if k == "a" and v == "INSTITUTION":
return True
elif isinstance(record["980"], dict) and "a" in record["980"] and \
record["980"]["a"] == "INSTITUTION":
return True
return False return False
def is_thesis(record): def is_thesis(recjson):
"""True when the record describes a thesis. """True when the record describes a thesis.
Args: Args:
...@@ -99,6 +116,13 @@ def is_thesis(record): ...@@ -99,6 +116,13 @@ def is_thesis(record):
bool: ``True`` when the MARC record describes a thesis. bool: ``True`` when the MARC record describes a thesis.
""" """
li = record._get("980", "a", force_list=True) # THESIS in collection
val = ", ".join(li) if "collection" in recjson:
return "THESIS" in val data = recjson["collection"]
data = (data if isinstance(data, list) else [data])
value = "THESIS"
li = [di for di in data if "primary" in di and di["primary"] == value]
if len(li) > 0:
return True
# -*- coding: utf-8 -*-
"""test_instantiate_Record
* Test functions to introspect the type of record.
* Test functions to upcast the Record from the JSON object.
"""
from invenio_tools.base import is_conference, is_institute, is_thesis
from invenio_tools.factory import build_record
from invenio_tools.inveniostore import InvenioStore
from invenio_tools.recordconf import RecordConf
from invenio_tools.recordinst import RecordInst
from invenio_tools.recordpubli import RecordPubli
from invenio_tools.recordthesis import RecordThesis
def test_conference_cds():
store = InvenioStore("cds.cern.ch")
recjson = store.get_record(1411352)
assert is_conference(recjson)
assert not is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordConf)
def test_conference_inspirehep():
store = InvenioStore("inspirehep.net")
recjson = store.get_record(1276938)
assert is_conference(recjson)
assert not is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordConf)
def test_institute():
"""CPPM"""
store = InvenioStore("inspirehep.net")
recjson = store.get_record(902989)
assert not is_conference(recjson)
assert is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordInst)
def test_publi_cds():
"""Precision luminosity measurements at LHCb"""
store = InvenioStore("cds.cern.ch")
recjson = store.get_record(1951625)
assert not is_conference(recjson)
assert not is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordPubli)
def test_publi_inspirehep():
"""Precision luminosity measurements at LHCb"""
store = InvenioStore("inspirehep.net")
recjson = store.get_record(1319638)
assert not is_conference(recjson)
assert not is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordPubli)
def test_talk_cds():
store = InvenioStore("cds.cern.ch")
recjson = store.get_record(2239092)
assert is_conference(recjson)
assert not is_institute(recjson)
assert not is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordConf)
def test_thesis_cds():
store = InvenioStore("cds.cern.ch")
recjson = store.get_record(1632177)
assert not is_conference(recjson)
assert not is_institute(recjson)
assert is_thesis(recjson)
record = build_record(recjson)
assert isinstance(record, RecordThesis)
"""test_marc
"""
from invenio_tools import (is_conference,
is_institute,
is_thesis,
load_record,
Record,
RecordConf,
RecordInst,
RecordPubli,
RecordThesis)
def test_conference_cds():
record = load_record("cds.cern.ch", 1411352)
assert is_conference(record) == True
assert is_institute(record) == False
assert is_thesis(record) == False
assert isinstance(record, RecordConf)
def test_conference_inspirehep():
record = load_record("inspirehep.net", 1276938)
assert is_conference(record) == True
assert is_institute(record) == False
assert is_thesis(record) == False
assert isinstance(record, RecordConf)
def test_institute():
"""CPPM"""
record = load_record("inspirehep.net", 902989)
assert is_conference(record) == False
assert is_institute(record) == True
assert is_thesis(record) == False
assert isinstance(record, RecordInst)
def test_publi_cds():
"""Precision luminosity measurements at LHCb"""
record = load_record("cds.cern.ch", 1951625)
assert is_conference(record) == False
assert is_institute(record) == False
assert is_thesis(record) == False
assert isinstance(record, RecordPubli)
def test_publi_inspirehep():
"""Precision luminosity measurements at LHCb"""
record = load_record("inspirehep.net", 1319638)
assert is_conference(record) == False
assert is_institute(record) == False
assert is_thesis(record) == False
assert isinstance(record, RecordPubli)
def test_thesis_cds():
record = load_record("cds.cern.ch", 1632177)
assert is_conference(record) == False
assert is_institute(record) == False
assert is_thesis(record) == True
assert isinstance(record, RecordThesis)
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