-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
305 lines (280 loc) · 12.1 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="lib/jquery/jquery-ui.min.css" />
<link rel="stylesheet" href="lib/Smoothness/jquery.ui.all.css" />
<link rel="stylesheet" href="annotate.css" />
<script type="text/javascript" src="lib/jquery/jquery-1.8.2.js"></script>
<!--<script type="text/javascript" src="lib/jquery-ui.1.9m5.js"></script>-->
<script type="text/javascript" src="lib/jqueryui/jquery-ui.1.10.2.min.js"></script>
<!--
<script type="text/javascript" src="lib/jqueryui/jquery-ui.1.8.24.js"></script>
-->
<script type="text/javascript" src="lib/underscore-min.js"></script>
<script type="text/javascript" src="lib/backboneJS/backbone.js"></script>
<script type="text/javascript" src="lib/hallo/hallo.js"></script>
<script type="text/javascript" src="lib/hallo/format.js"></script>
<script type="text/javascript" src="lib/jquery.rdfquery.debug.js"></script>
<script type="text/javascript" src="lib/vie/vie.js"></script>
<script type="text/javascript" src="lib/vie.entitypreview.js"></script>
<script type="text/javascript" src="lib/annotate.js"></script>
<style>
article {
padding: 10px;
}
#loadingDiv {
position: absolute;
top: 10px;
right: 10px;
}
</style>
<script>
if (window.JSON === undefined ) {
document.write('<' + 'script src="lib/json/json2.js">/script>"></' + 'script>');
}
$(document).ready(function(){ _.defer(function(){
var stanbolUrl = "http://dev.iks-project.eu:8081";
$('#loadingDiv')
.hide() // hide it initially
.ajaxStart(function() {
$(this).show();
})
.ajaxStop(function() {
$(this).hide();
});
function getChain(){
return $("#chain").val();
}
// Whenever the chain selector changes, tell annotate.js about it.
$("#chain").bind('change', function (e) {
var z = new VIE();
var chain = getChain();
z.use(new z.StanbolService({
// remove "/enhancervie" or "/enhancervie/" from the end of the uri.
// it.publicBaseUri gives back http://localhost:8080 or so if redirected so it's not useful.
url: stanbolUrl,
enhancer: {chain: chain}
}));
$('.content').annotate('option', 'vie', z);
var state = $('.enhanceButton').prop('checked');
if (state) {
$('.content').annotate('disable');
_.defer(function(){
$('.content').annotate('enable');
});
}
});
// make the content element editable
$('.content').hallo({
plugins: {
// 'halloformat': {}
},
editable: true
});
function enable(){
$('.content')
.each(function(){
$(this)
.annotate('enable', function(success){
if(success){
$('.enhanceButton')
.button('enable')
.button('option', 'label', 'Done');
$('.acceptAllButton')
.show()
.button('enable')
} else {
$('.enhanceButton')
.button('enable')
.button('option', 'label', 'error, see the log.. Try to enhance again!');
}
});
});
}
function instantiate(){
var z = new VIE();
z.use(new z.StanbolService({
url : stanbolUrl
// enhancer: {chain: getChain()}
}));
$('.content').annotate({
vie: z,
// typeFilter: ["http://dbpedia.org/ontology/Place", "http://dbpedia.org/ontology/Organisation", "http://dbpedia.org/ontology/Person"],
debug: true,
continuousChecking: true,
//autoAnalyze: true,
showTooltip: true,
decline: function(event, ui){
console.info('decline event', event, ui);
},
select: function(event, ui){
console.info('select event', event, ui);
},
remove: function(event, ui){
console.info('remove event', event, ui);
},
success: function(event, ui){
console.info('success event', event, ui);
},
error: function(event, ui){
console.info('error event', event, ui);
alert(ui.message);
}
});
}
instantiate();
$('.acceptAllButton')
.button()
.hide()
.click(function(){
$('.content')
.each(function(){
$(this)
.annotate('acceptAll', function(report){
console.log('AcceptAll finished with the report:', report);
});
})
$('.acceptAllButton')
.button('disable');
});
$('.enhanceButton')
.button()
.change(function(e){
var button = $(e.target);
var state = button.prop('checked');
$('.enhanceButton').prop('checked', state).button('refresh');
if(state){
$('.enhanceButton').button('option', 'label', 'Done');
enable();
$('.acceptAllButton')
.show();
} else {
// annotate.disable()
$('.content').annotate('disable');
$('.enhanceButton').button('option', 'label', 'Enhance!');
$('.acceptAllButton')
.hide();
}
});
function getChains(stanbolUri, cb) {
var query = "PREFIX enhancer: <http://stanbol.apache.org/ontology/enhancer/enhancer#> \n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"SELECT distinct ?name ?chain " +
"WHERE { " +
"?chain a enhancer:EnhancementChain. \n" +
"?chain rdfs:label ?name .\n" +
"} " +
"ORDER BY ASC(?name) ";
function success(res) {
var chains = $('binding[name=name] literal', res).map(function () {
return this.textContent;
}).toArray();
if (_(chains).indexOf('default') != -1) {
chains = _.union(['default'], chains);
}
cb(null, chains);
}
function error(xhr) {
cb(xhr);
}
var uri = stanbolUri + "/enhancer/sparql";
$.ajax({
type: "POST",
url: uri,
data: {query: query},
// accepts: ["application/json"],
accepts: {'application/json': 'application/sparql-results+json'},
// dataType: "application/json",
success: success,
error: error
});
// var xhr = $.getJSON(uri,success);xhr.error(error);
}
function fillChainList(cb) {
var v = new VIE();
v.use(new v.StanbolService({url: stanbolUrl}));
getChains(stanbolUrl, function (err, chains) {
if (err) {
console.info(err);
$('#chain').html("<option>Error loading chains</option>");
$('#error').html('Error loading list of chains from ' + stanbolUrl);
} else {
console.info('Chains:', chains);
$('#chain').html('');
for (i in chains) {
var chain = chains[i];
$('#chain').append("<option value='" + chain + "'>" + chain + "</option>");
}
cb();
}
});
}
// Fill in the chain list, then initialize the annotate.js widget.
fillChainList(instantiate);
jQuery('.instantiate').button().click(instantiate);
jQuery('.destroy').button().click(function(){
jQuery('.content').annotate('destroy');
});
jQuery('.enable').button().click(function(){
enable();
});
jQuery('.disable').button().click(function(){
jQuery('.content').annotate('disable');
});
jQuery('.listDom').button().click(function(){
alert(jQuery('.content')[0].outerHTML);
});
});});
</script>
</head>
<body xmlns:sioc = "http://rdfs.org/sioc/ns#"
xmlns:skos = "http://www.w3.org/2004/02/skos/core#"
xmlns:schema = "http://schema.org/">
<div class="panel" id="webview">
<h2>Test annotate.js on itself</h2>
<div>
<label>
Enhancement chain:
<select id="chain" value="default">
<option>not loaded yet</option>
</select>
</label>
</div>
<input type="checkbox" class="enhanceButton" id="enhanceButton1" /><label for="enhanceButton1">Enhance!</label>
<button class="acceptAllButton" style="display:none;">Accept all</button>
<article typeof="schema:CreativeWork" about="http://stanbol.apache.org/enhancertest">
<div property="sioc:content" class="content"><p>
Hungary i/ˈhʌŋɡəri/ (Hungarian: Magyarország [ˈmɒɟɒrorsaːɡ] ( listen)) is a landlocked country in
Central Europe.[6] It is situated in the Carpathian Basin and is bordered by Slovakia to the north,
Ukraine, and Romania to the east, Serbia, and Croatia to the south, Slovenia to the southwest and
Austria to the west. The country's capital, and largest city, is Budapest. Hungary is a member of
the European Union, NATO, the OECD, the Visegrád Group, and the Schengen Agreement. The official
language is Hungarian, also known as Magyar, which is part of the Finno-Ugric group and is the most
widely spoken non-Indo-European language in Europe.[7]
</p>
<p>
Following periods of successive habitation by Celts, Romans, Huns, Slavs, Gepids, and Avars, the
foundation of Hungary was laid in the late 9th century by the Hungarian grand prince Árpád, whose
great-grandson Saint Stephen I ascended to the throne in 1000 AD. The Kingdom of Hungary existed
for 946 years,[note 1] and at various points was regarded as a major political power in Europe, as
well as one of the cultural centres of the Western world.[8] After about 150 years of partial
Ottoman occupation (1541–1699), Hungary was integrated into the Habsburg Monarchy, and later
constituted half of the Austro–Hungarian Empire (1867–1918).
</p>
</div>
</article>
<input type="checkbox" class="enhanceButton" id="enhanceButton2" /><label for="enhanceButton2">Enhance!</label>
<button class="acceptAllButton" style="display:none;">Accept all</button>
</div>
<div>
<h2>Debug the widget states</h2>
<button class="destroy">Destroy</button>
<button class="instantiate">Instantiate</button>
<button class="enable">Enable</button>
<button class="disable">Disable</button>
<button class="listDom">Show Dom Html</button>
</div>
<p>See source code on <a href="https://github.com/szabyg/annotate.js">Github</a></p>
<div id="loadingDiv" style="display:none;"><img src="spinner.gif"/></div>
</body>
</html>