";
+
+ if($.isArray(e["resource"]))
+ var firstRes = e["resource"][0];
+ else
+ var firstRes = e["resource"];
+
+ var support = parseInt(firstRes["@support"]);
+ var confidence = parseFloat(firstRes["@finalScore"]);
+ var classes = "annotation support_" + support + " confidence_" + confidence;
+
+ snippet += "
" + sfName + "";
//TODO instead of showing directly the select box, it would be cuter to just show a span, and onClick on that span, build the select box.
var ul = Parser.getSelectBox($(e.resource),'candidate');
//ul.children().each(function() { console.log($.data($(this),"testProp")); });
@@ -96,6 +107,43 @@
//console.log(annotatedText);
return annotatedText;
},
+ getAnnotatedTextFirstBest: function(response) {
+ var json = $.parseJSON(response);
+ if (json==null) json = response; // when it comes already parsed
+
+ var text = json["@text"];
+
+ var start = 0;
+ var annotatedText = text;
+
+ if (json['Resources']!=undefined)
+ var annotations = new Array().concat(json.Resources) // deals with the case of only one surfaceFrom returned (ends up not being an array)
+
+ annotatedText = annotations.map(function(e) {
+ if (e==undefined) return "";
+
+ var sfName = e["@surfaceForm"];
+ var offset = parseInt(e["@offset"]);
+ var uri = e["@URI"];
+
+ var sfLength = parseInt(sfName.length);
+ var snippet = text.substring(start, offset)
+ var surfaceForm = text.substring(offset,offset+sfLength);
+ start = offset+sfLength;
+
+ var support = parseInt(e["@support"]);
+ var confidence = 0.0;
+ var classes = "annotation support_" + support + " confidence_" + confidence;
+ snippet += "
" + sfName + "";
+
+ return snippet;
+ }).join("");
+ //snippet after last surface form
+ annotatedText += text.substring(start, text.length);
+ //console.log(annotatedText);
+ return annotatedText;
+ },
+
getSuggestions: function(response, targetSurfaceForm) {
var json = $.parseJSON(response);
if (json==null) json = response; // when it comes already parsed
@@ -112,6 +160,7 @@
}
};
+ var ajaxRequest;
var methods = {
init : function( options ) {
// If options exist, lets merge them with our default settings
@@ -122,13 +171,12 @@
best: function( options ) {
//init(options);
function update(response) {
- //console.log($(response));
- var content = $(response).find("div"); //the div with the annotated text
- if (settings.powered_by == 'yes') {
- $(content).append($(powered_by));
- };
- //var entities = $(content).find("a/[about]");
- $(this).html(content);
+
+ var content = "
" + Parser.getAnnotatedTextFirstBest(response) + "
";
+ if (settings.powered_by == 'yes') {
+ $(content).append($(powered_by));
+ };
+ $(this).html(content);
if(settings.callback != undefined) {
settings.callback();
@@ -137,15 +185,16 @@
return this.each(function() {
//console.log($.quoteString($(this).text()));
- var params = {'text': $(this).text(), 'confidence': settings.confidence, 'support': settings.support, 'spotter': settings.spotter };
- if("types" in settings && settings["types"] != undefined){
+ var params = {'text': $(this).text(), 'confidence': settings.confidence, 'support': settings.support, 'spotter': settings.spotter, 'policy': settings.policy };
+ if("types" in settings && settings["types"] != undefined)
params["types"] = settings.types;
- }
+ if("sparql" in settings && settings["sparql"] != undefined)
+ params["sparql"] = settings.sparql;
- $.ajax({ 'url': settings.endpoint+"/annotate",
+ ajaxRequest = $.ajax({ 'url': settings.endpoint+"/annotate",
'data': params,
'context': this,
- 'headers': {'Accept': 'application/xhtml+xml'},
+ 'headers': {'Accept': 'application/json'},
'success': update
});
});
@@ -157,16 +206,21 @@
if (settings.powered_by == 'yes') {
$(content).append($(powered_by));
};
- $(this).html(content);
+ $(this).html(content);
+
+ if(settings.callback != undefined) {
+ settings.callback();
+ }
}
return this.each(function() {
- var params = {'text': $(this).text(), 'confidence': settings.confidence, 'support': settings.support, 'spotter': settings.spotter };
- if("types" in settings && settings["types"] != undefined){
+ var params = {'text': $(this).text(), 'confidence': settings.confidence, 'support': settings.support, 'spotter': settings.spotter, 'policy': settings.policy };
+ if("types" in settings && settings["types"] != undefined)
params['types'] = settings.types;
- }
+ if("sparql" in settings && settings["sparql"] != undefined)
+ params["sparql"] = settings.sparql;
- $.ajax({ 'url': settings.endpoint+"/candidates",
+ ajaxRequest = $.ajax({ 'url': settings.endpoint+"/candidates",
'data': params,
'context': this,
'headers': {'Accept': 'application/json'},
@@ -196,7 +250,7 @@
params['types'] = settings.types;
}
- $.ajax({ 'url': settings.endpoint+"/candidates",
+ ajaxRequest = $.ajax({ 'url': settings.endpoint+"/candidates",
'data': params,
'context': this,
'headers': {'Accept': 'application/json'},
@@ -220,5 +274,9 @@
$.error( 'Method ' + method + ' does not exist on jQuery.spotlight' );
}
};
+
+ $.fn.cancelAnnotation = function() {
+ ajaxRequest.abort();
+ }
})( jQuery );
diff --git a/index.html b/index.html
index bf62c42..0d2a2fe 100644
--- a/index.html
+++ b/index.html
@@ -77,7 +77,7 @@
padding-left: 0;
display: inline;
}
-#text_container, #action_container {
+#text_container, #action_container, #filter_infobox {
width: 700px;
border-radius: 5px;
border: 1px solid #ccc;
@@ -91,6 +91,12 @@
clear: both;
}
+#filter_infobox {
+ background: #fafafa;
+ text-align: center;
+ margin-top: 10px;
+}
+
#text {
background: transparent;
}
@@ -207,6 +213,26 @@
position: relative;
overflow: visible;
}
+#text_container .annotation {
+ color: #135E6C;
+}
+#text_container .filtered {
+ color: #666;
+ text-decoration: none;
+}
+#text_container a.filtered:hover {
+ text-decoration: underline;
+}
+#text_container div.filtered {
+ color: #666;
+ background: transparent;
+ text-decoration: none;
+}
+#text_container div.filtered a.surfaceForm {
+ color: #666;
+ background-color: #F2F2F2;
+ text-decoration: none;
+}
ul.candidates {
font-size: 100%;
@@ -296,7 +322,6 @@
#copyright {
color: #666;
- margin-top: 30px;
font-size: 80%;
text-align: center;
}
@@ -322,9 +347,6 @@
background-position: 50% 50%;
background-repeat: no-repeat;
}
-.hidden {
- display: none;
-}