|
@@ -3,6 +3,7 @@ |
|
|
|
Usage: |
|
|
|
scholia.query arxiv-to-q <arxiv> |
|
|
|
scholia.query cas-to-q <cas> |
|
|
|
scholia.query cordis-to-q <cordis> |
|
|
|
scholia.query count-scientific-articles |
|
|
|
scholia.query doi-to-q <doi> |
|
|
|
scholia.query github-to-q <github> |
|
@@ -353,8 +354,8 @@ def search_article_titles_to_quickstatements(q, search_string=None): |
|
|
|
articles = search_article_titles(q, search_string=search_string) |
|
|
|
quickstatements = u('') |
|
|
|
for article in articles: |
|
|
|
quickstatements += u("{article_q}\twdt:P921\t{topic_q} /* {title} */\n" |
|
|
|
).format( |
|
|
|
quickstatements += u( |
|
|
|
"{article_q}\twdt:P921\t{topic_q} /* {title} */\n").format( |
|
|
|
article_q=article['q'], topic_q=q, title=article['title']) |
|
|
|
return quickstatements |
|
|
|
|
|
@@ -666,6 +667,39 @@ def inchikey_to_qs(inchikey): |
|
|
|
for item in data['results']['bindings']] |
|
|
|
|
|
|
|
|
|
|
|
def cordis_to_qs(cordis): |
|
|
|
"""Convert CORDIS project ID to Wikidata ID. |
|
|
|
|
|
|
|
Parameters |
|
|
|
---------- |
|
|
|
cordis : str |
|
|
|
CORDIS identifier |
|
|
|
|
|
|
|
Returns |
|
|
|
------- |
|
|
|
qs : list of str |
|
|
|
List of strings with Wikidata IDs. |
|
|
|
|
|
|
|
Examples |
|
|
|
-------- |
|
|
|
>>> cordis_to_qs('604134') == ['Q27990087'] |
|
|
|
True |
|
|
|
|
|
|
|
""" |
|
|
|
# This query only matches on exact match |
|
|
|
query = """select ?item |
|
|
|
where {{ ?item wdt:P3400 "{cordis}" }}""".format( |
|
|
|
cordis=escape_string(cordis)) |
|
|
|
|
|
|
|
url = 'https://query.wikidata.org/sparql' |
|
|
|
params = {'query': query, 'format': 'json'} |
|
|
|
response = requests.get(url, params=params, headers=HEADERS) |
|
|
|
data = response.json() |
|
|
|
|
|
|
|
return [item['item']['value'][31:] |
|
|
|
for item in data['results']['bindings']] |
|
|
|
|
|
|
|
|
|
|
|
def cas_to_qs(cas): |
|
|
|
"""Convert a CAS registry number to Wikidata ID. |
|
|
|
|
|
@@ -741,6 +775,11 @@ def main(): |
|
|
|
if len(qs) > 0: |
|
|
|
print(qs[0]) |
|
|
|
|
|
|
|
elif arguments['cordis-to-q']: |
|
|
|
qs = cordis_to_qs(arguments['<cordis>']) |
|
|
|
if len(qs) > 0: |
|
|
|
print(qs[0]) |
|
|
|
|
|
|
|
elif arguments['count-scientific-articles']: |
|
|
|
count = count_scientific_articles() |
|
|
|
print(count) |
|
|
0 comments on commit
2445f52