123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
- thisUrlParams = {};
- window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
- thisUrlParams[key] = value;
- });
- console.log('URL get params: ', thisUrlParams);
- // Funzioni per eseguire le queries
- function prepareQueryURL(query){
- sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
- sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
- return sparqlEndpoint + sparqlUrlParams;
- }
- function doJsonQuery(query){
- queryURL = prepareQueryURL(query);
- response = $.ajax({//OGGETTO
- url: queryURL,
- dataType: "json",
- success: function (data){},
- error: function (e) {}
- });
- return response;
- }
- // Funzioni per raccattare + stringhificare l'output
- queryStringOutput = "";
- function stringifyResponse(val){
- resultArray = val['results']['bindings'];
- out = "";
- for(i = 0; i < resultArray.length; i++){
- out = out + JSON.stringify(resultArray[i])
- }
- queryStringOutput = (queryStringOutput + out).replace("}{",",");
- }
- prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
- PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
- PREFIX owl: <http://www.w3.org/2002/07/owl#>"
- query = prefixes + " SELECT DISTINCT ?graph ?name_place ?coordinates ?ref ?toponym {\
- GRAPH ?graph {<" + thisUrlParams.link + "> crm:P168_place_is_defined_by ?coordinates;\
- rdfs:label ?name_place ;\
- owl:sameAs ?ref;\
- crm:P1_is_identified_by ?uri_toponym .\
- ?uri_toponym rdfs:label ?toponym\
- }\
- }"
- queryRiferimenti = prefixes + " SELECT DISTINCT ?references {\
- <" + thisUrlParams.link + "> owl:sameAs ?references\
- }"
- queryToponimi = prefixes + " SELECT DISTINCT ?toponimi {\
- <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri_toponym .\
- ?uri_toponym rdfs:label ?toponimi\
- }"
- queryRicezione = prefixes + " SELECT DISTINCT ?object ?label {\
- <" + thisUrlParams.link + "> owl:sameAs ?place .\
- ?event_to crm:P26_moved_to ?place ;\
- rdf:type crm:EL3_Receive_Letter ;\
- rdfs:subClassOf ?event .\
- ?object crm:P25i_moved_by ?event ; \
- rdfs:label ?label .\
- } "
- queryInvio = prefixes + " SELECT DISTINCT ?object ?label {\
- <" + thisUrlParams.link + "> owl:sameAs ?place .\
- ?event_to crm:P27_moved_from ?place ;\
- rdf:type crm:EL2_Send_Letter ;\
- rdfs:subClassOf ?event .\
- ?object crm:P25i_moved_by ?event ; \
- rdfs:label ?label .\
- }"
- queryCitazione = prefixes + " SELECT DISTINCT ?object ?label{\
- <" + thisUrlParams.link + "> crm:P1_is_identified_by ?toponym .\
- ?object crm:P67_refers_to ?toponym ;\
- rdfs:label ?label\
- }"
- queryURL = prepareQueryURL(query);
- queryRef = prepareQueryURL(queryRiferimenti);
- queryTopo = prepareQueryURL(queryToponimi);
- queryRec = prepareQueryURL(queryRicezione);
- querySend = prepareQueryURL(queryInvio);
- queryCit = prepareQueryURL(queryCitazione);
- response = $.ajax({//OGGETTO
- url: queryURL,
- dataType: "json",
- success: function (data){
- handle_data(data);
- },
- error: function (e) {}
- });
- response_ref = $.ajax({//OGGETTO
- url: queryRef,
- dataType: "json",
- success: function (data){
- handle_ref(data);
- },
- error: function (e) {}
- });
- response_top = $.ajax({//OGGETTO
- url: queryTopo,
- dataType: "json",
- success: function (data){
- handle_toponym(data);
- },
- error: function (e) {}
- });
- response_receive = $.ajax({//OGGETTO
- url: queryRec,
- dataType: "json",
- success: function (data){
- handle_receive(data);
- },
- error: function (e) {}
- });
- response_send = $.ajax({//OGGETTO
- url: querySend,
- dataType: "json",
- success: function (data){
- handle_send(data);
- },
- error: function (e) {}
- });
- response_cit = $.ajax({//OGGETTO
- url: queryCit,
- dataType: "json",
- success: function (data){
- handle_cit(data);
- },
- error: function (e) {}
- });
- function handle_data(json) {
- console.log(json);
- const locations = [];
- $.each(
- json['results']['bindings'],
- function (index, value) {
- const loc = []
- var graph = value['graph']['value'];
- var ref = value['ref']['value'];
- var label = value['name_place']['value'];
- var coord = value['coordinates']['value'];
- const coordinates = coord.split(", ");
- loc.push(label);
- loc.push(coordinates[0]);
- loc.push(coordinates[1]);
- locations.push(loc);
- document.getElementById("grafo").innerHTML = graph;
- document.getElementById("nome_luogo").innerHTML = label;
-
- });
- var map = L.map('map').setView([locations[0][1], locations[0][2]], 12);
- mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
- L.tileLayer(
- 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
- attribution: '© ' + mapLink + ' Contributors',
- maxZoom: 18,
- }).addTo(map);
- for (var i = 0; i < locations.length; i++) {
- marker = new L.marker([locations[i][1], locations[i][2]])
- .bindPopup(locations[i][0])
- .addTo(map);
- }
- }
- function handle_ref(json) {
- console.log(json);
- const references = [];
- $.each(
- json['results']['bindings'],
- function (index, value) {
- var ref = value['references']['value'];
- references.push(ref);
- });
-
- document.getElementById("riferimenti").innerHTML = references;
-
- }
- function handle_toponym(json) {
- console.log(json);
- const toponym = [];
- $.each(
- json['results']['bindings'],
- function (index, value) {
- var topo = value['toponimi']['value'];
- toponym.push(topo);
- });
-
- document.getElementById("toponimi").innerHTML = toponym;
- }
- function handle_receive(json) {
- console.log(json);
- const received = {};
- $.each(
- json['results']['bindings'],
- function (index, value) {
- key = value['object']['value'];
- data = value['label']['value'];
- received[key] = data;
- });
- var myArray = "";
- for (var key in received) {
- myArray += received[key] + "<br />";
- }
- document.getElementById("object_receive").innerHTML = myArray;
- }
- function handle_send(json) {
- console.log(json);
- const sent = {};
- $.each(
- json['results']['bindings'],
- function (index, value) {
- key = value['object']['value'];
- data = value['label']['value'];
- sent[key] = data;
- });
- var myArray = "";
- for (var key in sent) {
- myArray += sent[key] + "<br />";
- }
- document.getElementById("object_send").innerHTML = myArray;
- }
- function handle_cit(json) {
- console.log(json);
- const citations = {};
- $.each(
- json['results']['bindings'],
- function (index, value) {
- key = value['object']['value'];
- data = value['label']['value'];
- citations[key] = data;
- });
- var myArray = "";
- for (var key in citations) {
- myArray += citations[key] + "<br />";
- }
- document.getElementById("object_cit").innerHTML = myArray;
- }
- //out = "";
- //for(i = 0; i < resultArray.length; i++){
- // out = out + JSON.stringify(resultArray[i])
- //}
- //queryStringOutput = (queryStringOutput + out).replace("}{",",");
- /*
- var locations = [
- ["LOCATION_1", 11.8166, 122.0942],
- ["LOCATION_2", 11.9804, 121.9189],
- ["LOCATION_3", 10.7202, 122.5621],
- ["LOCATION_4", 11.3889, 122.6277],
- ["LOCATION_5", 10.5929, 122.6325]
- ];
- var map = L.map('map').setView([11.206051, 122.447886], 8);
- mapLink =
- '<a href="http://openstreetmap.org">OpenStreetMap</a>';
- L.tileLayer(
- 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
- attribution: '© ' + mapLink + ' Contributors',
- maxZoom: 18,
- }).addTo(map);
- for (var i = 0; i < locations.length; i++) {
- marker = new L.marker([locations[i][1], locations[i][2]])
- .bindPopup(locations[i][0])
- .addTo(map);
- }
- */
|