-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
230 lines (205 loc) · 7.31 KB
/
index.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="semantic-ui/semantic.min.css" />
<style type="text/css">
#banner h1 {
padding: 2em 0em;
}
#main {
padding-bottom: 2em;
}
#search-config > p {
text-align: right;
color: rgba(0,0,0,.6);
cursor: pointer;
}
#search-config > p:hover {
text-decoration-line: underline;
}
</style>
<script src="jquery.min.js"></script>
<script src="semantic-ui/semantic.min.js"></script>
<script src="sttl-browser.js"></script>
<script id="search-tpl" type="application/sparql-template">
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX st: <http://ns.inria.fr/sparql-template/>
TEMPLATE <#search-tpl>(?keyword) {
"<div class=\"item\">"
"<div class=\"content\">"
"<div class=\"ui segment accordion\">"
"<div class=\"title\">"
format { "<h3 class=\"header\">%s</h3>" ?label }
format { "<p class=\"description\">%s</p>" ?comment }
"</div>"
"<div class=\"content\">"
format { "<p>IRI: <code><a href=\"%s\">%s</a></code></p>" ?term ?term }
"<p>" st:call-template(<#hierarchy-tpl>, ?term) "</p>"
"<p>" "Related concepts:"
"<ul>"
st:call-template(<#related-tpl>, ?term)
"</ul>"
"</p>"
"</div>"
"</div>"
"</div>"
"</div>"
} WHERE {
?term a ?cl .
VALUES ?cl { rdfs:Class owl:Class } .
?term rdfs:label ?label ;
rdfs:comment ?comment .
FILTER (contains(lcase(?label), ?keyword))
}
</script>
<script id="hierarchy-tpl" type="application/sparql-template">
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX st: <http://ns.inria.fr/sparql-template/>
TEMPLATE <#hierarchy-tpl>(?cl) {
"<p>"
"Hierarchy: "
st:call-template(<#hierarchy-tpl>, ?parent)
format { "> <span><a href=\"%s\">%s</a></span>" ?parent ?label }
"</p>"
} WHERE {
?cl rdfs:subClassOf ?parent .
?parent rdfs:label ?label .
} LIMIT 1
</script>
<script id="related-tpl" type="application/sparql-template">
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ssn: <http://www.w3.org/ns/ssn/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
TEMPLATE <#related-tpl>(?cl) {
"<li>"
format {
"<a href=\"%s\">%s</a> (via property <a href=\"%s\">%s</a>)"
?related ?label ?rel ?relLabel
}
"</li>"
} WHERE {
BIND (?cl AS ?term)
{
?term rdfs:subClassOf ?restriction .
?restriction owl:onProperty ?rel .
?restriction owl:someValuesFrom ?related .
} UNION {
?related rdfs:subClassOf ?restriction .
?restriction owl:onProperty ?rel .
?restriction owl:someValuesFrom ?term .
} UNION {
?term rdfs:subClassOf ?restriction .
?restriction owl:onProperty ?rel .
?restriction owl:allValuesFrom ?related .
} UNION {
?related rdfs:subClassOf ?restriction .
?restriction owl:onProperty ?rel .
?restriction owl:allValuesFrom ?term .
} UNION {
?rel rdfs:domain ?term .
?rel rdfs:range ?related .
} UNION {
?rel rdfs:range ?term .
?rel rdfs:domain ?related .
}
?rel rdfs:label ?relLabel .
?related rdfs:label ?label .
}
</script>
<script>
function search(s) {
display('search-error', false);
let input = document.getElementById('search-input');
input.value = s;
let ul = document.getElementById('search-results');
let keywords = s.toLowerCase().split(' ');
let arg = {
type: 'literal',
value: keywords[0] // TODO
};
sttl.callTemplate(document.documentURI + '#search-tpl', arg)
.then(str => {
ul.innerHTML = str;
$('.ui.accordion').accordion();
})
.catch(err => {
console.log(err);
display('search-error', true);
});
}
function configure(ep) {
let search = document.getElementById('search-ep');
// TODO valid URI?
search.value = ep;
sttl.connect(ep);
}
function showConfiguration(ep) {
let config = document.getElementById('config-ep');
config.value = ep;
}
function display(id, bool) {
let m = $('#' + id);
m.removeClass('hidden').removeClass('visible');
m.addClass(bool ? 'visible' : 'hidden');
}
</script>
</head>
<body>
<div class="ui text container">
<div id="banner">
<h1 class="ui center aligned header">
Web of Things Cloud
<div class="sub header">A collection of Web ontologies for semantic interoperability on the Web of Things</div>
</h1>
<form action="#" method="get">
<div class="ui action input fluid">
<input id="search-input" type="text" name="s" placeholder="Search for concepts..." />
<input id="search-ep" type="text" hidden name="ep" value="http://localhost" />
<button class="ui button">Search</button>
</div>
</form>
<div id="search-config">
<p onclick="$('#config-modal').modal('show');">Change SPARQL endpoint...</p>
<div id="config-modal" class="ui small modal">
<div class="header">SPARQL Endpoint</div>
<div class="content">
<div class="ui input fluid">
<input id="config-ep" type="text" placeholder="Enter a URI..." />
</div>
</div>
<div class="actions">
<button class="ui positive button">OK</button>
</div>
<div/>
</div>
</div>
<div id="main">
<div class="ui items" id="search-results"></div>
<div id="search-error" class="ui negative message hidden">
<div class="header">Cannot connect to SPARQL endpoint.</div>
<p>Have you changed the endpoint URI (default: <code>localhost</code>)?</p>
</div>
</div>
</div>
<script>
document
.querySelectorAll('script[type="application/sparql-template"]')
.forEach(script => {
script = 'BASE <' + document.documentURI + '>' + script.text;
sttl.register(script);
});
$('#config-modal').modal({
onShow: () => showConfiguration($('#search-ep').val()),
onApprove: () => configure($('#config-ep').val())
});
let url = new URL(document.documentURI);
let params = url.searchParams;
if (params.has('ep')) configure(params.get('ep'));
if (params.has('s')) search(params.get('s'));
</script>
</body>
<html>