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
9b4a0fdb
Commit
9b4a0fdb
authored
Jun 20, 2017
by
LE GAC Renaud
Browse files
Redesing the base function is_conference, is_institute, is_thesis.
parent
5a7bf40d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
98 deletions
+167
-98
modules/invenio_tools/base.py
modules/invenio_tools/base.py
+61
-37
tests/basis/test_02_Record.py
tests/basis/test_02_Record.py
+106
-0
tests/invenio_tools/Marc12/test_marc.py
tests/invenio_tools/Marc12/test_marc.py
+0
-61
No files found.
modules/invenio_tools/base.py
View file @
9b4a0fdb
...
...
@@ -31,64 +31,81 @@ REG_YEAR = re.compile(r"(\d{4})")
THESIS_DIR
=
"dir."
def
is_conference
(
rec
ord
):
def
is_conference
(
rec
json
):
"""True when the record describes a publication related to a conference.
Args:
rec
ord (Record): MARC12 record associated to a publication
or to and institute.
rec
json (dict):
record associated to a publication
or to and institute.
Return:
bool: ``True`` when the MARC record describes a publication related
bool:
``True`` when the record describes a publication related
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
# try with the conference key
# the location of this values depends on the store
# cds.cern.ch (962, n) and inspirehep.net (773,w).
if
record
.
host
().
startswith
(
"cds"
):
field
,
subfield
=
"962"
,
"n"
else
:
field
,
subfield
=
"773"
,
"w"
# 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
len
(
record
.
_get
(
field
,
subfield
))
>
0
return
False
def
is_institute
(
rec
ord
):
def
is_institute
(
rec
json
):
"""True when the record describes an institute.
Args:
rec
ord (Record): MARC12 record associated to a publication
or to and institute.
rec
json (dict):
record associated to a publication
or to and institute.
Return:
bool: ``True`` when the MARC record describes an institute.
bool:
``True`` when the record describes an institute.
"""
# "980": [
# {"b": ["CK90", "HEP200", "PDGLIST", "PPF", "TOP500", "WEB"]},
# {"a": "INSTITUTION"},
# {"a": "CORE"}
# ]
if
"980"
in
record
:
if
isinstance
(
record
[
"980"
],
list
):
for
di
in
record
[
"980"
]:
for
k
,
v
in
di
.
items
():
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
# INSTITUTION in collection
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
(
rec
ord
):
def
is_thesis
(
rec
json
):
"""True when the record describes a thesis.
Args:
...
...
@@ -99,6 +116,13 @@ def is_thesis(record):
bool: ``True`` when the MARC record describes a thesis.
"""
li
=
record
.
_get
(
"980"
,
"a"
,
force_list
=
True
)
val
=
", "
.
join
(
li
)
return
"THESIS"
in
val
# THESIS in collection
if
"collection"
in
recjson
:
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
tests/basis/test_02_Record.py
0 → 100644
View file @
9b4a0fdb
# -*- 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
)
tests/invenio_tools/Marc12/test_marc.py
deleted
100644 → 0
View file @
5a7bf40d
"""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
)
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