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
Open sidebar
limbra
limbra
Commits
f531e739
Commit
f531e739
authored
Jan 07, 2021
by
LE GAC Renaud
Browse files
Add recordhep.py
parent
e42aa50d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
0 deletions
+162
-0
modules/store_tools/recordhep.py
modules/store_tools/recordhep.py
+162
-0
No files found.
modules/store_tools/recordhep.py
0 → 100644
View file @
f531e739
"""recordhep.py
"""
import
pprint
class
RecordHep
(
dict
):
"""Base class for JSON record coming from inspirehep.net version v2.
Schema documentation is defined here:
https://inspire-schemas.readthedocs.io/en/latest/schemas/
Args:
recjson (dict):
meta data from the JSON record returns by the store
"""
def
__init__
(
self
,
recjson
):
super
().
__init__
(
recjson
)
# meta data
# the authors of my institutes signing the record
# string containing a list of name separated by a comma
self
.
my_authors
=
""
@
staticmethod
def
_oai_url
(
value
):
"""Build the Open Archive Initiative URL.
Args:
value (str):
OAI identifier, *e.g.* ``oai:host:id``
Returns:
str:
the pattern of the string is `https://host/api/literature/id`
The string is empty when it is not defined or when the value
is not well formed.
"""
def
debug
(
self
):
"""Print the record structure on the standard output.
"""
pprint
.
pprint
(
self
)
def
host
(
self
):
"""The store housing the record.
Returns:
str:
"""
return
"inspirehep.net"
def
id
(
self
):
"""The id of the record in the store.
Returns:
int:
"""
return
self
[
"control_number"
]
def
oai
(
self
):
"""The Open Archive Initiative identifier(s).
Returns:
str:
the primary and secondary OAI identifier are separated
by a comma. The pattern of the identifier is ``oai:host:id`` or
an empty string when it is not defined.
"""
lst
=
[
self
.
primary_oai
(),
self
.
secondary_oai
()]
return
", "
.
join
(
lst
).
strip
(
", "
)
def
oai_url
(
self
):
"""The Open Archive Initiative identifier URL(s).
Returns:
str:
the primary and secondary URLs are separated by a comma.
The pattern of the URL is ``https://host/api/literature/id``
or an empty string when it is not defined or when the OAI is
not well formed.
"""
lst
=
[
self
.
primary_oai_url
(),
self
.
secondary_oai_url
()]
return
", "
.
join
(
lst
).
strip
(
", "
)
def
primary_oai
(
self
):
"""The primary Open Archive Initiative identifier.
The primary OAI identifier matches the record identifier.
Returns:
str:
the pattern of the string is ``oai:host:id``.
It is an empty string when not defined
"""
return
f
"oai:inspirehep.net:
{
self
[
'control_number'
]
}
"
def
primary_oai_url
(
self
):
"""The Open Archive Initiative URL for the primary OAI.
Returns:
str:
the pattern of the string is ``https://host/api/literature/id``.
The string is empty when it is not defined or when the OAI
is not well formed.
"""
recid
=
self
[
"control_number"
]
return
f
"https://inspirehep.net/api/literature/
{
recid
}
"
def
secondary_oai
(
self
):
"""The secondary OAI identifier.
the secondary OAI identifier corresponds to the record in the
store, *cds.cern.ch*.
Returns:
str:
the pattern of the string is ``oai:host:id``.
It is an empty string when not defined
"""
if
"external_system_identifiers"
not
in
self
:
return
""
for
elt
in
self
[
"external_system_identifiers"
]:
if
elt
[
"schema"
]
==
"CDS"
:
return
f
"oai:cds.cern.ch:
{
elt
[
'value'
]
}
"
return
""
def
secondary_oai_url
(
self
):
"""The Open Archive Initiative URL for the secondary OAI.
the secondary OAI URL corresponds to the record in the
store, *cds.cern.ch*.
Returns:
str:
the pattern of the string is ``https://host/record/id``.
The string is empty when it is not defined or when the OAI
is not well formed.
"""
if
"external_system_identifiers"
not
in
self
:
return
""
for
elt
in
self
[
"external_system_identifiers"
]:
if
elt
[
"schema"
]
==
"CDS"
:
return
f
"https://cds.cern.ch/record/
{
elt
[
'value'
]
}
"
return
""
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