Skip to content

Commit

Permalink
fixed bug in OntologyType.equals, added confidence/support filtering …
Browse files Browse the repository at this point in the history
…to client side
  • Loading branch information
pablomendes committed Sep 6, 2011
1 parent 8f65887 commit 41a9397
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 18 deletions.
52 changes: 40 additions & 12 deletions dbpedia-spotlight-0.3.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright 2011 Pablo Mendes, Max Jakob
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Check our project website for information on how to acknowledge the authors and how to contribute to the project: http://spotlight.dbpedia.org
*/

/**
* If you use this script, please give credit to DBpedia Spotlight by:
* - adding "powered by DBpedia Spotlight" somewhere in the page.
Expand All @@ -15,7 +33,7 @@
var powered_by = "<div style='font-size: 9px; float: right'><a href='http://spotlight.dbpedia.org'>Powered by DBpedia Spotlight</a></div>";

var settings = {
'endpoint' : 'http://spotlight.dbpedia.org/dev/rest',
'endpoint' : 'http://localhost:2223/rest',
'confidence' : 0.4, //
'support' : 20,
'powered_by': 'yes', // yes or no
Expand All @@ -26,17 +44,22 @@

var Parser = {
getSelectBox: function(resources, className) {
var snippet = "<ul class='"+className+"s'>";
//console.log(resources);
var options = ""; $.each(resources, function(i, r) {
options += "<li class='"+className+"-" + i + "'><a href='http://dbpedia.org/resource/" + r["@uri"] + "' about='" + r["@uri"] + "'>" + r["@label"] + "</a>";
var ul = $("<ul class='"+className+"s'></ul>");
$.each(resources, function(i, r) {
var li = "<li class='"+className+" "+className+"-" + i + "'><a href='http://dbpedia.org/resource/" + r["@uri"] + "' about='" + r["@uri"] + "'>" + r["@label"] + "</a>";
//TODO settings.showScores = ["finalScore"] foreach showscores, add k=v
if (settings.showScores == 'yes') options += " <span>(" + parseFloat(r["@finalScore"]).toPrecision(3) +")</span>";
options += "</li>";
if (settings.showScores == 'yes') li += " (<span class='finalScore'>" + parseFloat(r["@finalScore"]).toPrecision(3) +"</span>)";
li += "<span class='hidden contextualScore'>"+parseFloat(r["@contextualScore"])+"</span>";
li += "<span class='hidden percentageOfSecondRank'>"+parseFloat(r["@percentageOfSecondRank"])+"</span>";
li += "<span class='hidden support'>"+parseFloat(r["@support"])+"</span>";
li += "<span class='hidden priorScore'>"+parseFloat(r["@priorScore"])+"</span>";
li += "</li>";
var opt = $(li);
$.data(opt,"testProp","testValue");
//console.log($.data(opt,"testProp"));
$(ul).append(opt);
});
snippet += options;
snippet += "</ul>"
return snippet;
return ul;
},
getAnnotatedText: function(response) {
var json = $.parseJSON(response);
Expand All @@ -61,8 +84,11 @@
start = offset+sfLength;
snippet += "<div id='"+(sfName+offset)+"' class='annotation'><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.
snippet += Parser.getSelectBox($(e.resource),'candidate');
var ul = Parser.getSelectBox($(e.resource),'candidate');
//ul.children().each(function() { console.log($.data($(this),"testProp")); });
snippet += "<ul class='candidates'>"+ul.html()+"</ul>"; //FIXME this wrapper is a repeat from getSelectBox
snippet += "</div>";

return snippet;
}).join("");
//snippet after last surface form
Expand Down Expand Up @@ -182,7 +208,9 @@
};

$.fn.annotate = function(method) {
console.log('method:',method);

//console.log('method:',method);

// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
Expand Down
54 changes: 48 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
<script>
var annotated = false;
var textInput = null;
var server = 'http://spotlight.dbpedia.org/dev/rest'
var server = 'http://localhost:2223/rest'

function run(method) {

Expand Down Expand Up @@ -428,8 +428,8 @@

//accept parameters from URL
var t = $(document).getUrlParam('text');
var execute = ($(document).getUrlParam('execute') == "yes");
console.log("Execute:"+execute);
var doExecute = ($(document).getUrlParam('execute') == "yes");
console.log("Execute:"+doExecute);

if ($.trim(t)!='' && t != "null") { $('#text').val(decodeURIComponent(t)); }

Expand Down Expand Up @@ -457,6 +457,23 @@
runWithSettings();
});

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

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

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


$("#support-slider").slider({
value:0,
min: 0,
Expand All @@ -466,8 +483,21 @@
$( "#support" ).val( ui.value );
},
stop: function( event, ui ) {
var minSupport = parseInt($( "#support" ).val());
var minConfidence = parseFloat($( "#confidence" ).val());
if(annotated){
runWithSettings(); //TODO only hide spans with lower scores, do not query server again
$(".candidate").each(function() {
var occ = { 'support': parseInt($(this).children(".support").text()),
'finalScore': parseFloat($(this).children(".finalScore").text()),
'contextualScore': parseFloat($(this).children(".contextualScore").text()),
'percentageOfSecondRank': parseFloat($(this).children(".percentageOfSecondRank").text()) }
$( "#confidence" ).val()
if (filter(occ, minConfidence, minSupport)) {
$(this).hide();
} else {
$(this).show();
}
});
}
}
});
Expand All @@ -481,8 +511,20 @@
$( "#confidence" ).val( ui.value );
},
stop: function( event, ui ) {
var minSupport = parseInt($( "#support" ).val());
var minConfidence = parseFloat($( "#confidence" ).val());
if(annotated){
runWithSettings(); //TODO only hide spans with lower scores, do not query server again
$(".candidate").each(function() {
var occ = { 'support': parseInt($(this).children(".support").text()),
'finalScore': parseFloat($(this).children(".finalScore").text()),
'contextualScore': parseFloat($(this).children(".contextualScore").text()),
'percentageOfSecondRank': parseFloat($(this).children(".percentageOfSecondRank").text()) };
if (filter(occ, minConfidence, minSupport)) {
$(this).hide();
} else {
$(this).show();
}
});
}
}
});
Expand Down Expand Up @@ -565,7 +607,7 @@
}
});

if (execute==true) runWithSettings;
if (doExecute==true) runWithSettings;
});

function sparqlExample(i) {
Expand Down

0 comments on commit 41a9397

Please sign in to comment.