Skip to content

Commit

Permalink
Added schema.org selection tree, updated confidence value calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodaiber committed Sep 13, 2011
1 parent 606ed06 commit 55ad9be
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 42 deletions.
15 changes: 4 additions & 11 deletions dbpedia-spotlight-0.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@
var snippet = text.substring(start, offset)
var surfaceForm = text.substring(offset,offset+sfLength);
start = offset+sfLength;

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;

var classes = "annotation";

snippet += "<div id='"+(sfName+offset)+"' class='" + classes + "'><a class='surfaceForm'>" + sfName + "</a>";
//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.
Expand Down Expand Up @@ -179,7 +172,7 @@
$(this).html(content);

if(settings.callback != undefined) {
settings.callback();
settings.callback(response);
}
}

Expand Down Expand Up @@ -209,7 +202,7 @@
$(this).html(content);

if(settings.callback != undefined) {
settings.callback();
settings.callback(response);
}
}

Expand Down
97 changes: 68 additions & 29 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@
var textInput = null;
var server = 'http://spotlight.dbpedia.org/dev/rest'

var lastResponse;

function run(method) {

$('#edit_text_wrapper').show();

var settings = {
'endpoint' : server,
'confidence' : $('#confidence').val(),
Expand All @@ -366,7 +367,7 @@
'showScores': 'yes',
'spotter' : $('#spotter').val(),
'policy' : getFilterPolicy(),
'callback' : function callback() {$('#status_indicator').removeClass("loading");}
'callback' : function callback(response) {lastResponse = response; $('#status_indicator').removeClass("loading");}
}
if(getSPARQLQuery() != "")
settings.sparql = getSPARQLQuery();
Expand Down Expand Up @@ -419,6 +420,9 @@
$("#tree_freebase").jstree( "get_checked" ).each(function () {
checked_ids.push("Freebase:" + this.id);
});
$("#tree_schema").jstree( "get_checked" ).each(function () {
checked_ids.push("Schema:" + this.id);
});
return checked_ids.join(",");
}

Expand Down Expand Up @@ -539,41 +543,53 @@
}
);

function filter(occ, minConfidence, minSupport) {
var simThresholds = [0, 0.1155594, 0.1413648, 0.1555880, 0.1666082, 0.1769609, 0.1866261, 0.1957517,
0.20482580,0.2138903,0.2237287,0.2335491,0.2442384,0.2560859,0.2693643,0.2848305,
0.3033198,0.3288046,0.36692468,0.449684,0.5];
var simThreshold = simThresholds[Math.max(Math.round((simThresholds.length-1)*minConfidence), 0)]
var squaredConfidence = minConfidence*minConfidence

var support = parseInt(occ["@support"]);
var finalScore = parseFloat(occ["@finalScore"]);
var percentageOfSecondRank = parseFloat(occ["@percentageOfSecondRank"]);

console.log( "support: " + support + " < " + minSupport +
" || finalScore: "+ finalScore + " < " + simThreshold +
" || percentageOfSecondRank: " + percentageOfSecondRank + "<" + (1-squaredConfidence));

return ( (support < minSupport) ||
(finalScore < simThreshold) ||
(percentageOfSecondRank > (1-squaredConfidence)) );
}

function filterAnnotations() {
var treshSupport = parseInt($( "#support" ).val());
var treshConfidence = parseFloat($( "#confidence" ).val());

$(".annotation").each(function(){
var keep = true;
var classes = $(this).attr("class").split(" ");

for(i in classes) {
if(classes[i].indexOf("support_") != -1) {
var support = parseInt(classes[i].replace("support_", ""));
if(support < treshSupport) {
keep = false;
break;
}
}else if(classes[i].indexOf("confidence_") != -1) {
var confidence = parseFloat(classes[i].replace("confidence_", ""));
if(confidence < treshConfidence) {
keep = false;
break;
}
}

//Read response:
var json = $.parseJSON(lastResponse);
if (json==null) json = lastResponse; // when it comes already parsed

var annotations;
if(json["Resources"] != undefined) {
//first-best:
annotations = new Array().concat(json.Resources);
}else{
//n-best:
annotations = new Array().concat(json.annotation.surfaceForm).map(function(x) {return x[0]});
}

}
if(keep) {
$(this).removeClass("filtered")
for(annotation in annotations) {
var annID = annotation["@surfaceForm"] + annotation["@offset"];
if(filter(annotation, treshConfidence, treshSupport)) {
$("#" + annID).removeClass("filtered")
}else{
$(this).addClass("filtered")
$("#" + annID).addClass("filtered")
}
})
}
}



$("#method").change(
function() {
if(annotated){
Expand Down Expand Up @@ -619,6 +635,22 @@

});

$("#tree_schema").jstree({
"plugins" : [ "themes", "json_data", "checkbox" ],
"themes" : {
"icons" : false,
},
"json_data" : {
"ajax" : {
"url" : "tree.schema.json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
}

});


$(".tree").jstree("set_theme","default");

Expand Down Expand Up @@ -782,7 +814,8 @@ <h2>Bookmarklet</h2>
<ul>
<li><a href="#tabs-1">DBpedia</a></li>
<li><a href="#tabs-2">Freebase</a></li>
<li><a href="#tabs-3">Custom (SPARQL)</a></li>
<li><a href="#tabs-3">Schema.org</a></li>
<li><a href="#tabs-4">Custom (SPARQL)</a></li>
</ul>

<div id="tabs-1">
Expand All @@ -798,6 +831,12 @@ <h2>Bookmarklet</h2>
</div>

<div id="tabs-3">
<ul>
<li id="tree_schema" class="tree" />
</ul>
</div>

<div id="tabs-4">

<textarea id="sparql_type" rows="8"></textarea>

Expand Down
Loading

0 comments on commit 55ad9be

Please sign in to comment.