Skip to content

Commit 3c2599b

Browse files
committed
Merge branch 'qlever' into template_testing
2 parents 7b597ef + ad3d9f2 commit 3c2599b

File tree

406 files changed

+9930
-9593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

406 files changed

+9930
-9593
lines changed

README-apache-config.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Apache virtual host configuration
2+
3+
Currently runs on <https://qlever.scholia.wiki> and
4+
<https://wikidata-query-gui.scholia.wiki> with the following
5+
Apache configurations.
6+
7+
## qlever.scholia.wiki
8+
9+
```apache
10+
<VirtualHost *:443>
11+
ServerName qlever.scholia.wiki
12+
ServerAdmin webmaster@localhost
13+
14+
SSLEngine On
15+
SSLCertificateFile /etc/letsencrypt/live/qlever.scholia.wiki/fullchain.pem
16+
SSLCertificateKeyFile /etc/letsencrypt/live/qlever.scholia.wiki/privkey.pem
17+
# SSLCertificateFile /etc/letsencrypt/live/qlever.cs.uni-freiburg.de/fullchain.pem
18+
# SSLCertificateKeyFile /etc/letsencrypt/live/qlever.cs.uni-freiburg.de/privkey.pem
19+
Include /etc/letsencrypt/options-ssl-apache.conf
20+
21+
ProxyPass / http://tajo.informatik.privat:8100/
22+
23+
<Directory />
24+
Options Indexes
25+
Options FollowSymLinks
26+
AllowOverride None
27+
Allow from all
28+
</Directory>
29+
30+
ErrorLog ${APACHE_LOG_DIR}/scholia-error.log
31+
CustomLog ${APACHE_LOG_DIR}/scholia-access.log combined
32+
</VirtualHost>
33+
```
34+
35+
## wikidata-query-gui.scholia.wiki
36+
37+
```apache
38+
<VirtualHost *:443>
39+
ServerName wikidata-query-gui.scholia.wiki
40+
ServerAdmin webmaster@localhost
41+
42+
SSLEngine On
43+
SSLCertificateFile /etc/letsencrypt/live/wikidata-query-gui.scholia.wiki/fullchain.pem
44+
SSLCertificateKeyFile /etc/letsencrypt/live/wikidata-query-gui.scholia.wiki/privkey.pem
45+
Include /etc/letsencrypt/options-ssl-apache.conf
46+
47+
ProxyPass / http://tajo.informatik.privat:8080/
48+
49+
<Directory />
50+
Options Indexes
51+
Options FollowSymLinks
52+
AllowOverride None
53+
Allow from all
54+
</Directory>
55+
56+
ErrorLog ${APACHE_LOG_DIR}/wikidata-query-gui-error.log
57+
CustomLog ${APACHE_LOG_DIR}/wikidata-query-gui.log combined
58+
</VirtualHost>
59+
```
60+
61+
62+

runserver.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
from scholia.app import create_app
22
import sys
3+
import logging
4+
5+
# Enable debug logging
6+
logging.basicConfig(level=logging.DEBUG)
37

48
app = create_app(
59
text_to_topic_q_text_enabled=False,
610
third_parties_enabled=True)
711
app.config['APPLICATION_ROOT'] = '/'
812

913
if __name__ == '__main__':
14+
if len(sys.argv) == 3:
15+
hostIP = port=sys.argv[2]
16+
else :
17+
hostIP = '0.0.0.0'
18+
1019
if len(sys.argv) == 2:
11-
app.run(debug=True, port=sys.argv[1])
20+
app.run(debug=True, host=hostIP, port=sys.argv[1])
1221
else:
13-
app.run(debug=True, port=8100)
22+
app.run(debug=True, host=hostIP, port=8100)

scholia/app/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from flask import Flask
77
from flask_bootstrap import Bootstrap, StaticCDN
8+
from werkzeug.middleware.proxy_fix import ProxyFix
89

910
from ..text import TextToTopicQText
1011

@@ -33,6 +34,11 @@ def create_app(text_to_topic_q_text_enabled=True, third_parties_enabled=False):
3334
"""
3435
app = Flask(__name__)
3536

37+
# Configure for proxy deployment
38+
app.wsgi_app = ProxyFix(
39+
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
40+
)
41+
3642
Bootstrap(app)
3743

3844
# Serve assets from wmflabs for privacy reasons

scholia/app/static/scholia.js

Lines changed: 86 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -96,69 +96,74 @@ function convertDataTableData(data, columns) {
9696
}
9797
}
9898
for (var i = 0 ; i < data.length ; i++) {
99-
var convertedRow = {};
100-
for (var key in data[i]) {
101-
if (key.slice(-11) == 'Description') {
102-
convertedRow[key.slice(0, key.length - 11) + ' description'] = data[i][key];
99+
var convertedRow = {};
100+
for (var key in data[i]) {
101+
if (key.slice(-11) == 'Description') {
102+
convertedRow[key.slice(0, key.length - 11) + ' description'] = data[i][key];
103103

104-
} else if (
105-
key + 'Label' in data[i] &&
104+
} else if (
105+
key + 'Label' in data[i] &&
106106
key + 'Url' in data[i]
107-
) {
107+
) {
108108
convertedRow[key] = '<a href="' +
109-
data[i][key + 'Url'] +
110-
'">' + data[i][key + 'Label'] + '</a>';
109+
data[i][key + 'Url'] +
110+
'">' + data[i][key + 'Label'] + '</a>';
111111

112-
} else if (key.slice(-17) == 'ChemicalStructure') {
112+
} else if (key.slice(-17) == 'ChemicalStructure') {
113113
convertedRow[key.slice(0, key.length - 17) + ' structure'] = '<img loading="lazy" src="' +
114114
'https://cdkdepict.toolforge.org/depict/bow/svg?smi=' +
115-
encodeURIComponent(data[i][key]) +
115+
encodeURIComponent(data[i][key]) +
116116
'&abbr=on&hdisp=bridgehead&showtitle=false&zoom=2&annotate=cip' +
117-
'" />';
117+
'" />';
118118

119-
} else if (
120-
key + 'Label' in data[i] &&
121-
/^http/.test(data[i][key]) &&
122-
data[i][key].length > 30
123-
) {
124-
convertedRow[key] = '<a href="../' +
125-
data[i][key].slice(31) +
126-
'">' + data[i][key + 'Label'] + '</a>';
119+
} else if (
120+
key + 'Label' in data[i] &&
121+
/^http/.test(data[i][key]) &&
122+
data[i][key].length > 30
123+
) {
124+
convertedRow[key] = '<a href="../' +
125+
data[i][key].slice(31) +
126+
'">' + data[i][key + 'Label'] + '</a>';
127127

128128
} else if (key.slice(-5) == 'Label') {
129-
// pass
130-
131-
} else if (key + 'Url' in data[i]) {
132-
convertedRow[key] = '<a href="' +
133-
data[i][key + 'Url'] +
134-
'">' + data[i][key] + '</a>';
135-
136-
} else if (key.slice(-3) == 'Url') {
137-
// pass
138-
139-
} else if (key.slice(-3) == 'url') {
140-
// Convert URL to a link
141-
convertedRow[key] = "<a href='" +
142-
data[i][key] + "'>" +
143-
$("<div>").text(data[i][key]).html() + '</a>';
144-
145-
} else if (key == 'orcid') {
146-
// Add link to ORCID website
147-
convertedRow[key] = '<a href="https://orcid.org/' +
148-
data[i][key] + '">' +
149-
data[i][key] + '</a>';
150-
151-
} else if (key == 'doi') {
152-
// Add link to Crossref
153-
convertedRow[key] = '<a href="https://doi.org/' +
154-
encodeURIComponent(data[i][key]) + '">' +
155-
$("<div>").text(data[i][key]).html() + '</a>';
156-
157-
} else {
158-
convertedRow[key] = data[i][key];
159-
}
160-
}
161-
convertedData.push(convertedRow);
129+
// pass
130+
131+
} else if (key + 'Url' in data[i]) {
132+
convertedRow[key] = '<a href="' +
133+
data[i][key + 'Url'] +
134+
'">' + data[i][key] + '</a>';
135+
136+
} else if (key.slice(-3) == 'Url') {
137+
// pass
138+
139+
} else if (key.slice(-3) == 'url') {
140+
// Convert URL to a link
141+
convertedRow[key] = "<a href='" +
142+
data[i][key] + "'>" +
143+
$("<div>").text(data[i][key]).html() + '</a>';
144+
145+
} else if (key == 'orcid') {
146+
// Add link to ORCID website
147+
convertedRow[key] = '<a href="https://orcid.org/' +
148+
data[i][key] + '">' +
149+
data[i][key] + '</a>';
150+
151+
} else if (key == 'doi') {
152+
// Add link to Crossref
153+
convertedRow[key] = '<a href="https://doi.org/' +
154+
encodeURIComponent(data[i][key]) + '">' +
155+
$("<div>").text(data[i][key]).html() + '</a>';
156+
157+
} else {
158+
var convertedRowValue = data[i][key];
159+
if (convertedRowValue.startsWith("http://www.wikidata.org/entity/Q")) {
160+
var qid = convertedRowValue.slice(31);
161+
convertedRowValue = '<a href="../' + qid + '">' + qid + '</a>';
162+
}
163+
convertedRow[key] = convertedRowValue;
164+
}
165+
}
166+
convertedData.push(convertedRow);
162167
}
163168
return { data: convertedData, columns: convertedColumns };
164169
}
@@ -260,7 +265,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
260265
var paging = (typeof options.paging === 'undefined') ? true : options.paging;
261266
var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom;
262267
var sparqlEndpointName = (typeof options.sparqlEndpointName === 'undefined')
263-
? window.jsConfig.sparqlEndpointName : options.sparqlEndpointName;
268+
? window.jsConfig.sparqlEndpointName : options.sparqlEndpointName;
264269

265270
$(element).html("<div class='loader'><div></div><div></div><div></div></div>");
266271

@@ -277,7 +282,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
277282
};
278283
columns.push(column);
279284
}
280-
285+
281286
if (convertedData.data.length <= 10) {
282287
paging = false;
283288
}
@@ -299,7 +304,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
299304
'<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
300305
encodeURIComponent(sparql) +
301306
'">' + sparqlEndpointName + '</a></span>' +
302-
'<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia/scholia/blob/main/scholia/app/templates/' +
307+
'<span style="float:right; font-size:smaller;"><a href="https://github.com/ad-freiburg/scholia/blob/qlever/scholia/app/templates/' +
303308
filename + '">' +
304309
filename.replace("_", ": ") +
305310
'</a></span></caption>'
@@ -359,7 +364,7 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
359364
var paging = (typeof options.paging === 'undefined') ? true : options.paging;
360365
var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom;
361366
var sparqlEndpointName = (typeof options.sparqlEndpointName === 'undefined')
362-
? window.jsConfig.sparqlEndpointName : options.sparqlEndpointName;
367+
? window.jsConfig.sparqlEndpointName : options.sparqlEndpointName;
363368

364369
// overwrite the central URLs of SPARQL specific URLs are found
365370
configFromSPARQL = extractConfig(sparql);
@@ -372,7 +377,7 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
372377
const datatableFooter =
373378
'<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
374379
encodeURIComponent(sparql) + '">' + sparqlEndpointName + '</a></span>' +
375-
'<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia/scholia/blob/main/scholia/app/templates/' +
380+
'<span style="float:right; font-size:smaller;"><a href="https://github.com/ad-freiburg/scholia/blob/qlever/scholia/app/templates/' +
376381
filename +
377382
'">' +
378383
filename.replace('_', ': ') +
@@ -484,11 +489,15 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
484489
}
485490
$(element).append(datatableFooter);
486491
}
487-
}).fail(function () {
492+
}).fail(function (jqXHR, textStatus, errorThrown) {
488493
$('#' + loaderID).remove(); // remove loader
489-
$(element).prepend(
490-
'<p>This query has timed out, we recommend that you follow the link to the Wikidata Query Service below to modify the query to be less intensive. </p> '
491-
);
494+
let error_message = "";
495+
try {
496+
error_message = "QLever execption: " + JSON.parse(jqXHR.responseText).exception;
497+
} catch (e) {
498+
error_message = "getJSON query failed: " + textStatus + " " + errorThrown;
499+
}
500+
$(element).prepend("<p style='color:red;'>" + escapeHTML(error_message) + "</p>");
492501
const reloadButton = document.getElementById(element.slice(1) + '-reload');
493502
reloadButton.classList.add('btn-secondary');
494503
reloadButton.classList.remove('btn-outline-secondary');
@@ -516,6 +525,13 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
516525

517526
if (!embedURL) embedURL = "https://query.wikidata.org/embed.html#";
518527

528+
// overwrite the central URLs of SPARQL specific URLs are found
529+
configFromSPARQL = extractConfig(sparql);
530+
if (configFromSPARQL["url"]) url = configFromSPARQL["url"];
531+
if (configFromSPARQL["editURL"]) editURL = configFromSPARQL["editURL"];
532+
if (configFromSPARQL["embedURL"]) embedURL = configFromSPARQL["embedURL"];
533+
if (configFromSPARQL["endpointName"]) sparqlEndpointName = configFromSPARQL["endpointName"];
534+
519535
const wikidata_sparql = url + "?query=" + encodeURIComponent(sparql);
520536
const wikidata_query = editURL + encodeURIComponent(sparql);
521537
var url = embedURL + encodeURIComponent(sparql);
@@ -549,6 +565,7 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
549565

550566
$.ajax({
551567
url: wikidata_sparql,
568+
headers: { Accept: "application/sparql-results+xml" },
552569
success: function (data) {
553570
let $xml = $(data);
554571
let results = $xml.find('results');
@@ -559,7 +576,7 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
559576
}
560577
$iframe.parent().after(
561578
'<span style="float:right; font-size:smaller">' +
562-
'<a href="https://github.com/WDscholia/scholia/blob/main/scholia/app/templates/' + filename + '">' +
579+
'<a href="https://github.com/ad-freiburg/scholia/blob/qlever/scholia/app/templates/' + filename + '">' +
563580
filename.replace("_", ": ") +
564581
'</a>' +
565582
'</span>'
@@ -796,9 +813,12 @@ function askQuery(panel, askQuery, callback) {
796813

797814

798815
function askQuery2(endpointUrl, panel, askQuery, callback) {
799-
if (!endpointUrl) endpointUrl = "https://query.wikidata.org/sparql";
800-
801-
var settings = {
816+
if (!endpointUrl) endpointUrl = "https://query.wikidata.org/sparql";
817+
// overwrite the central URLs of SPARQL specific URLs are found
818+
configFromSPARQL = extractConfig(askQuery);
819+
if (configFromSPARQL["url"]) endpointUrl = configFromSPARQL["url"];
820+
821+
var settings = {
802822
headers: { Accept: 'application/sparql-results+json' },
803823
data: { query: askQuery },
804824
};
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
SELECT ?mol ?molLabel ?InChIKey ?CAS ?ChemSpider ?PubChem_CID WITH {
2-
SELECT ?mol ?InChIKey WHERE {
3-
SERVICE wikibase:mwapi {
4-
bd:serviceParam wikibase:endpoint "www.wikidata.org";
5-
wikibase:api "Search";
6-
mwapi:srsearch "_shortkey_ haswbstatement:P235";
7-
mwapi:srlimit "max".
8-
?mol wikibase:apiOutputItem mwapi:title.
9-
}
10-
?mol wdt:P235 ?InChIKey .
11-
FILTER (regex(str(?InChIKey), "^_shortkey_"))
1+
{% import 'sparql-helpers.sparql' as sparql_helpers -%}
2+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
3+
SELECT ?mol ?molLabel ?InChIKey ?CAS ?ChemSpider ?PubChem_CID {
4+
?mol wdt:P235 ?InChIKey .
5+
FILTER (REGEX(?InChIKey,"^_shortkey_"))
6+
OPTIONAL {
7+
?mol wdt:P231 ?CAS
128
}
13-
} AS %MOLS {
14-
INCLUDE %MOLS
15-
OPTIONAL { ?mol wdt:P231 ?CAS }
16-
OPTIONAL { ?mol wdt:P661 ?ChemSpider }
17-
OPTIONAL { ?mol wdt:P662 ?PubChem_CID }
18-
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
9+
OPTIONAL {
10+
?mol wdt:P661 ?ChemSpider
11+
}
12+
OPTIONAL {
13+
?mol wdt:P662 ?PubChem_CID
14+
}
15+
{{ sparql_helpers.labels(["?mol"], languages) }}
1916
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
PREFIX wd: <http://www.wikidata.org/entity/>
2+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
13
ASK {
2-
?work wdt:P50 wd:{{q}} . BIND("author-retractions" AS ?aspectsubpage)
3-
{ ?work wdt:P31 wd:Q45182324 } UNION { ?work wdt:P793 wd:Q7316896 . } UNION { ?work wdt:P5824 [] . }
4+
# ?work wdt:P50 wd:{{q}} . BIND("author-retractions" AS ?aspectsubpage)
5+
{
6+
?work wdt:P31 wd:Q45182324
7+
}
8+
UNION {
9+
?work wdt:P793 wd:Q7316896 .
10+
}
11+
UNION {
12+
?work wdt:P5824 [] .
13+
}
414
}

0 commit comments

Comments
 (0)