Skip to content

Commit

Permalink
dojson: reference pubnote building refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Bivol <mihai.bivol@cern.ch>
  • Loading branch information
mihaibivol committed Jul 19, 2016
1 parent e5d6bb1 commit fbc2b59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
27 changes: 10 additions & 17 deletions inspirehep/dojson/hep/fields/bd90x99x.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)

from inspirehep.modules.references.processors import ReferenceBuilder
from inspirehep.utils.pubnote import build_pubnote
from inspirehep.utils.record import get_value


Expand Down Expand Up @@ -91,26 +92,18 @@ def get_value(value):

@hep2marc.over('999C5', 'references')
@utils.for_each_value
@utils.filter_values
def references2marc(self, key, value):
"""Produce list of references."""
repnos = value.get('arxiv_eprints', [])
if 'reportnumber' in value.get('publication_info', {}):
repnos.append(value['publication_info']['reportnumber'])
j_title = value.get('publication_info', {}).get('journal_title')
j_vol = value.get('publication_info', {}).get('journal_volume')
j_pg_s = value.get('publication_info', {}).get('page_start')
j_pg_e = value.get('publication_info', {}).get('page_end')
j_artid = value.get('publication_info', {}).get('artid')
pubnote = ''
if j_title and j_vol:
pubnote = '{},{}'.format(j_title, j_vol)
if j_pg_s and j_pg_e:
pubnote += ',{}-{}'.format(j_pg_s, j_pg_e)
elif j_pg_s:
pubnote += ',{}'.format(j_pg_s)
if j_artid and j_artid != j_pg_s:
pubnote += ',{}'.format(j_artid)
# If not found it will be filtered anyway.
repnos.append(get_value(value, 'publication_info.reportnumber'))
journal_title = get_value(value, 'publication_info.journal_title')
journal_volume = get_value(value, 'publication_info.journal_volume')
journal_pg_start = get_value(value, 'publication_info.page_start')
journal_pg_end = get_value(value, 'publication_info.page_end')
journal_artid = get_value(value, 'publication_info.artid')
pubnote = build_pubnote(journal_title, journal_volume, journal_pg_start,
journal_pg_end, journal_artid)
return {
'0': get_recid_from_ref(value.get('record')),
'1': get_value(value, 'texkey'),
Expand Down
15 changes: 15 additions & 0 deletions inspirehep/utils/pubnote.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,18 @@ def split_pubnote(pubnote_str):
page_start, page_end, artid = split_page_artid(parts[2:])

return title, volume, page_start, page_end, artid


def build_pubnote(title, volume, page_start, page_end, artid):
"""Build pubnite string from parts (reverse of split_pubnote)."""
pubnote = None
if title and volume:
pubnote = '{},{}'.format(title, volume)
if page_start and page_end:
pubnote += ',{}-{}'.format(page_start, page_end)
elif page_start:
pubnote += ',{}'.format(page_start)
if artid and artid != page_start:
pubnote += ',{}'.format(artid)

return pubnote

0 comments on commit fbc2b59

Please sign in to comment.