Skip to content

Commit 895535c

Browse files
larsgwegonw
authored andcommitted
Handle DOI URLs and prefixed DOIs
Fixes #2729
1 parent 1c9e175 commit 895535c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scholia/query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
import requests
5959

60+
import re
61+
6062
from six import u
6163

6264
from .config import config
@@ -370,6 +372,9 @@ def doi_to_qs(doi):
370372
371373
Wikidata Query Service is used to resolve the DOI.
372374
375+
If the DOI is given as a URL or with a "doi:" prefix,
376+
that is removed first.
377+
373378
The DOI string is converted to uppercase before any
374379
query is made. Uppercase DOIs are default in Wikidata.
375380
@@ -395,7 +400,15 @@ def doi_to_qs(doi):
395400
>>> doi_to_qs(doi) == ['Q135403558']
396401
True
397402
403+
>>> doi = 'https://doi.org/10.3390/MICROORGANISMS12071299'
404+
>>> doi_to_qs(doi) == ['Q135390431']
405+
True
406+
407+
>>> doi_to_qs('doi:10.3390/MICROORGANISMS12071299') == ['Q135390431']
408+
True
409+
398410
"""
411+
doi = re.sub(r'(?i)^(https?://(www\.|dx\.)?doi\.org/?|doi:)', '', doi)
399412
query = SPARQL_PREFIXES + (
400413
'select ?work where {{ ?work wdt:P356 "{doi}" }}').format(
401414
doi=escape_string(doi.upper()))

0 commit comments

Comments
 (0)