|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
# Function here may belong somewhere else. In the mean time...
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from . import color
|
|
|
|
|
from . import pretty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True):
|
|
|
|
|
"""Check that a citekey exists, or autocompletes it if not ambiguous."""
|
|
|
|
|
""" :returns found citekey """
|
|
|
|
@ -47,6 +47,7 @@ def resolve_citekey_list(repo, citekeys, ui=None, exit_on_fail=True):
|
|
|
|
|
else:
|
|
|
|
|
return keys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def standardize_doi(doi):
|
|
|
|
|
"""
|
|
|
|
|
Given a putative doi, attempts to always return it in the form of
|
|
|
|
@ -60,22 +61,22 @@ def standardize_doi(doi):
|
|
|
|
|
and attempts to verify doi adherence to DOI handbook standards and
|
|
|
|
|
crossref.org advice:
|
|
|
|
|
https://www.doi.org/doi_handbook/2_Numbering.html
|
|
|
|
|
https://www.crossref.org/blog/dois-and-matching-regular-expressions/"""
|
|
|
|
|
""" :returns standardized doi """
|
|
|
|
|
https://www.crossref.org/blog/dois-and-matching-regular-expressions/
|
|
|
|
|
|
|
|
|
|
:returns standardized doi
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
doi_regexes = (
|
|
|
|
|
re.compile(r'(10\.\d{4,9}/[-._;()/:A-z0-9\>\<]+)'),
|
|
|
|
|
re.compile(r'(10.1002/[^\s]+)'),
|
|
|
|
|
re.compile(r'(10\.\d{4}/\d+-\d+X?(\d+)\d+<[\d\w]+:[\d\w]*>\d+.\d+.\w+;\d)'),
|
|
|
|
|
re.compile(r'(10\.1021/\w\w\d+\+)'),
|
|
|
|
|
re.compile(r'(10\.1207/[\w\d]+\&\d+_\d+)')
|
|
|
|
|
)
|
|
|
|
|
'(10\.\d{4,9}/[-._;()/:A-z0-9\>\<]+)',
|
|
|
|
|
'(10.1002/[^\s]+)',
|
|
|
|
|
'(10\.\d{4}/\d+-\d+X?(\d+)\d+<[\d\w]+:[\d\w]*>\d+.\d+.\w+;\d)',
|
|
|
|
|
'(10\.1021/\w\w\d+\+)',
|
|
|
|
|
'(10\.1207/[\w\d]+\&\d+_\d+)')
|
|
|
|
|
doi_pattern = re.compile('|'.join(doi_regexes))
|
|
|
|
|
|
|
|
|
|
for doi_regex in doi_regexes:
|
|
|
|
|
match = doi_regex.search(doi)
|
|
|
|
|
if match:
|
|
|
|
|
new_doi = match.group(0)
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
new_doi = None
|
|
|
|
|
match = doi_pattern.search(doi)
|
|
|
|
|
if not match:
|
|
|
|
|
raise ValueError("Not a valid doi: %s", doi)
|
|
|
|
|
new_doi = match.group(0)
|
|
|
|
|
|
|
|
|
|
return new_doi
|
|
|
|
|