Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
limbra
limbra
Commits
f8f57a5e
Commit
f8f57a5e
authored
Jan 08, 2021
by
LE GAC Renaud
Browse files
Add RecordHepThesis and Test_09_RecordHepThesis
parent
b9de097e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
193 additions
and
10 deletions
+193
-10
modules/store_tools/__init__.py
modules/store_tools/__init__.py
+1
-0
modules/store_tools/factory.py
modules/store_tools/factory.py
+3
-2
modules/store_tools/recordheppubli.py
modules/store_tools/recordheppubli.py
+8
-3
modules/store_tools/recordhepthesis.py
modules/store_tools/recordhepthesis.py
+110
-0
tests/basis/test_02_factory_tools.py
tests/basis/test_02_factory_tools.py
+18
-4
tests/basis/test_05_RecordHepPubli.py
tests/basis/test_05_RecordHepPubli.py
+2
-1
tests/basis/test_08_RecordThesis.py
tests/basis/test_08_RecordThesis.py
+1
-0
tests/basis/test_09_RecordHepThesis.py
tests/basis/test_09_RecordHepThesis.py
+50
-0
No files found.
modules/store_tools/__init__.py
View file @
f8f57a5e
...
...
@@ -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
...
...
modules/store_tools/factory.py
View file @
f8f57a5e
...
...
@@ -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
)
...
...
modules/store_tools/recordheppubli.py
View file @
f8f57a5e
...
...
@@ -43,7 +43,7 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
+---------------+--------------------------------+
| last_name | family name |
+---------------+--------------------------------+
| r
elator_name
| equal to dir. for phd director |
| r
ole
| 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
)
...
...
modules/store_tools/recordhepthesis.py
0 → 100644
View file @
f8f57a5e
""" 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
)
tests/basis/test_02_factory_tools.py
View file @
f8f57a5e
...
...
@@ -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_020
1
1
():
def
test_article_cds_020
2
1
():
"""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_020
1
2
():
def
test_article_inspirehep_020
2
2
():
"""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_020
1
3
():
def
test_thesis_cds_0203
0
():
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_020
1
4
():
def
test_to_initial_0204
0
():
assert
to_initial
(
"Albert"
)
==
"A."
assert
to_initial
(
"Antonio Augusto"
)
==
"A. A."
...
...
tests/basis/test_05_RecordHepPubli.py
View file @
f8f57a5e
...
...
@@ -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
...
...
tests/basis/test_08_RecordThesis.py
View file @
f8f57a5e
...
...
@@ -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
\b
ar{t}$ spin correlation and W polarization with
the $t
\b
ar{t}$ di-leptonic channel events at ATLAS
...
...
tests/basis/test_09_RecordHepThesis.py
0 → 100644
View file @
f8f57a5e
"""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
\b
ar{t}$ spin correlation and W polarization with
the $t
\b
ar{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"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment