-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.html
137 lines (103 loc) · 3.85 KB
/
query.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<style>
table, tr, td, th {
border-collapse: collapse;
border: 1px solid black;
}
td {
padding: 5px;
}
th {
padding: 5px;
background-color: #e0e0e0;
}
BODY DIV {
margin: 10px;
}
</style>
</head>
<body>
<div>
<div>
<textarea id="query" rows="10" cols="60"></textarea>
</div>
<div>
<button id="submit">Submit</button>
<button id="b0">KTN information exchange challenges</button>
<button id="b1">Farming challenges</button>
<button id="b2">Source/topic map</button>
</div>
</div>
<div id="output">
</div>
<script language="JavaScript">
function handle() {
var div = document.getElementById("output");
while (div.firstChild) {
div.removeChild(div.firstChild);
}
var resp = this.responseXML;
if (resp == null) {
div.appendChild(document.createTextNode(this.responseText));
return;
}
var elt = document.createElement("table");
div.appendChild(elt);
var tr = document.createElement("tr");
elt.appendChild(tr);
var vars = resp.getElementsByTagName("head")[0].children;
for (var i = 0; i < vars.length; i++) {
var variable = vars[i].getAttribute("name")
var th = document.createElement("th");
tr.appendChild(th);
th.appendChild(document.createTextNode(variable));
}
var rows = resp.getElementsByTagName("results")[0].children;
for (var i = 0; i < rows.length; i++) {
var tr = document.createElement("tr");
elt.appendChild(tr);
for (var j = 0; j < rows[i].children.length; j++) {
var item = rows[i].children[j];
var val = "";
var intern = item.getElementsByTagName("uri");
if (intern.length > 0) {
val = intern[0].textContent;
} else {
var intern = item.getElementsByTagName("literal");
if (intern.length > 0) {
val = intern[0].textContent;
}
}
var td = document.createElement("td");
tr.appendChild(td);
td.appendChild(document.createTextNode(val));
}
}
}
function run_query() {
var req = new XMLHttpRequest();
req.addEventListener("load", handle);
req.overrideMimeType("text/xml");
var query = document.getElementById('query').value;
const url = "/sparql?query=" + encodeURIComponent(query);
req.open("GET", url);
req.send();
}
function execute(q) {
document.getElementById("query").value = q;
run_query();
}
var b0 = "SELECT DISTINCT ?title ?opens ?closes\nWHERE {\n ?chl <http://pivotlabs.vc/challenges/p#has-source>\n <http://pivotlabs.vc/challenges/s/ktnie> .\n ?chl <http://pivotlabs.vc/challenges/p#title> ?title .\n ?chl <http://pivotlabs.vc/challenges/p#opens> ?opens .\n ?chl <http://pivotlabs.vc/challenges/p#closes> ?closes .\n}\nLIMIT 25";
var b1 = "SELECT DISTINCT ?title ?url\nWHERE {\n ?chl <http://pivotlabs.vc/challenges/p#has-topic>\n <http://pivotlabs.vc/challenges/t/farming> .\n ?chl <http://pivotlabs.vc/challenges/p#title> ?title .\n ?chl <http://purl.org/dc/elements/1.1/relation> ?url .\n}\nLIMIT 25";
var b2 = "SELECT DISTINCT ?source ?topic\nWHERE {\n ?chl <http://pivotlabs.vc/challenges/p#has-topic> ?t .\n ?chl <http://pivotlabs.vc/challenges/p#has-source> ?s .\n ?s <http://www.w3.org/2000/01/rdf-schema#label> ?source .\n ?t <http://www.w3.org/2000/01/rdf-schema#label> ?topic .\n}\nLIMIT 25";
document.getElementById("submit").onclick = run_query;
document.getElementById("b0").onclick = function() { execute(b0); };
document.getElementById("b1").onclick = function() { execute(b1); };
document.getElementById("b2").onclick = function() { execute(b2); };
var params = new URLSearchParams(window.location.search);
query = params.get('query');
execute(query);
</script>
</body>
</html>