Permalink
Browse files

Merge branch 'feature/cordisResolve' of https://github.com/egonw/scholia



Conflicts:
	runserver.py
  • Loading branch information...
fnielsen committed Jun 19, 2018
2 parents a9ad2d9 + a26ca19 commit 2445f5284198508d09dcaad1cb0e33e075395e50
Showing with 61 additions and 4 deletions.
  1. +1 −1 runserver.py
  2. +19 −1 scholia/app/views.py
  3. +41 −2 scholia/query.py
@@ -7,4 +7,4 @@
app.config['APPLICATION_ROOT'] = '/'

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True, port=8100)
@@ -13,7 +13,8 @@
from ..arxiv import get_metadata as get_arxiv_metadata
from ..query import (arxiv_to_qs, cas_to_qs, doi_to_qs, github_to_qs,
inchikey_to_qs, issn_to_qs, orcid_to_qs, viaf_to_qs,
q_to_class, random_author, twitter_to_qs)
q_to_class, random_author, twitter_to_qs,
cordis_to_qs)
from ..utils import sanitize_q
from ..wikipedia import q_to_bibliography_templates

@@ -336,6 +337,23 @@ def redirect_cas(cas):
return render_template('404.html')


@main.route('/cordis/<cordis>')
def redirect_cordis(cordis):
"""Detect and redirect for EU CORDIS project IDs.
Parameters
----------
cordis : str
CORDIS identifier.
"""
qs = cordis_to_qs(cordis)
if len(qs) > 0:
q = qs[0]
return redirect(url_for('app.show_project', q=q), code=302)
return render_template('404.html')


@main.route('/catalogue/' + q_pattern)
def show_catalogue(q):
"""Return rendered HTML page for specific catalogue.
@@ -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

Please sign in to comment.