";
var maxTitles = 3;
for (var a = 0; a < titles.length && maxTitles > 0; a++) {
var resultArray = methods.getJsonValue(values, titles[a], titles[a].indexOf('http') == 0 ? '' : titles[a]);
if (titles[a].indexOf('http') != 0) {
if (result.indexOf($.trim(unescape(titles[a])) + " \n") == -1) {
result += $.trim(unescape(titles[a])) + " \n";
maxTitles--;
}
} else {
for (var af = 0; af < resultArray.length; af++) {
if (result.indexOf(unescape(resultArray[af]) + " \n") == -1) {
result += unescape(resultArray[af]) + " \n";
maxTitles--;
}
}
}
}
if ((values.length == 0 && uris.length == 0) || containerBox.attr("data-endpoint").indexOf("http://system/dummy") == 0) {
if (containerBox.attr("data-endpoint").indexOf("http://system/dummy") != -1) {
containerBox.attr("data-endpoint", lang('endpointNotConfigured'));
}
if (uris.length == 0 && values.length == 0) {
result = "";
var jResult = $(result);
if (jResult.text() == '' && docType == 'bnode') {
jResult.text('[blank node]');
} else if (jResult.text() == '') {
jResult.text(lang('noName'));
}
destBox.append(jResult);
if (!jResult.children().html() || jResult.children().html().indexOf(">") == -1) {
jResult.ThreeDots({
max_rows : 3
});
}
var el = jResult.find('.threedots_ellipsis');
if (el.length > 0) {
el.detach();
jResult.children('span').append(el);
}
var resourceTitle = jResult.text();
// posiziono il titolo al centro del box
jResult.css({
'marginTop' : jResult.height() == 13 ? 58 : jResult.height() == 26 ? 51 : 45,
'height' : jResult.height() + 5
});
destBox.hover(function() {
methods.msg(jResult.attr("threedots") == '' ? jResult.text() : jResult.attr("threedots") + " \n " + thisUri, 'show', 'fullInfo', containerBox.attr("data-endpoint"));
}, function() {
methods.msg(null, 'hide');
});
// calcolo le uri e le url dei documenti correlati
var connectedDocs = [];
var invertedDocs = [];
var propertyGroup = {};
var propertyGroupInverted = {};
var connectedImages = [];
var connectedLongs = [];
var connectedLats = [];
var sameDocControl = [];
$.each(uris, function(key, value) {
for (var akey in value) {
// escludo la definizione della classe, le proprieta'
// relative alle immagini ed ai link web
if (lodLiveProfile.uriSubstitutor) {
$.each(lodLiveProfile.uriSubstitutor, function(skey, svalue) {
value[akey] = value[akey].replace(svalue.findStr, svalue.replaceStr);
});
}
if ($.inArray(akey, images) > -1) {
eval('connectedImages.push({\'' + value[akey] + '\':\'' + escape(resourceTitle) + '\'})');
// to expand types } else if (akey !=
// 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
// $.inArray(akey, weblinks) == -1) {
} else if ($.inArray(akey, weblinks) == -1) {
// controllo se trovo la stessa relazione in una
// proprieta' diversa
if ($.inArray(value[akey], sameDocControl) > -1) {
var aCounter = 0;
$.each(connectedDocs, function(key2, value2) {
for (var akey2 in value2) {
if (value2[akey2] == value[akey]) {
eval('connectedDocs[' + aCounter + '] = {\'' + akey2 + ' | ' + akey + '\':\'' + value[akey] + '\'}');
}
}
aCounter++;
});
} else {
eval('connectedDocs.push({\'' + akey + '\':\'' + value[akey] + '\'})');
sameDocControl.push(value[akey]);
}
}
}
});
if (inverses) {
sameDocControl = [];
$.each(inverses, function(key, value) {
for (var akey in value) {
if (docType == 'bnode' && value[akey].indexOf("~~") != -1) {
continue;
}
if (lodLiveProfile.uriSubstitutor) {
$.each(lodLiveProfile.uriSubstitutor, function(skey, svalue) {
value[akey] = value[akey].replace(escape(svalue.findStr), escape(svalue.replaceStr));
});
}
// controllo se trovo la stessa relazione in una
// proprieta' diversa
if ($.inArray(value[akey], sameDocControl) > -1) {
var aCounter = 0;
$.each(invertedDocs, function(key2, value2) {
for (var akey2 in value2) {
if (value2[akey2] == value[akey]) {
var theKey = akey2;
if (akey2 != akey) {
theKey = akey2 + ' | ' + akey;
}
eval('invertedDocs[' + aCounter + '] = {\'' + theKey + '\':\'' + value[akey] + '\'}');
return false;
}
}
aCounter++;
});
} else {
eval('invertedDocs.push({\'' + akey + '\':\'' + value[akey] + '\'})');
sameDocControl.push(value[akey]);
}
}
});
}
if ($.jStorage.get('doDrawMap', true)) {
for (var a = 0; a < points.length; a++) {
var resultArray = methods.getJsonValue(values, points[a], points[a]);
for (var af = 0; af < resultArray.length; af++) {
if (resultArray[af].indexOf(" ") != -1) {
eval('connectedLongs.push(\'' + unescape(resultArray[af].split(" ")[1]) + '\')');
eval('connectedLats.push(\'' + unescape(resultArray[af].split(" ")[0]) + '\')');
} else if (resultArray[af].indexOf("-") != -1) {
eval('connectedLongs.push(\'' + unescape(resultArray[af].split("-")[1]) + '\')');
eval('connectedLats.push(\'' + unescape(resultArray[af].split("-")[0]) + '\')');
}
}
}
for (var a = 0; a < longs.length; a++) {
var resultArray = methods.getJsonValue(values, longs[a], longs[a]);
for (var af = 0; af < resultArray.length; af++) {
eval('connectedLongs.push(\'' + unescape(resultArray[af]) + '\')');
}
}
for (var a = 0; a < lats.length; a++) {
var resultArray = methods.getJsonValue(values, lats[a], lats[a]);
for (var af = 0; af < resultArray.length; af++) {
eval('connectedLats.push(\'' + unescape(resultArray[af]) + '\')');
}
}
if (connectedLongs.length > 0 && connectedLats.length > 0) {
var mapsMap = $.jStorage.get("mapsMap", {});
mapsMap[containerBox.attr("id")] = {
longs : connectedLongs[0],
lats : connectedLats[0],
title : thisUri + "\n" + escape(resourceTitle)
};
$.jStorage.set('mapsMap', mapsMap);
methods.updateMapPanel($('#controlPanel'));
}
}
if ($.jStorage.get('doCollectImages', true)) {
if (connectedImages.length > 0) {
var imagesMap = $.jStorage.get("imagesMap", {});
imagesMap[containerBox.attr("id")] = connectedImages;
$.jStorage.set('imagesMap', imagesMap);
methods.updateImagePanel($('#controlPanel'));
}
}
var totRelated = connectedDocs.length + invertedDocs.length;
// se le proprieta' da mostrare sono troppe cerco di accorpare
// quelle uguali
if (totRelated > 16) {
$.each(connectedDocs, function(key, value) {
for (var akey in value) {
if (propertyGroup[akey]) {
var t = propertyGroup[akey];
t.push(value[akey]);
propertyGroup[akey] = t;
} else {
propertyGroup[akey] = [value[akey]];
}
}
});
$.each(invertedDocs, function(key, value) {
for (var akey in value) {
if (propertyGroupInverted[akey]) {
var t = propertyGroupInverted[akey];
t.push(value[akey]);
propertyGroupInverted[akey] = t;
} else {
propertyGroupInverted[akey] = [value[akey]];
}
}
});
totRelated = 0;
for (var prop in propertyGroup) {
if (propertyGroup.hasOwnProperty(prop)) {
totRelated++;
}
}
for (var prop in propertyGroupInverted) {
if (propertyGroupInverted.hasOwnProperty(prop)) {
totRelated++;
}
}
}
// calcolo le parti in cui dividere il cerchio per posizionare i
// link
// var chordsList = this.lodlive('circleChords',
// destBox.width() / 2 + 12, ((totRelated > 1 ? totRelated - 1 :
// totRelated) * 2) + 4, destBox.position().left + destBox.width() /
// 2, destBox.position().top + destBox.height() / 2, totRelated +
// 4);
var chordsList = methods.circleChords(75, 24, destBox.position().left + 65, destBox.position().top + 65);
var chordsListGrouped = methods.circleChords(95, 36, destBox.position().left + 65, destBox.position().top + 65);
// aggiungo al box i link ai documenti correlati
var a = 1;
var inserted = {};
var counter = 0;
var innerCounter = 1;
var objectList = [];
var innerObjectList = [];
$.each(connectedDocs, function(key, value) {
if (counter == 16) {
counter = 0;
}
if (a == 1) {
} else if (a == 15) {
a = 1;
}
for (var akey in value) {
var obj = null;
if (propertyGroup[akey] && propertyGroup[akey].length > 1) {
if (!inserted[akey]) {
innerCounter = 1;
inserted[akey] = true;
// var objBox = $("" + (propertyGroup[akey].length) +
// "
");
var objBox = $("");
// containerBox.append(objBox);
var akeyArray = akey.split(" ");
if (unescape(propertyGroup[akey][0]).indexOf('~~') != -1) {
objBox.addClass('isBnode');
} else {
for (var i = 0; i < akeyArray.length; i++) {
if (lodLiveProfile.arrows[akeyArray[i]]) {
objBox.addClass(lodLiveProfile.arrows[akeyArray[i]]);
}
}
}
objBox.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
objectList.push(objBox);
// containerBox.append('');
a++;
counter++;
}
// var alredyInserted = $('.relatedBox',
// containerBox).length;
// if (alredyInserted <
// document.lodliveVars['relationsLimit']) {
if (innerCounter < 25) {
obj = $("");
// containerBox.append(obj);
obj.attr('style', 'display:none;position:absolute;top:' + (chordsListGrouped[innerCounter][1] - 8) + 'px;left:' + (chordsListGrouped[innerCounter][0] - 8) + 'px');
obj.attr("data-circlePos", innerCounter);
obj.attr("data-circleParts", 36);
obj.attr("data-circleId", containerBox.attr('id'));
}
/*
* } else if (alredyInserted == document.lodliveVars['relationsLimit']) { $('.' + MD5(akey), containerBox).append('[...]'); }
*/
innerCounter++;
} else {
obj = $("");
// containerBox.append(obj);
obj.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
obj.attr("data-circlePos", a);
obj.attr("data-circleParts", 24);
a++;
counter++;
}
if (obj) {
obj.attr("data-circleId", containerBox.attr('id'));
obj.attr("data-property", akey);
// se si tratta di un Bnode applico una classe diversa
var akeyArray = akey.split(" ");
if (obj.attr('rel').indexOf('~~') != -1) {
obj.addClass('isBnode');
} else {
for (var i = 0; i < akeyArray.length; i++) {
if (lodLiveProfile.arrows[akeyArray[i]]) {
obj.addClass(lodLiveProfile.arrows[akeyArray[i]]);
}
}
}
if (obj.hasClass("aGrouped")) {
innerObjectList.push(obj);
} else {
objectList.push(obj);
}
}
}
});
inserted = {};
$.each(invertedDocs, function(key, value) {
if (counter == 16) {
counter = 0;
}
if (a == 1) {
} else if (a == 15) {
a = 1;
}
for (var akey in value) {
var obj = null;
if (propertyGroupInverted[akey] && propertyGroupInverted[akey].length > 1) {
if (!inserted[akey]) {
innerCounter = 1;
inserted[akey] = true;
// var objBox = $("" + (propertyGroup[akey].length) +
// "
");
var objBox = $("");
// containerBox.append(objBox);
var akeyArray = akey.split(" ");
if (unescape(propertyGroupInverted[akey][0]).indexOf('~~') != -1) {
objBox.addClass('isBnode');
} else {
for (var i = 0; i < akeyArray.length; i++) {
if (lodLiveProfile.arrows[akeyArray[i]]) {
objBox.addClass(lodLiveProfile.arrows[akeyArray[i]]);
}
}
}
objBox.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
// containerBox.append('');
objectList.push(objBox);
a++;
counter++;
}
// var alredyInserted = $('.relatedBox',
// containerBox).length;
// if (alredyInserted <
// document.lodliveVars['relationsLimit']) {
if (innerCounter < 25) {
var destUri = unescape(value[akey].indexOf('~~') == 0 ? thisUri + value[akey] : value[akey]);
obj = $("");
// containerBox.append(obj);
obj.attr('style', 'display:none;position:absolute;top:' + (chordsListGrouped[innerCounter][1] - 8) + 'px;left:' + (chordsListGrouped[innerCounter][0] - 8) + 'px');
obj.attr("data-circlePos", innerCounter);
obj.attr("data-circleParts", 36);
obj.attr("data-circleId", containerBox.attr('id'));
}
/*
* } else if (alredyInserted == document.lodliveVars['relationsLimit']) { $('.' + MD5(akey), containerBox).append('[...]'); }
*/
innerCounter++;
} else {
obj = $("");
// containerBox.append(obj);
obj.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
obj.attr("data-circlePos", a);
obj.attr("data-circleParts", 24);
a++;
counter++;
}
if (obj) {
obj.attr("data-circleId", containerBox.attr('id'));
obj.attr("data-property", akey);
// se si tratta di un sameas applico una classe diversa
var akeyArray = akey.split(" ");
if (obj.attr('rel').indexOf('~~') != -1) {
obj.addClass('isBnode');
} else {
for (var i = 0; i < akeyArray.length; i++) {
if (lodLiveProfile.arrows[akeyArray[i]]) {
obj.addClass(lodLiveProfile.arrows[akeyArray[i]]);
}
}
}
if (obj.hasClass("aGrouped")) {
innerObjectList.push(obj);
} else {
objectList.push(obj);
}
}
}
});
var page = 0;
var totPages = objectList.length > 14 ? (objectList.length / 14 + (objectList.length % 14 > 0 ? 1 : 0)) : 1;
for (var i = 0; i < objectList.length; i++) {
if (i % 14 == 0) {
page++;
var aPage = $('');
if (page > 1 && totPages > 1) {
aPage.append("");
}
if (totPages > 1 && page < totPages - 1) {
aPage.append("");
}
containerBox.append(aPage);
}
containerBox.children('.page' + page).append(objectList[i]);
}
page = 0;
totPages = innerObjectList.length / 24 + (innerObjectList.length % 24 > 0 ? 1 : 0);
if (innerObjectList.length > 0) {
containerBox.append('');
for (var i = 0; i < innerObjectList.length; i++) {
containerBox.children('.innerPage').append(innerObjectList[i]);
}
}
containerBox.children('.page1').fadeIn('fast');
containerBox.children('.page').children('.pager').click(function() {
var pager = $(this);
containerBox.find('.lastClick').removeClass('lastClick').click();
pager.parent().fadeOut('fast', null, function() {
$(this).parent().children('.' + pager.attr("data-page")).fadeIn('fast');
});
}); {
var obj = $("
");
containerBox.append(obj);
obj.hover(function() {
$(this).parent().children('.box').setBackgroundPosition({
y : -260
});
}, function() {
$(this).parent().children('.box').setBackgroundPosition({
y : 0
});
});
obj = $("
");
containerBox.append(obj);
obj.hover(function() {
$(this).parent().children('.box').setBackgroundPosition({
y : -130
});
}, function() {
$(this).parent().children('.box').setBackgroundPosition({
y : 0
});
});
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' format ');
}
},
circleChords : function(radius, steps, centerX, centerY, breakAt, onlyElement) {
if (debugOn) {
start = new Date().getTime();
}
var values = [];
var i = 0;
if (onlyElement) {
// ottimizzo i cicli evitando di calcolare elementi che non
// servono
i = onlyElement;
var radian = (2 * Math.PI) * (i / steps);
values.push([centerX + radius * Math.cos(radian), centerY + radius * Math.sin(radian)]);
} else {
for (; i < steps; i++) {
// calcolo le coodinate lungo il cerchio del box per
// posizionare
// strumenti ed altre risorse
var radian = (2 * Math.PI) * (i / steps);
values.push([centerX + radius * Math.cos(radian), centerY + radius * Math.sin(radian)]);
}
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' circleChords ');
}
return values;
// console.debug(xValues)
// console.debug(yValues)
},
getJsonValue : function(map, key, defaultValue) {
if (debugOn) {
start = new Date().getTime();
}
var returnVal = [];
$.each(map, function(skey, value) {
for (var akey in value) {
if (akey == key) {
returnVal.push(unescape(value[akey]));
}
}
});
if (returnVal == []) {
returnVal = [defaultValue];
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' getJsonValue');
}
return returnVal;
},
getProperty : function(area, prop, context) {
if (debugOn) {
start = new Date().getTime();
}
if ( typeof context == typeof '') {
if (lodLiveProfile[context] && lodLiveProfile[context][area]) {
if (prop) {
return lodLiveProfile[context][area][prop] ? lodLiveProfile[context][area][prop] : lodLiveProfile['default'][area][prop];
} else {
return lodLiveProfile[context][area] ? lodLiveProfile[context][area] : lodLiveProfile['default'][area];
}
}
} else {
for (var a = 0; a < context.length; a++) {
if (lodLiveProfile[context[a]] && lodLiveProfile[context[a]][area]) {
if (prop) {
return lodLiveProfile[context[a]][area][prop] ? lodLiveProfile[context[a]][area][prop] : lodLiveProfile['default'][area][prop];
} else {
return lodLiveProfile[context[a]][area] ? lodLiveProfile[context[a]][area] : lodLiveProfile['default'][area];
}
}
}
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' getProperty');
}
if (lodLiveProfile['default'][area]) {
if (prop) {
return lodLiveProfile['default'][area][prop];
} else {
return lodLiveProfile['default'][area];
}
} else {
return '';
}
},
parseRawResource : function(destBox, resource, fromInverse) {
var values = [];
var uris = [];
if (lodLiveProfile['default']) {
// attivo lo sparql interno basato su sesame
var res = getSparqlConf('documentUri', lodLiveProfile['default'], lodLiveProfile).replace(/\{URI\}/ig, resource);
var url = lodLiveProfile['default'].endpoint + "?uri=" + encodeURIComponent(resource) + "&query=" + encodeURIComponent(res);
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
title : lang('endpointNotConfiguredSoInternal'),
text : res,
uriId : resource
});
}
$.jsonp({
url : url,
beforeSend : function() {
destBox.children('.box').html('');
},
success : function(json) {
json = json['results']['bindings'];
var conta = 0;
$.each(json, function(key, value) {
conta++;
if (value.object.type == 'uri') {
if (value.object.value != resource) {
eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
}
} else {
eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
}
});
if (debugOn) {
console.debug((new Date().getTime() - start) + ' openDoc eval uris & values');
}
var inverses = [];
var callback = function() {
destBox.children('.box').html('');
methods.format(destBox.children('.box'), values, uris, inverses);
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
};
if ($.jStorage.get('doAutoSameas')) {
var counter = 0;
var tot = 0;
$.each(lodLiveProfile.connection, function(key, value) {
tot++;
});
methods.findInverseSameAs(resource, counter, inverses, callback, tot);
} else {
callback();
}
},
error : function(e, j, k) {
// console.debug(e);console.debug(j);
destBox.children('.box').html('');
var inverses = [];
if (fromInverse) {
eval('uris.push({\'' + fromInverse.replace(/div\[data-property="([^"]*)"\].*/, '$1') + '\':\'' + fromInverse.replace(/.*\[rel="([^"]*)"\].*/, '$1') + '\'})');
}
methods.format(destBox.children('.box'), values, uris, inverses);
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
}
});
} else {
// console.debug(e);console.debug(j);
destBox.children('.box').html('');
var inverses = [];
if (fromInverse) {
eval('uris.push({\'' + fromInverse.replace(/div\[data-property="([^"]*)"\].*/, '$1') + '\':\'' + fromInverse.replace(/.*\[rel="([^"]*)"\].*/, '$1') + '\'})');
}
methods.format(destBox.children('.box'), values, uris, inverses);
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
}
},
openDoc : function(anUri, destBox, fromInverse) {
if (debugOn) {
start = new Date().getTime();
}
var uris = [];
var values = [];
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('init', {
uriId : anUri
});
methods.queryConsole('log', {
uriId : anUri,
resource : anUri
});
}
SPARQLquery = methods.composeQuery(anUri, 'documentUri');
if ($.jStorage.get('doStats')) {
methods.doStats(anUri);
}
if (SPARQLquery.indexOf("endpoint=") != -1) {
var endpoint = SPARQLquery.substring(SPARQLquery.indexOf("endpoint=") + 9);
endpoint = endpoint.substring(0, endpoint.indexOf("&"));
destBox.attr("data-endpoint", endpoint);
} else {
destBox.attr("data-endpoint", SPARQLquery.substring(0, SPARQLquery.indexOf("?")));
}
if (SPARQLquery.indexOf("http://system/dummy") == 0) {
// guessing endpoint from URI
methods.guessingEndpoint(anUri, function() {
methods.openDoc(anUri, destBox, fromInverse);
}, function() {
methods.parseRawResource(destBox, anUri, fromInverse);
});
} else {
$.jsonp({
url : SPARQLquery,
beforeSend : function() {
destBox.children('.box').html('');
},
success : function(json) {
json = json['results']['bindings'];
// var tot = json.length;
var conta = 0;
// var aSpan = $('
gg0/' +
// tot + '');
// destBox.children('.box').append(aSpan);
// var control = {};
$.each(json, function(key, value) {
conta++;
if (value.object.type == 'uri' || value.object.type == 'bnode') {
if (value.object.value != anUri) {
if (value.object.type == 'bnode') {
eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(anUri + '~~' + value.object.value) + '\'})');
} else {
eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
}
}
} else {
eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
}
});
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
founded : conta,
id : SPARQLquery,
uriId : anUri
});
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' openDoc eval uris & values');
}
destBox.children('.box').html('');
if ($.jStorage.get('doInverse')) {
SPARQLquery = methods.composeQuery(anUri, 'inverse');
var inverses = [];
$.jsonp({
url : SPARQLquery,
beforeSend : function() {
destBox.children('.box').html('');
},
success : function(json) {
json = json['results']['bindings'];
var conta = 0;
// var tot = json.length;
// var aSpan = $('
0/' + tot +
// '');
// destBox.children('.box').append(aSpan);
$.each(json, function(key, value) {
conta++;
eval('inverses.push({\'' + value['property']['value'] + '\':\'' + (value.object.type == 'bnode' ? anUri + '~~' : '') + escape(value.object.value) + '\'})');
// aSpan.text(conta + '/' + tot);
});
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
founded : conta,
id : SPARQLquery,
uriId : anUri
});
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' openDoc inverse eval uris ');
}
var callback = function() {
destBox.children('.box').html('');
methods.format(destBox.children('.box'), values, uris, inverses);
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
};
if ($.jStorage.get('doAutoSameas')) {
var counter = 0;
var tot = 0;
$.each(lodLiveProfile.connection, function(key, value) {
tot++;
});
methods.findInverseSameAs(anUri, counter, inverses, callback, tot);
} else {
callback();
}
},
error : function(e, b, v) {
destBox.children('.box').html('');
methods.format(destBox.children('.box'), values, uris);
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
error : 'error',
id : SPARQLquery,
uriId : anUri
});
}
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
}
});
} else {
methods.format(destBox.children('.box'), values, uris);
methods.addClick(destBox, fromInverse ? function() {
try {
$(fromInverse).click();
} catch (e) {
}
} : null);
if ($.jStorage.get('doAutoExpand')) {
methods.autoExpand(destBox);
}
}
},
error : function(e, b, v) {
methods.errorBox(destBox);
}
});
}
if (debugOn) {
console.debug((new Date().getTime() - start) + ' openDoc');
}
},
errorBox : function(destBox) {
destBox.children('.box').addClass("errorBox");
destBox.children('.box').html('');
var jResult = $("" + lang('enpointNotAvailable') + "
");
destBox.children('.box').append(jResult);
jResult.css({
'marginTop' : jResult.height() == 13 ? 58 : jResult.height() == 26 ? 51 : 45
});
var obj = $("
");
obj.click(function() {
methods.removeDoc(destBox);
});
destBox.append(obj);
destBox.children('.box').hover(function() {
methods.msg(lang('enpointNotAvailableOrSLow'), 'show', 'fullInfo', destBox.attr("data-endpoint"));
}, function() {
methods.msg(null, 'hide');
});
},
allClasses : function(SPARQLquery, destBox, destSelect, template) {
if (debugOn) {
start = new Date().getTime();
}
SPARQLquery = methods.composeQuery(SPARQLquery, 'allClasses');
var classes = [];
$.jsonp({
url : SPARQLquery,
beforeSend : function() {
destBox.html('');
},
success : function(json) {
destBox.html(lang('choose'));
json = json['results']['bindings'];
$.each(json, function(key, value) {
var aclass = json[key].object.value;
if (aclass.indexOf('http://www.openlinksw.com/') == -1) {
aclass = aclass.replace(/http:\/\//, "");
classes.push(aclass);
}
});
for (var i = 0; i < classes.length; i++) {
destSelect.append(template.replace(/\{CONTENT\}/g, classes[i]));
}
},
error : function(e, b, v) {
destSelect.append(template.replace(/\{CONTENT\}/g, 'si è verificato un errore'));
}
});
if (debugOn) {
console.debug((new Date().getTime() - start) + ' allClasses');
}
},
findInverseSameAs : function(anUri, counter, inverse, callback, tot) {
if (debugOn) {
start = new Date().getTime();
}
var innerCounter = 0;
$.each(lodLiveProfile.connection, function(key, value) {
if (innerCounter == counter) {
var skip = false;
var keySplit = key.split(",");
if (!value.useForInverseSameAs) {
skip = true;
} else {
for (var a = 0; a < keySplit.length; a++) {
// salto i sameas interni allo stesso endpoint
if (anUri.indexOf(keySplit[a]) != -1) {
skip = true;
}
}
}
if (skip) {
counter++;
if (counter < tot) {
methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
} else {
callback();
}
return false;
}
var SPARQLquery = value.endpoint + "?" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri));
if (value.proxy) {
SPARQLquery = value.proxy + '?endpoint=' + value.endpoint + "&" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri));
}
$.jsonp({
url : SPARQLquery,
timeout : 3000,
beforeSend : function() {
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
title : value.endpoint,
text : getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri),
id : SPARQLquery,
uriId : anUri
});
}
},
success : function(json) {
json = json['results']['bindings'];
var conta = 0;
$.each(json, function(key, value) {
conta++;
if (value.property && value.property.value) {
eval('inverse.splice(1,0,{\'' + value.property.value + '\':\'' + escape(value.object.value) + '\'})');
} else {
eval('inverse.splice(1,0,{\'' + 'http://www.w3.org/2002/07/owl#sameAs' + '\':\'' + escape(value.object.value) + '\'})');
}
});
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
founded : conta,
id : SPARQLquery,
uriId : anUri
});
}
counter++;
if (counter < tot) {
methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
} else {
callback();
}
},
error : function(e, b, v) {
if ($.jStorage.get('showInfoConsole')) {
methods.queryConsole('log', {
error : 'error',
id : SPARQLquery,
uriId : anUri
});
}
counter++;
if (counter < tot) {
methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
} else {
callback();
}
}
});
if (debugOn) {
console.debug((new Date().getTime() - start) + ' findInverseSameAs ' + value.endpoint);
}
}
innerCounter++;
});
if (debugOn) {
console.debug((new Date().getTime() - start) + ' findInverseSameAs');
}
},
findSubject : function(SPARQLquery, selectedClass, selectedValue, destBox, destInput) {
if (debugOn) {
start = new Date().getTime();
}
$.each(lodLiveProfile.connection, function(key, value) {
var keySplit = key.split(",");
for (var a = 0; a < keySplit.length; a++) {
if (SPARQLquery.indexOf(keySplit[a]) != -1) {
SPARQLquery = value.endpoint + "?" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('findSubject', value, lodLiveProfile).replace(/\{CLASS\}/g, selectedClass).replace(/\{VALUE\}/g, selectedValue));
if (value.proxy) {
SPARQLquery = value.proxy + "?endpoint=" + value.endpoint + "&" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('findSubject', value, lodLiveProfile).replace(/\{CLASS\}/g, selectedClass).replace(/\{VALUE\}/g, selectedValue));
}
}
}
});
var values = [];
$.jsonp({
url : SPARQLquery,
beforeSend : function() {
destBox.html('');
},
success : function(json) {
destBox.html('');
json = json['results']['bindings'];
$.each(json, function(key, value) {
values.push(json[key].subject.value);
});
for (var i = 0; i < values.length; i++) {
// console.debug(destInput)
destInput.val(values[i]);
}
},
error : function(e, b, v) {
destBox.html('errore: ' + e);
}
});
if (debugOn) {
console.debug((new Date().getTime() - start) + ' findSubject');
}
},
/* start lines */
standardLine : function(label, x1, y1, x2, y2, canvas, toId) {
// eseguo i calcoli e scrivo la riga di connessione tra i cerchi
var lineangle = (Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI) + 180;
var x2bis = x1 - Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) + 60;
// canvas.detectPixelRatio();
canvas.rotateCanvas({
rotate : lineangle,
x : x1,
y : y1
}).drawLine({
strokeStyle : "#fff",
strokeWidth : 1,
strokeCap : 'bevel',
x1 : x1 - 60,
y1 : y1,
x2 : x2bis,
y2 : y1
});
if (lineangle > 90 && lineangle < 270) {
canvas.rotateCanvas({
rotate : 180,
x : (x2bis + x1) / 2,
y : (y1 + y1) / 2
});
}
label = $.trim(label).replace(/\n/g, ', ');
canvas.drawText({// inserisco l'etichetta
fillStyle : "#606060",
strokeStyle : "#606060",
x : (x2bis + x1 + ((x1 + 60) > x2 ? -60 : +60)) / 2,
y : (y1 + y1 - ((x1 + 60) > x2 ? 18 : -18)) / 2,
text : ((x1 + 60) > x2 ? " « " : "") + label + ((x1 + 60) > x2 ? "" : " » "),
align : "center",
strokeWidth : 0.01,
fontSize : 11,
fontFamily : "'Open Sans',Verdana"
}).restoreCanvas().restoreCanvas();
// ed inserisco la freccia per determinarne il verso della
// relazione
lineangle = Math.atan2(y2 - y1, x2 - x1);
var angle = 0.79;
var h = Math.abs(8 / Math.cos(angle));
var fromx = x2 - 60 * Math.cos(lineangle);
var fromy = y2 - 60 * Math.sin(lineangle);
var angle1 = lineangle + Math.PI + angle;
var topx = (x2 + Math.cos(angle1) * h) - 60 * Math.cos(lineangle);
var topy = (y2 + Math.sin(angle1) * h) - 60 * Math.sin(lineangle);
var angle2 = lineangle + Math.PI - angle;
var botx = (x2 + Math.cos(angle2) * h) - 60 * Math.cos(lineangle);
var boty = (y2 + Math.sin(angle2) * h) - 60 * Math.sin(lineangle);
canvas.drawLine({
strokeStyle : "#fff",
strokeWidth : 1,
x1 : fromx,
y1 : fromy,
x2 : botx,
y2 : boty
});
canvas.drawLine({
strokeStyle : "#fff",
strokeWidth : 1,
x1 : fromx,
y1 : fromy,
x2 : topx,
y2 : topy
});
}
}
/* end lines */;
$.fn.lodlive = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if ( typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.lodlive');
}
};
})(jQuery, $.jStorage.get('profile'));