Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RefExtract: Update eprint extraction in engine and regex #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions refextract/references/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,13 @@ def add_recid_elements(splitted_citations):


def arxiv_urls_to_report_numbers(citation_elements):
arxiv_url_prefix = 'http://arxiv.org/abs/'
arxiv_url_prefix = re.compile('^https?:\/\/(?:(?:cn\.|de\.|in\.|lanl\.)?arxiv\.org|xxx\.lanl\.gov)\/(?:abs|pdf)\/(\S+\d{4})(?:v\d{1,2})?(?:\.pdf)?', re.UNICODE | re.IGNORECASE)
for el in citation_elements:
if el['type'] == 'URL' and el['url_string'].startswith(arxiv_url_prefix):
el['type'] = 'REPORTNUMBER'
el['report_num'] = el['url_string'].replace(arxiv_url_prefix, 'arXiv:')
if el['type'] == 'URL' and el['url_string']:
matchobj = arxiv_url_prefix.match(el['url_string'])
if matchobj:
el['type'] = 'REPORTNUMBER'
el['report_num'] = 'arXiv:' + matchobj.group(1)


def look_for_hdl(citation_elements):
Expand Down
22 changes: 14 additions & 8 deletions refextract/references/regexs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,26 @@ def compute_pos_patterns(patterns):

# Pattern for arxiv numbers
# arxiv 9910-1234v9 [physics.ins-det]
re_arxiv = re.compile(r"""
ARXIV[\s:-]*(?P<year>\d{2})-?(?P<month>\d{2})
[\s.-]*(?P<num>\d{4})(?!\d)(?:[\s-]*V(?P<version>\d))?
re_arxiv = re.compile(r"""(?:(?:https?://(?:www\.)?arxiv\.org/(?:abs|pdf)/)|
(?:https?://(?:xxx\.)?lanl\.gov/(?:abs|pdf)/)|
(?:ARXIV[\s:-]*))(?P<year>\d{2})-?(?P<month>\d{2})
[\s.-]*(?P<num>\d{4})(?!\d)(?:[\s-]*V(?P<version>\d{1,2}))?
(?:\.pdf)?
\s*(?P<suffix>\[[A-Z.-]+\])? """, re.VERBOSE | re.UNICODE | re.IGNORECASE)

re_arxiv_5digits = re.compile(r"""
ARXIV[\s:-]*(?P<year>(1[3-9]|[2-8][0-9]))-?(?P<month>(0[1-9]|1[0-2]))
[\s.-]*(?P<num>\d{5})(?!\d)(?:[\s-]*V(?P<version>\d))?
re_arxiv_5digits = re.compile(r"""(?:(?:https?://(?:www\.)?arxiv\.org/(?:abs|pdf)/)|
(?:https?://(?:xxx\.)?lanl\.gov/(?:abs|pdf)/)|
(?:ARXIV[\s:-]*))(?P<year>(1[3-9]|[2-8][0-9]))-?(?P<month>(0[1-9]|1[0-2]))
[\s.-]*(?P<num>\d{5})(?!\d)
(?:[\s-]*V(?P<version>\d{1,2}))?
(?:\.pdf)?
\s*(?P<suffix>\[[A-Z.-]+\])? """, re.VERBOSE | re.UNICODE | re.IGNORECASE)

# Pattern for arxiv numbers catchup
# arxiv:9910-123 [physics.ins-det]
RE_ARXIV_CATCHUP = re.compile(r"""
ARXIV[\s:-]*(?P<year>\d{2})-?(?P<month>\d{2})
RE_ARXIV_CATCHUP = re.compile(r"""(?:(?:https?://(?:www\.)?arxiv\.org/(?:abs|pdf)/)|
(?:https?://(?:xxx\.)?lanl\.gov/(?:abs|pdf)/)|
(?:ARXIV[\s:-]*))(?P<year>\d{2})-?(?P<month>\d{2})
[\s.-]*(?P<num>\d{3})
\s*\[(?P<suffix>[A-Z.-]+)\]""", re.VERBOSE | re.UNICODE | re.IGNORECASE)

Expand Down
32 changes: 32 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,38 @@ def test_doi_subdivisions():
assert references[0]['linemarker'] == [u'10']


def test_old_arxiv():
ref_line = u'[20] B. Moore, T. R. Quinn, F. Governato, J. Stadel, and G. Lake, "Cold collapse and the corecatastrophe," Mon. Not. Roy. Astron. Soc.310(1999) 1147–1152, arXiv:astro-ph/9903164 [astro-ph].'
res = get_references(ref_line)
references = res[0]
assert references[0]['reportnumber'] == [u'astro-ph/9903164']
assert references[0]['linemarker'] == [u'20']


def test_old_lanl_url_version():
ref_line = u'[44] Navarro, J.F., Frenk, C.S., White, S.D.M. http://xxx.lanl.gov/pdf/astro-ph/9508025v1'
res = get_references(ref_line)
references = res[0]
assert references[0]['reportnumber'] == [u'astro-ph/9508025']
assert references[0]['linemarker'] == [u'44']


def test_old_arxiv_url():
ref_line = u'[298] V. Allori, D. Duerr, S. Goldstein, and N. Zanghi. 2002. Seven steps towards the classical world. Journal of Optics B : Quantum and semiclassical Optics, Volume 4, number 4. https://arxiv.org/abs/quant-ph/0112005'
res = get_references(ref_line)
references = res[0]
assert references[0]['reportnumber'] == [u'quant-ph/0112005']
assert references[0]['linemarker'] == [u'298']


def test_old_arxiv_mirror_url():
ref_line = u'[13] A. Zupanc, et al, Belle Collaboration, https://cn.arxiv.org/abs/hep-ex/0703040 2007'
res = get_references(ref_line)
references = res[0]
assert references[0]['reportnumber'] == [u'hep-ex/0703040']
assert references[0]['linemarker'] == [u'13']


def test_get_plaintext_document_body(tmpdir):
input = [u"Some text\n", u"on multiple lines\n"]
f = tmpdir.join("plain.txt")
Expand Down
24 changes: 24 additions & 0 deletions tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,27 @@ def test_5_digits_suffix_version_new_2012():
ref_line = u"""{any prefix}1210.12345v9 [physics.ins-det]{any postfix}"""
r = tag_arxiv(ref_line)
assert r.strip(': ') == u"{any prefix}1210.12345v9 [physics.ins-det]{any postfix}"


def test_4_digits_new_url():
ref_line = u"""{any prefix}https://arxiv.org/abs/1311.2198{any postfix}"""
r = tag_arxiv(ref_line)
assert r.strip(': ') == u"{any prefix}<cds.REPORTNUMBER>arXiv:1311.2198</cds.REPORTNUMBER>{any postfix}"


def test_5_digits_new_url():
ref_line = u"""{any prefix}https://arxiv.org/abs/1602.03988{any postfix}"""
r = tag_arxiv(ref_line)
assert r.strip(': ') == u"{any prefix}<cds.REPORTNUMBER>arXiv:1602.03988</cds.REPORTNUMBER>{any postfix}"


def test_4_digits_version_new_url():
ref_line = u"""{any prefix}https://arxiv.org/abs/0708.0882v1{any postfix}"""
r = tag_arxiv(ref_line)
assert r.strip(': ') == u"{any prefix}<cds.REPORTNUMBER>arXiv:0708.0882</cds.REPORTNUMBER>{any postfix}"


def test_5_digits_new_pdf_url():
ref_line = u"""{any prefix}https://arxiv.org/pdf/1712.03976.pdf{any postfix}"""
r = tag_arxiv(ref_line)
assert r.strip(': ') == u"{any prefix}<cds.REPORTNUMBER>arXiv:1712.03976</cds.REPORTNUMBER>{any postfix}"