-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
163 lines (148 loc) · 7.18 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
<html>
<head>
<meta charset="UTF-8">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="typeahead.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="uduvudu-dbpedia-package.js" type="text/javascript"></script>
<script src="matcher.js" type="text/javascript"></script>
</head>
<body>
<div class="container" style="width: 560px">
<div id="intro">
<h1>UDUVUDU – DBpedia Viewer</h1>
This proof of concept application shows <a href="https://github.com/uduvudu/uduvudu/">UDUVUDU</a> rendering entries from <a href="http://dbpedia.org">DBpedia</a>. <small>It further makes uses of <!--<a href="http://linkeddatafragments.org/">linked data fragments</a>, --><a href="https://github.com/zazukoians/rdf-ext">rdf-ext</a> and also <a href="http://getbootstrap.com/">bootstrap</a> and <a href="https://twitter.github.io/typeahead.js/">typeaheadjs</a>.</small>
<br>
Please start searching for an entry in DBpedia by typing at least 3 letters. To confirm your decision select a proposition in the list.
</div>
<div id="chooser">
<br>
<form class="form-inline" role="form">
<div class="form-group col-md-10" style="padding-left: 0">
<input class="typeahead form-control" type="text" placeholder="search ..." autofocus>
</div>
<div class="form-group" style="width: 13.5%;">
<select id="language" class="form-control">
<option></option>
<option>ar</option>
<option>de</option>
<option>en</option>
<option>es</option>
<option>fr</option>
<option>it</option>
<option>nl</option>
<option>pt</option>
<option>ru</option>
<option>ja</option>
<option>zh</option>
</select>
</div>
</form>
</div>
<div id="main">
</div>
<div id="footer" style="clear: both">
</div>
</div>
<div id="visualizer">
</div>
<script type="text/javascript">
var t_start, t_loaded, t_end;
// typeahead source
var dbpedia = function() {
return function findMatches(q, cb) {
$.ajax(
"https://lookup.dbpedia.org/api/prefix?format=json&query="+q,
{dataType: "json"}
).done(function(data) {
cb(data.docs)
// cb(_.sortBy(_.sortBy(data.docs, function(b){return b.label.length}),function(s){return -s.label.search(new RegExp('^'+q,'i'))}));
});
};
};
// initialize type ahead
$('#chooser .typeahead').typeahead({
hint: true,
autoselect: true,
highlight: true,
minLength: 2
},
{
name: 'dbpedia',
displayKey: 'label',
source: dbpedia()
});
var language = 'en';
document.getElementById('language').onchange = function (e) {
language = this.options[this.selectedIndex].value;
if (uduvudu.options) {
t_loaded = t_start = +new Date();
uduvudu.process(undefined, {'language': language});
};
};
// prepare visualizer templates for uduvudu
$("#visualizer").load("visualizer.html");
// helper to decipher the get query
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function loadFromSource(source, resource) {
console.log(source, resource);
var query = "https://dbpedia.org/sparql?query="+encodeURIComponent("CONSTRUCT { <" + source + "> ?p ?o. ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l} WHERE { <"+ source +"> ?p ?o. OPTIONAL {?o <http://www.w3.org/2000/01/rdf-schema#label> ?l.}}")+"&format="+encodeURIComponent("text/turtle")
var store = new rdf.LdpStore();
document.getElementById('main').innerHTML = ''
+ '<div class="alert alert-info">'
+ ' <button type="button" class="close" data-dismiss="alert">×</button>'
+ ' <strong>Loading</strong> '+source+' is being loaded ...'
+ '</div>';
// load triples
store.graph(query, function (error, graph) {
if (error == null) {
console.debug("successfully loaded "+graph.toArray().length+" triples");
// resource (entry for template search) is same as source in this example
uduvudu.process(graph, {'resource': resource, 'language': language} , function (out) {
// where to add the processed html
var main = document.getElementById('main')
// write the result of the processing in the main div
main.innerHTML = out;
// run scripts which were added
var codes = main.getElementsByTagName("script");
for(var i=0;i<codes.length;i++)
{
eval(codes[i].text);
}
});
} else {
document.getElementById('main').innerHTML = ''
+ '<div class="alert alert-danger">'
+ ' <button type="button" class="close" data-dismiss="alert">×</button>'
+ ' <strong>Error:</strong> '+ error +'.'
+ '</div>';
};
});
};
// if uri is specified in title get it
var uri = getParameterByName('res');
if (uri != '') {
loadFromSource(uri, uri);
}
$('#chooser .typeahead').on('typeahead:selected', function (event, d) {
var uri = d.resource[0];
loadFromSource(uri, uri);
});
$('#setSource').on('keyup', function() {
loadFromSource(this.value, $('#setResource').val());
});
$('#setResource').on('keyup', function() {
loadFromSource($('#setSource').val(), this.value);
});
$('#selectSource').on('change', function(event) {
loadFromSource(this.value, event.target.selectedOptions[0].attributes['data-res'].nodeValue);
});
</script>
</body>
</html>