Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

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

Add RecordHepThesis and Test_09_RecordHepThesis

parent b9de097e
......@@ -31,6 +31,7 @@ from .recordconf import RecordConf
from .recordhepconf import RecordHepConf
from .recordhepinst import RecordHepInst
from .recordheppubli import RecordHepPubli
from .recordhepthesis import RecordHepThesis
from .recordpubli import RecordPubli
from .recordthesis import RecordThesis
......
......@@ -20,6 +20,7 @@ from .recordconf import RecordConf
from .recordhepconf import RecordHepConf
from .recordheppubli import RecordHepPubli
from .recordhepinst import RecordHepInst
from .recordhepthesis import RecordHepThesis
from .recordpubli import RecordPubli
from .recordthesis import RecordThesis
......@@ -216,8 +217,8 @@ def build_record(recjson, shelf=None):
elif shelf == "institutions":
upcast_record = RecordHepInst(recjson)
# elif is_thesis(recjson) and shelf == "literature":
# upcast_record = RecordHepThesis(recjson)
elif is_thesis(recjson) and shelf == "literature":
upcast_record = RecordHepThesis(recjson)
elif shelf == "literature":
upcast_record = RecordHepPubli(recjson)
......
......@@ -43,7 +43,7 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
+---------------+--------------------------------+
| last_name | family name |
+---------------+--------------------------------+
| relator_name | equal to dir. for phd director |
| role | equal to dir. for phd director |
+---------------+--------------------------------+
Note:
......@@ -59,7 +59,8 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
"first_name",
"fmt_name",
"full_name",
"last_name"]
"last_name",
"role"]
self.df_authors = DataFrame([[""] * len(cols)], columns=cols)
return
......@@ -70,6 +71,9 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
if "affiliations" in author:
affiliations = [elt["value"] for elt in author["affiliations"]]
role = \
(author["inspire_roles"] if "inspire_roles" in author else [])
full_name = author["full_name"]
last_name, first_name = full_name.split(",")
......@@ -77,7 +81,8 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
"first_name": first_name.strip(),
"fmt_name": full_name,
"full_name": full_name,
"last_name": last_name.strip()}
"last_name": last_name.strip(),
"role": ", ".join(role)}
data.append(dct)
......
""" store_tools.recordhepthesis
"""
from filters import CLEAN_THESIS_DEFENSE
from .recordheppubli import RecordHepPubli
class RecordHepThesis(RecordHepPubli):
"""Thesis from inspirehep.net version 2.
Schema for publication is documented here:
https://inspire-schemas.readthedocs.io/en/latest/schemas/
"""
def authors_as_list(self, sort=False):
"""The list of author(s) signing the publication.
Note:
supersede the base class since the authors field contains
the author as well as names of director.
Args:
sort (bool): sort authors by first name when true.
Returns:
list:
the list is empty when authors are not defined.
"""
# for a thesis, the authors field contains names of author
# as well as those of directors. The latter have to be removed.
df = self.df_authors
if "role" in df:
df = df[df.role.str.len() == 0]
if sort:
li = (df[["last_name", "fmt_name"]]
.sort_values(by="last_name")
.fmt_name
.tolist())
else:
li = (df.fmt_name
.sort_index()
.tolist())
if len(li) == 1 and li[0] == "":
li = []
return li
def these_defense(self):
"""The defence date for a master/phd thesis.
Returns:
str:
* 10 Dec 2012
* The filter CLEAN_THESIS_DEFENSE is applied.
"""
val = self.get("thesis_info", {}).get("defense_date", "")
return CLEAN_THESIS_DEFENSE(val)
def these_level(self):
"""The level of the thesis.
Returns:
str:
* The value is ``master`` or ``phd``.
* Empty string when it is not defined
"""
return self.get("thesis_info", {}).get("degree_type", "")
def these_directors(self, sep=", "):
"""The list of director(s)
Returns:
str:
* Names are separated by the ``sep`` argument.
* Empty string when it is not defined.
"""
# for a thesis, the author field 700 field contains
# names of the director as well as the name of authors
df = self.df_authors
if "role" in df:
query = df.role.str.len() > 0
df = df.loc[query]
return (sep.join(df.fmt_name) if len(df) > 0 else "")
else:
return ""
def these_universities(self):
"""The university(ies) delivering the thesis diploma.
Returns:
str:
- empty when university(ies) is not defined
- several university are separated by ``&`` character.
"""
lst = self.get("thesis_info", {}).get("institutions", [])
val = [dct.get("name", "") for dct in lst]
return " & ".join(val)
......@@ -19,6 +19,7 @@ from store_tools.recordconf import RecordConf
from store_tools.recordhepconf import RecordHepConf
from store_tools.recordhepinst import RecordHepInst
from store_tools.recordheppubli import RecordHepPubli
from store_tools.recordhepthesis import RecordHepThesis
from store_tools.recordpubli import RecordPubli
from store_tools.recordthesis import RecordThesis
......@@ -156,7 +157,7 @@ def test_institute_ins_02010():
#
# Article, ...
#
def test_article_cds_02011():
def test_article_cds_02021():
"""Precision luminosity measurements at LHCb"""
store = build_store("cds.cern.ch")
......@@ -170,7 +171,7 @@ def test_article_cds_02011():
assert isinstance(record, RecordPubli)
def test_article_inspirehep_02012():
def test_article_inspirehep_02022():
"""Precision luminosity measurements at LHCb"""
store = build_store("inspirehep.net", shelf="literature")
......@@ -188,7 +189,7 @@ def test_article_inspirehep_02012():
#
# Thesis
#
def test_thesis_cds_02013():
def test_thesis_cds_02030():
store = build_store("cds.cern.ch")
recjson = store.get_record(1632177)
......@@ -201,11 +202,24 @@ def test_thesis_cds_02013():
assert isinstance(record, RecordThesis)
def test_thesis_ins_02031():
store = build_store("inspirehep.net", shelf="literature")
recjson = store.get_record(1296381)
assert not is_conference(recjson)
assert not is_institute(recjson)
assert is_thesis(recjson)
record = build_record(recjson, shelf="literature")
assert isinstance(record, RecordHepThesis)
# ............................................................................
#
# Author manipulation
#
def test_to_initial_02014():
def test_to_initial_02040():
assert to_initial("Albert") == "A."
assert to_initial("Antonio Augusto") == "A. A."
......
......@@ -46,7 +46,8 @@ def test_constructor_ins_05002(record):
"first_name",
"fmt_name",
"full_name",
"last_name"]
"last_name",
"role"]
assert len(authors.columns.difference(refcols)) == 0
assert len(authors) == 704
......
......@@ -3,6 +3,7 @@
Test specific methods of the RecordThesis class for::
https://cds.cern.ch/record/1632177
(same as https://inspirehep.net/api/literature/1296381)
Measurement of $t\bar{t}$ spin correlation and W polarization with
the $t\bar{t}$ di-leptonic channel events at ATLAS
......
"""test_09_RecordHepThesis
Test specific methods of the RecordThesis class for::
https://inspirehep.net/api/literature/1296381
(same as https://cds.cern.ch/record/1632177)
Measurement of $t\bar{t}$ spin correlation and W polarization with
the $t\bar{t}$ di-leptonic channel events at ATLAS
L. Chen
10 Dec 2013
No corrections are applied to the record.
Allow to test the brute force decoding with its mistakes.
Note:
* Only the first author is defined
* Record submitted is not defined
* The year is not defined
"""
import pytest
from store_tools import load_record
@pytest.fixture(scope="module")
def record():
return load_record("inspirehep.net", 1296381, shelf="literature")
def test_authors_as_list_ins_09001(record):
assert record.authors_as_list() == [u'Chen, Liming']
def test_these_defense_ins_09002(record):
assert record.these_defense() == "2013-12-10"
def test_these_level_ins_09003(record):
assert record.these_level() == "phd"
def test_these_directors_ins_09004(record):
assert record.these_directors(sep=u"|") == \
"He, Mao|Monnier, Emmanuel|Zhu, Chengguang"
def test_these_universities_ins_09005(record):
assert record.these_universities() == "Shandong U. & Marseille, CPPM"
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