Commit a54c3941 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update store_tools/base.py to add is_conference and friends to new inspirehep API

parent 397a56c4
...@@ -43,6 +43,10 @@ THESIS_DIR = "dir." ...@@ -43,6 +43,10 @@ THESIS_DIR = "dir."
def is_conference(recjson): 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.
Note:
This tools works for JSON record coming from cds.cern.ch,
old.inspirehep.net as well as inspirehep.net
Args: Args:
recjson (dict): recjson (dict):
record associated to a publication or to and institute. record associated to a publication or to and institute.
...@@ -53,8 +57,13 @@ def is_conference(recjson): ...@@ -53,8 +57,13 @@ def is_conference(recjson):
to a conference. to a conference.
""" """
# ConferencePaper in collection # proceeding in inspirehep
# find proceeding in both stores if recjson.get("$schema", "").endswith("hep.json"):
for elt in recjson.get("document_type", []):
if elt == "conference paper":
return True
# proceeding in cds
if "collection" in recjson: if "collection" in recjson:
data = recjson["collection"] data = recjson["collection"]
data = (data if isinstance(data, list) else [data]) data = (data if isinstance(data, list) else [data])
...@@ -65,7 +74,7 @@ def is_conference(recjson): ...@@ -65,7 +74,7 @@ def is_conference(recjson):
if len(li) > 0: if len(li) > 0:
return True return True
# try to identify talk in cds # talk in cds
# look for a conference key or for a subject equal to Talk # look for a conference key or for a subject equal to Talk
found = \ found = \
("aleph_linking_page" in recjson) or \ ("aleph_linking_page" in recjson) or \
...@@ -76,21 +85,16 @@ def is_conference(recjson): ...@@ -76,21 +85,16 @@ def is_conference(recjson):
if found: if found:
return True return True
# try to identify talk in inspirehep
# look for a conference key
found = \
("publication_info" in recjson
and "cnum" in recjson["publication_info"])
if found:
return True
return False return False
def is_institute(recjson): def is_institute(recjson):
"""True when the record describes an institute. """True when the record describes an institute.
Note:
This tools works for JSON record coming from cds.cern.ch,
old.inspirehep.net as well as inspirehep.net
Args: Args:
recjson (dict): recjson (dict):
record associated to a publication or to and institute. record associated to a publication or to and institute.
...@@ -100,23 +104,16 @@ def is_institute(recjson): ...@@ -100,23 +104,16 @@ def is_institute(recjson):
``True`` when the record describes an institute. ``True`` when the record describes an institute.
""" """
# INSTITUTION in collection return recjson.get("$schema", "").endswith("institutions.json")
if "collection" in recjson:
data = recjson["collection"]
data = (data if isinstance(data, list) else [data])
value = "INSTITUTION"
li = [di for di in data if "primary" in di and di["primary"] == value]
if len(li) > 0:
return True
return False
def is_thesis(recjson): def is_thesis(recjson):
"""True when the record describes a thesis. """True when the record describes a thesis.
Note:
This tools works for JSON record coming from cds.cern.ch,
old.inspirehep.net as well as inspirehep.net
Args: Args:
recjson (dict): recjson (dict):
record associated to a publication or to and institute. record associated to a publication or to and institute.
...@@ -125,7 +122,13 @@ def is_thesis(recjson): ...@@ -125,7 +122,13 @@ def is_thesis(recjson):
bool: ``True`` when the record describes a thesis. bool: ``True`` when the record describes a thesis.
""" """
# THESIS in collection # Thesis in inspirehep
if recjson.get("$schema", "").endswith("hep.json"):
for elt in recjson.get("document_type", []):
if elt == "thesis":
return True
# Thesis in cds
if "collection" in recjson: if "collection" in recjson:
data = recjson["collection"] data = recjson["collection"]
data = (data if isinstance(data, list) else [data]) data = (data if isinstance(data, list) else [data])
...@@ -135,3 +138,5 @@ def is_thesis(recjson): ...@@ -135,3 +138,5 @@ def is_thesis(recjson):
if len(li) > 0: if len(li) > 0:
return True return True
return False
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