Forráskód Böngészése

Carica file su 'js'

Alessia 2 éve
szülő
commit
b56c126434
4 módosított fájl, 2084 hozzáadás és 0 törlés
  1. 887 0
      js/advanced_search.js
  2. 186 0
      js/lettera.js
  3. 202 0
      js/lettera_query.js
  4. 809 0
      js/search.js

+ 887 - 0
js/advanced_search.js

@@ -0,0 +1,887 @@
+const choiceArray = [
+	["Label", "Object, OA, Person, Letter, Place", "label"],
+	["Identificatore", "Object, OA, Person, Letter, Place", "identifier"], 
+	["Dimensione", "Object, OA", "dimension"],
+	["Materia", "Object, OA", "material"],
+	["Localizzazione", "Object, OA", "localization"],
+	["Tecnica", "OA", "technique"],
+	["Artista", "OA", "artist"],
+	["Soggetto", "OA", "subject"],
+	["Titolo", "Object, Inf", "title"],
+	["Tipo", "Object, Inf", "type"],
+	["Note", "Object, OA", "notes"],
+	["Riferimenti", "Object, Inf", "references"],
+	["Nome proprio", "Person", "givenName"],
+	["Nome di famiglia", "Person", "familyName"],
+	["Patronimico", "Person", "patronymic"],
+	["Luogo di Nascita", "Person", "birthPlace"],
+	["Luogo di Morte", "Person", "deathPlace"],
+	["Genere", "Person", "sex"],
+	["Data di Nascita", "Person", "birthDate"],
+	["Data di Morte", "Person", "deathDate"],
+	["Occupazione", "Person", "occupation"],
+	["Qualifica", "Person", "qualification"],
+	["Gruppi di appartenenza", "Person", "groups"],
+	["Mittente", "Letter", "sender"],
+	["Destinatario", "Letter", "receiver"],
+	["Luogo di Partenza", "Letter", "startPlace"],
+	["Luogo di Arrivo", "Letter", "endPlace"],
+	["Data partenza", "Letter", "startDate"],
+	["Data arrivo", "Letter", "endDate"],
+	["Lingua", "Letter", "language"],
+	["Area linguistica", "Letter", "languageArea"],
+	["Edizione", "Letter", "edition"],
+	["Antroponimo", "Letter", "antroponym"],
+	["Toponimo", "Letter", "toponym"],
+	["Data", "Object, OA", "date"]
+	];
+
+const typeArray = [
+	["Oggetto", "Object"], 
+	["Lettera", "Letter"],
+	["Opera d'Arte", "OA"],
+	["Persona", "Person"],
+	["Luogo", "Place"]
+	];
+
+const graphArray = [
+	["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"], 
+	["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
+	["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
+	["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
+	["ASPO - Autori ASPO", "http://dev.restore.ovi.cnr.it:8890/aspo/actors"],
+	["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
+	["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
+	["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
+	["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"]
+	];
+
+const objectArray = [];
+const personArray = [];
+const placeArray = [];
+const oaArray = [];
+const letterArray = [];
+
+$(document).ready(function () {
+	//#######################################
+
+	var type_selector = document.getElementById("type_selector");
+	var collection_selector = document.getElementById("collection_selector");
+
+	let x = typeArray.length;
+
+	for(var i=0; i<x; i++) {
+		   var opt = document.createElement("option");
+		   opt.value= typeArray[i][1];
+		   opt.innerHTML = typeArray[i][0]; // whatever property it has
+
+		   // then append it to the select element
+		   type_selector.add(opt);
+		}
+
+	let y = graphArray.length;
+
+	for(var i=0; i<y; i++) {
+		   var opt = document.createElement("option");
+		   opt.value= graphArray[i][1];
+		   opt.innerHTML = graphArray[i][0]; // whatever property it has
+
+		   // then append it to the select element
+		   collection_selector.add(opt);
+		}
+
+	let z = choiceArray.length;
+
+	for(var i=0; i<z; i++) {
+			var cat = choiceArray[i][1];
+			if (cat.includes("Object")) {
+				objectArray.push(choiceArray[i]);
+			}
+			if (cat.includes("OA")) {
+				oaArray.push(choiceArray[i]);
+			}
+			if (cat.includes("Person")) {
+				personArray.push(choiceArray[i]);
+			}
+			if (cat.includes("Letter")) {
+				letterArray.push(choiceArray[i]);
+			}
+			if (cat.includes("Place")) {
+				placeArray.push(choiceArray[i]);
+			}
+		}
+
+	$("#type_selector").change(function(){
+        $(this).find("option:selected").each(function(){
+            var optionValue = $(this).attr("value");
+            if(optionValue){
+                $(".box").not("." + optionValue).hide();
+                $("." + optionValue).show();
+            } else{
+                $(".box").hide();
+            }
+        });
+    }).change();
+
+    /*$('[name=sel-parent]').on('change', function() {
+	   $(this).attr("id", 'example' + $(this).name());
+	});*/
+
+
+});
+
+
+function populateOptions(selector, myArray) {
+
+	var choice_selector = document.getElementById(selector);
+
+	let k = myArray.length;
+
+	for(var i=0; i<k; i++) {
+		   var opt = document.createElement("option");
+		   opt.value= myArray[i][1];
+		   opt.innerHTML = myArray[i][0]; // whatever property it has
+
+		   // then append it to the select element
+		   choice_selector.add(opt);
+		}
+
+	$('#' + selector).on( "change", function() {
+		
+		var numberId= selector.split("-")[1]
+		var inputText=  $( this ).find(":selected").text();
+		/*$('#inputchoiceSelector_' +  numberId).val(inputText);
+		$('#inputchoiceSelector_' +  numberId).id(inputText);*/
+	});
+}
+
+var val = 0;
+
+function addToList() {
+	val = val+1;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, choiceArray);
+}
+
+function addToListObject() {
+	val = val+100;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content-Object').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, objectArray);
+}
+
+function addToListOA() {
+	val = val+200;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content-OA').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, oaArray);
+}
+
+function addToListPerson() {
+	val = val+300;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content-Person').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, personArray);
+}
+
+function addToListLetter() {
+	val = val+400;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content-Letter').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, letterArray);
+}
+
+function addToListPlace() {
+	val = val+500;
+	var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select" aria-label="Default select example"> \
+			  <option selected value="0">Scegli un\'opzione</option> \
+			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
+			</select></div></div>';
+	$('#drop-down-content-Place').append(sel);
+	var selector = 'choice_selector-' + val;
+	populateOptions(selector, placeArray);
+}
+
+
+//Get parameters from select and input options to build the query
+function getParameters() {
+	const arr = [];
+	const collection = document.getElementsByClassName("advanced-form-select");
+	for (let i = 0; i < collection.length; i++) {
+	  var x = collection[i].id;
+	  var t = document.getElementById(x);
+	  var e = t.options[t.selectedIndex].text;
+	  var numberId= x.split("-")[1]
+	  var inputId = "inputchoiceSelector_" + numberId;
+	  var inputText = document.getElementById(inputId).value;
+	  var el = [e, inputText];
+	  arr.push(el);
+	}
+
+	constructQuery(arr);
+	/*$('#query_results').append(arr);
+	testo = $('input#writeText').val();*/
+}
+
+function removeElement(id_element) {
+  const element = document.getElementById(id_element);
+
+  element.remove();
+}
+
+
+//Build query with harvested parametes
+function constructQuery(params) {
+
+	var g = document.getElementById("collection_selector");
+	var graph = g.value;
+
+	var search_graph = "?g";
+
+	if (graph != "") {
+		search_graph = '<' + graph + '>';
+	} 
+
+	var search_type = "";
+
+	var ct = document.getElementById("type_selector");
+	var choosen_type = ct.value;
+
+	console.log(choosen_type);
+
+	if (choosen_type == "Object") {
+		search_type = "?subject rdf:type crm:E22_Man-Made_Object . ";
+	}
+	/*if (choosen_type == "Person") {
+		search_type = "?subject rdf:type crm:E21_Person . ";
+	}
+	if (choosen_type == "Place") {
+		search_type = "?subject rdf:type crm:E53_Place . ";
+	}*/
+
+	//Letter, OA, Person, Place
+
+	var label = ""; //
+	var identificatore = ""; //
+	var dimensione = ""; //
+	var materia = ""; //
+	var localizzazione = ""; //
+	var tecnica = ""; //
+	var artista = ""; //
+	var soggetto = ""; //
+	var titolo = ""; //
+	var tipo = ""; //
+	var note = ""; //
+	var riferimenti = ""; //
+	var nome_proprio = ""; //
+	var nome_di_famiglia = ""; //
+	var patronimico = ""; //
+	var luogo_di_Nascita = ""; //
+	var luogo_di_Morte = ""; //
+	var genere = ""; //
+	var data_di_Nascita = ""; //
+	var data_di_Morte = ""; //
+	var occupazione = ""; //
+	var qualifica = ""; //
+	var gruppi_di_appartenenza = ""; //
+	var mittente = ""; //
+	var destinatario = ""; //
+	var luogo_di_Partenza = ""; //
+	var luogo_di_Arrivo = ""; //
+	var data_partenza = ""; //
+	var data_arrivo = ""; //
+	var lingua = ""; //
+	var area_linguistica = ""; //
+	var edizione = ""; //
+	var antroponimo = ""; //
+	var toponimo = ""; //
+	var data = ""; //
+	var letter_event = ""; //
+	var infObj = ""; //
+
+	var id = ""; //
+	var dm = ""; //
+	var mt = ""; //
+	var loc = ""; //
+	var tec = ""; //
+	var at = ""; //
+	var sg = ""; //
+	var tt = ""; //
+	var tp = ""; //
+	var nt = ""; //
+	var rf = ""; //
+	var np = ""; //
+	var nf = ""; //
+	var pt = ""; //
+	var ln = ""; //
+	var lm = ""; //
+	var gr = ""; //
+	var dn = ""; //
+	var dts = ""; //
+	var oc = ""; //
+	var qf = ""; //
+	var ga = ""; //
+	var mit = ""; //
+	var des = ""; //
+	var lp = ""; //
+	var la = ""; //
+	var dp = ""; //
+	var da = ""; //
+	var lin = ""; //
+	var alin = ""; //
+	var ed = ""; //
+	var antr = ""; //
+	var topo = ""; //
+	var dt = ""; //
+
+	for (let i = 0; i < params.length; i++) {
+		if(params[i][0] == "Label" && (params[i][1] != "")) {
+			label = "?label bif:contains \"\' "+ params[i][1] + " \'\" . ";
+		}
+		if(params[i][0] == "Identificatore" && (params[i][1] != "")) {
+			id = " ?identifier";
+
+			identificatore = "?subject crm:P1_is_identified_by ?uri_identifier . \
+			?uri_identifier rdfs:label ?identifier . \
+			?identifier bif:contains \"\'"+ params[i][1] +"\'\" . ";
+		}
+		if(params[i][0] == "Dimensione" && (params[i][1] != "")) {
+			dm = " ?dimension";
+
+			dimensione = "?subject crm:P43_has_dimension ?uri_dimension . \
+			?uri_dimension rdfs:label ?dimension . \
+			?dimension bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if(params[i][0] == "Materia" && (params[i][1] != "")) {
+			mt = " ?material";
+
+			materia = "?subject crm:P45_consists_of ?uri_material . \
+			?uri_material rdfs:label ?material . \
+			?material bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if(params[i][0] == "Localizzazione" && (params[i][1] != "")) {
+			loc = " ?location";
+
+			localizzazione = "?subject crm:P54_has_current_permanent_location ?uri_location . \
+			?uri_location rdfs:label ?location . \
+			?location bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
+			tec = " ?technique";
+
+			tecnica = "?subject ?property ?event . \
+			?event crm:P32_used_general_technique ?uri_technique . \
+			?uri_technique rdfs:label ?technique . \
+			?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Artista" && (params[i][1] != "")) {
+			at = " ?artist";
+
+			artista = "?subject rdfs:label ?label .	\
+			?production crm:P108_has_produced ?subject . \
+			?pc crm:P01_has_domain ?production . \
+			?pc crm:P02_has_range ?range . \
+			?range rdfs:label ?artist . \
+			?artist bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Soggetto" && (params[i][1] != "")) {
+			sg = " ?depiction";
+
+			soggetto = "?subject crm:P62_depicts ?uri_depiction . \
+			?uri_depiction rdfs:label ?depiction . \
+			?depiction bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Titolo" && (params[i][1] != "")) {
+			tt = " ?title";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			titolo = "?information_object crm:P1_is_identified_by ?uri_title . \
+			?uri_title rdfs:label ?title . \
+			?title bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Tipo" && (params[i][1] != "")) {
+			tp = " ?type";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			tipo = "?information_object crm:P2_has_type ?uri_type . \
+			?uri_type rdfs:label ?type . \
+			?type bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Note" && (params[i][1] != "")) {
+			nt = " ?note";
+
+			note = "?subject crm:P3_has_note ?uri_note . \
+			?uri_note rdfs:label ?note . \
+			?note bif:contains \"\'"+ params[i][1] +"\'\" .";
+		}
+		if (params[i][0] == "Riferimenti" && (params[i][1] != "")) {
+			rf = " ?ref";
+
+			riferimenti = "?subject crm:P67_refers_to ?uri_ref . \
+			?uri_ref rdfs:label ?ref . \
+			?ref bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Nome proprio" && (params[i][1] != "")) {
+			np = " ?givenName";
+
+			nome_proprio = "?subject foaf:givenName ?givenName . \
+			?givenName bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Nome di famiglia" && (params[i][1] != "")) {
+			nf = " ?familyName";
+
+			nome_di_famiglia = "?subject foaf:familyName ?familyName . \
+			?familyName bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Patronimico" && (params[i][1] != "")) {
+			pt = " ?patronymic";
+
+			patronimico = "?subject person:patronymicName ?patronymic . \
+			?patronymic bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Luogo di Nascita" && (params[i][1] != "")) {
+			ln = " ?birthPlace";
+
+			luogo_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
+			?Birth crm:P7_took_place_at ?uri_birthPlace . \
+			?uri_birthPlace rdfs:label ?birthPlace . \
+			?birthPlace bif:contains \""+ params[i][1] +"\" . "
+		}
+		if (params[i][0] == "Luogo di Morte" && (params[i][1] != "")) {
+			lm = " ?deathPlace";
+
+			luogo_di_Morte = "?subject crm:P100i_died_in ?Death . \
+			?Death crm:P7_took_place_at ?uri_deathPlace . \
+			?uri_deathPlace rdfs:label ?deathPlace \
+			?deathPlace bif:contains \""+ params[i][1] +"\" .	"
+		}
+		if (params[i][0] == "Genere" && (params[i][1] != "")) {
+			gr = "?genere";
+
+			genere = "?subject foaf:gender ?genere . \
+			?genere bif:contains \""+ params[i][1] +"\" . "
+		}
+		if (params[i][0] == "Data di Nascita" && (params[i][1] != "")) {
+			dn = " ?Birth_TS";
+
+			data_di_Nascita = "?subject crm:P98i_was_born ?Birth . 	\
+			?Birth crm:P4_has_time-span ?Birth_TS . \
+			?Birth_TS rdfs:label \""+ params[i][1] +"\" ."
+		}
+		if (params[i][0] == "Data di Morte" && (params[i][1] != "")) {
+			dts = " ?Death_TS";
+
+			data_di_Morte = "?subject crm:P100i_died_in ?Death . \
+			?Death crm:P4_has_time-span ?Death_TS . \
+			?Death_TS rdfs:label \""+ params[i][1] +"\" . "
+		}
+		if (params[i][0] == "Qualifica" && (params[i][1] != "")) {
+			qf = " ?qualification";
+
+			qualifica = "?subject schema:honorificPrefix ?qualification . \
+			?qualification bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Occupazione" && (params[i][1] != "")) {
+			oc = " ?occupation";
+
+			occupazione = "?subject schema:hasOccupation ?uriOccupation . \
+			?uriOccupation rdf:type schema:Occupation; \
+			rdfs:label ?occupation . \
+			?occupation bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Gruppi di appartenenza" && (params[i][1] != "")) {
+			ga = " ?group";
+
+			gruppi_di_appartenenza = "?subject crm:P107i_is_current_or_former_member_of ?uriGroup . \
+			?uriGroup rdfs:label ?group . \
+			?group bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Mittente" && (params[i][1] != "")) {
+			mit = " ?mittente";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			mittente = "?send crm:P01_has_domain ?pcS . \
+			?pcS crm:P02_has_range ?uriSender . \
+			?uriSender rdfs:label ?mittente . \
+			?mittente bif:contains \"\'"+ params[i][1] +"\'\" .	 "
+		}
+		if (params[i][0] == "Destinatario" && (params[i][1] != "")) {
+			des = " ?destinatario";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			destinatario = "?receive crm:P01_has_domain ?pcR . \
+			?pcR crm:P02_has_range ?uriReceiver . \
+			?uriReceiver rdfs:label ?destinatario . \
+			?destinatario bif:contains \"\'"+ params[i][1] +"\'\" .	"
+		}
+		if (params[i][0] == "Luogo di Partenza" && (params[i][1] != "")) {
+			lp = " ?luogo_partenza";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			luogo_di_Partenza = "?send crm:P27_moved_from ?uriLuogoPartenza . \
+			?uriLuogoPartenza rdfs:label ?luogo_partenza . \
+			?luogo_partenza bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Luogo di Arrivo" && (params[i][1] != "")) {
+			la = " ?luogo_arrivo";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			luogo_di_Arrivo = "?receive crm:P26_moved_to ?uriLuogoArrivo . \
+			?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
+			?luogo_arrivo bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Data partenza" && (params[i][1] != "")) {
+			dp = " ?timeSpanSend";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			data_partenza = "?send crm:P4_has_time-span ?time_spanS . \
+			?time_spanS rdfs:label ?timeSpanSend . \
+			?timeSpanSend bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Data arrivo" && (params[i][1] != "")) {
+			da = " ?timeSpanReceive";
+
+			letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
+			?send rdfs:subClassOf ?mov_ev ; \
+			rdf:type crm:EL2_Send_Letter . \
+			?receive rdfs:subClassOf ?mov_ev; \
+			rdf:type crm:EL3_Receive_Letter . ";
+
+			data_arrivo = "?receive crm:P4_has_time-span ?time_spanR . \
+			?time_spanR rdfs:label ?timeSpanReceive .\
+			?timeSpanReceive bif:contains \"\'"+ params[i][1] +"\'\" . "
+		}
+		if (params[i][0] == "Lingua" && (params[i][1] != "")) {
+			lin = " ?lingua";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			lingua = "?information_object crm:P72_has_language ?language . \
+			?language rdfs:label ?lingua . \
+			?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
+			alin = " ?area_linguistica";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			area_linguistica = "?information_object crm:P72_has_language ?language . \
+			?language crm:P3_has_note ?area . \
+			?area rdfs:label ?area_linguistica .\
+			?area_linguistica bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Edizione" && (params[i][1] != "")) {
+			ed = " ?edizione";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			edizione = "?edition crm:P70_documents ?information_object ; \
+			crm:P1_is_identified_by ?edition_id . \
+			?edition_id rdfs:label ?edizione . \
+			?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Toponimo" && (params[i][1] != "")) {
+			topo = " ?toponimo";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			toponimo = "?information_object crm:P67_refers_to ?link_toponimo . \
+			?link_toponimo rdfs:label ?toponimo ; \
+			crm:P2_has_type 'Toponimo' . \
+			?toponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Antroponimo" && (params[i][1] != "")) {
+			antr = " ?antroponimo";
+
+			infObj = "?subject crm:P128_carries ?information_object .";
+
+			antroponimo = "?information_object crm:P67_refers_to ?link_antroponimo . \
+			?link_antroponimo rdfs:label ?antroponimo; \
+			crm:P2_has_type 'Antroponimo' . \
+			?antroponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+		if (params[i][0] == "Data" && (params[i][1] != "")) {
+			dt = " ?date";
+
+			data = "?subject ?property ?event . \
+			?event crm:P4_has_time-span ?uri_date . \
+			?uri_date rdfs:label ?date . \
+			?date bif:contains \"\'"+ params[i][1] +"\'\" ."
+		}
+
+	}
+
+
+	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#> \
+	PREFIX schema: <http://schema.org/> \
+	PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
+	PREFIX person: <http://www.w3.org/ns/person#>"
+
+	query = prefixes + " SELECT DISTINCT ?subject ?label" + id + dm + mt + loc + tec + at
+	+ sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit 
+	+ des + lp + la + dp + da + lin + alin + ed + antr + topo + dt + " \
+	WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
+	?subject rdfs:label ?label . " 
+	+ infObj + letter_event + label + search_type + identificatore + dimensione + materia + localizzazione + tecnica 
+	+ artista + titolo + tipo + note + riferimenti + nome_proprio + nome_di_famiglia
+	+ patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita 
+	+ data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario 
+	+luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua 
+	+ area_linguistica + edizione + toponimo + antroponimo + data + "}"
+
+	var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
+
+	console.log(query);
+
+	$.ajax({
+
+			url: query_url + '&callback=?',
+			dataType: "json",
+			success: function (data) {
+				query_handle_json(data);
+			},
+			error: function (e) {}
+		});
+
+}
+
+function query_handle_json(json) {
+
+	console.log(json); 
+
+		$('#query_results').text("");
+
+		var i = 0;
+
+		const first_row = [];
+
+		$.each(
+			json['head']['vars'],
+			function (index, value) {
+				first_row.push(value);
+		});
+
+		var t_head = '<div class="row t_head">';
+
+		for (let k = 0; k < first_row.length; k++) {
+			t_head += '<div class="col-auto">' + first_row[k] + '</div>';
+		}
+
+		t_head += '</div>';
+
+
+		$('#query_results').append(t_head);
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var object = ""; 
+
+				var link = value['subject']['value'];
+				var label = value['label']['value'];
+
+				object += '<div class="row"><div class="col-auto">' + link + '</div><div class="col-auto">' + label + '</div>';
+
+				if (value.hasOwnProperty('identifier')) {
+		          identifier = value['identifier']['value'];
+		          object += '<div class="col-auto">' + identifier + '</div>';
+		        }
+		        if (value.hasOwnProperty('dimension')) {
+		          dimension = value['dimension']['value'];
+		          object += '<div class="col-auto">' + dimension + '</div>';
+		        }
+		        if (value.hasOwnProperty('material')) {
+		          material = value['material']['value'];
+		          object += '<div class="col-auto">' + material + '</div>';
+		        }
+		        if (value.hasOwnProperty('location')) {
+		          location = value['location']['value'];
+		          object += '<div class="col-auto">' + location + '</div>';
+		        }
+		        if (value.hasOwnProperty('technique')) {
+		          technique = value['technique']['value'];
+		          object += '<div class="col-auto">' + technique + '</div>';
+		        }
+		        if (value.hasOwnProperty('artist')) {
+		          artist = value['artist']['value'];
+		          object += '<div class="col-auto">' + artist + '</div>';
+		        }
+		        if (value.hasOwnProperty('depiction')) {
+		          depiction = value['depiction']['value'];
+		          object += '<div class="col-auto">' + depiction + '</div>';
+		        }
+		        if (value.hasOwnProperty('title')) {
+		          title = value['title']['value'];
+		          object += '<div class="col-auto">' + title + '</div>';
+		        }
+		        if (value.hasOwnProperty('type')) {
+		          type = value['type']['value'];
+		          object += '<div class="col-auto">' + type + '</div>';
+		        }
+		        if (value.hasOwnProperty('note')) {
+		          note = value['note']['value'];
+		          object += '<div class="col-auto">' + note + '</div>';
+		        }
+		        if (value.hasOwnProperty('ref')) {
+		          ref = value['ref']['value'];
+		          object += '<div class="col-auto">' + ref + '</div>';
+		        }
+		        if (value.hasOwnProperty('givenName')) {
+		          givenName = value['givenName']['value'];
+		          object += '<div class="col-auto">' + givenName + '</div>';
+		        }
+		        if (value.hasOwnProperty('familyName')) {
+		          familyName = value['familyName']['value'];
+		          object += '<div class="col-auto">' + familyName + '</div>';
+		        }
+		        if (value.hasOwnProperty('patronymic')) {
+		          patronymic = value['patronymic']['value'];
+		          object += '<div class="col-auto">' + patronymic + '</div>';
+		        }
+		        if (value.hasOwnProperty('birthPlace')) {
+		          birthPlace = value['birthPlace']['value'];
+		          object += '<div class="col-auto">' + birthPlace + '</div>';
+		        }
+		        if (value.hasOwnProperty('deathPlace')) {
+		          deathPlace = value['deathPlace']['value'];
+		          object += '<div class="col-auto">' + deathPlace + '</div>';
+		        }
+		        if (value.hasOwnProperty('genere')) {
+		          genere = value['genere']['value'];
+		          object += '<div class="col-auto">' + genere + '</div>';
+		        }
+		        if (value.hasOwnProperty('Birth_TS')) {
+		          Birth_TS = value['Birth_TS']['value'];
+		          object += '<div class="col-auto">' + Birth_TS + '</div>';
+		        }
+		        if (value.hasOwnProperty('Death_TS')) {
+		          Death_TS = value['Death_TS']['value'];
+		          object += '<div class="col-auto">' + Death_TS + '</div>';
+		        }
+		        if (value.hasOwnProperty('qualification')) {
+		          qualification = value['qualification']['value'];
+		          object += '<div class="col-auto">' + qualification + '</div>';
+		        }
+		        if (value.hasOwnProperty('occupation')) {
+		          occupation = value['occupation']['value'];
+		          object += '<div class="col-auto">' + occupation + '</div>';
+		        }
+		        if (value.hasOwnProperty('group')) {
+		          group = value['group']['value'];
+		          object += '<div class="col-auto">' + group + '</div>';
+		        }
+		        if (value.hasOwnProperty('mittente')) {
+		          mittente = value['mittente']['value'];
+		          object += '<div class="col-auto">' + mittente + '</div>';
+		        }
+		        if (value.hasOwnProperty('destinatario')) {
+		          destinatario = value['destinatario']['value'];
+		          object += '<div class="col-auto">' + destinatario + '</div>';
+		        }
+		        if (value.hasOwnProperty('luogo_partenza')) {
+		          luogo_partenza = value['luogo_partenza']['value'];
+		          object += '<div class="col-auto">' + luogo_partenza + '</div>';
+		        }
+		        if (value.hasOwnProperty('luogo_arrivo')) {
+		          luogo_arrivo = value['luogo_arrivo']['value'];
+		          object += '<div class="col-auto">' + luogo_arrivo + '</div>';
+		        }
+		        if (value.hasOwnProperty('timeSpanSend')) {
+		          timeSpanSend = value['timeSpanSend']['value'];
+		          object += '<div class="col-auto">' + timeSpanSend + '</div>';
+		        }
+		        if (value.hasOwnProperty('timeSpanReceive')) {
+		          timeSpanReceive = value['timeSpanReceive']['value'];
+		          object += '<div class="col-auto">' + timeSpanReceive + '</div>';
+		        }
+		        if (value.hasOwnProperty('lingua')) {
+		          lingua = value['lingua']['value'];
+		          object += '<div class="col-auto">' + lingua + '</div>';
+		        }
+		        if (value.hasOwnProperty('area_linguistica')) {
+		          area_linguistica = value['area_linguistica']['value'];
+		          object += '<div class="col-auto">' + area_linguistica + '</div>';
+		        }
+		        if (value.hasOwnProperty('edizione')) {
+		          edizione = value['edizione']['value'];
+		          object += '<div class="col-auto">' + edizione + '</div>';
+		        }
+		        if (value.hasOwnProperty('toponimo')) {
+		          toponimo = value['toponimo']['value'];
+		          object += '<div class="col-auto">' + toponimo + '</div>';
+		        }
+		        if (value.hasOwnProperty('antroponimo')) {
+		          antroponimo = value['antroponimo']['value'];
+		          object += '<div class="col-auto">' + antroponimo + '</div>';
+		        }
+		        if (value.hasOwnProperty('date')) {
+		          date = value['date']['value'];
+		          object += '<div class="col-auto">' + date + '</div>';
+		        } 
+
+		        object += '</div>';
+
+				i++;
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+				$('#query_results').append(object);
+				
+
+			});
+
+		if (i==0) {
+			var message = '<p>Nessun risultato trovato</p>';
+			$('#query_results').append(message);
+		}
+}

+ 186 - 0
js/lettera.js

@@ -0,0 +1,186 @@
+
+// Oggetto che raccoglie le info necessarie per la pagina
+pageInfo = {};
+
+// Inizializzazione della pagina
+initPage();
+
+
+// Def. funzione di inizializzazione
+async function initPage(){
+	pageInfo = await getPageInfo();
+	updatePage();
+}
+
+// Esegue le queries, restituisce un oggetto con tutte le info per completare la pagina
+async function getPageInfo(){
+	var out = {};
+
+	try{
+		out.query1 = await doJsonQuery(query1, true);
+		out.query2 = await doJsonQuery(query2, true);
+		out.titolo = await doJsonQuery(queryTitolo, true);
+		out.segnatura = await doJsonQuery(querySegnatura, true);
+		out.areaLinguistica = await doJsonQuery(queryAreaLinguistica, true);
+		out.descrizione = await doJsonQuery(queryDescrizione, true);
+		out.testo = await doJsonQuery(queryTestoLemmatizzato, true);
+		out.edizione = await doJsonQuery(queryEdizione, true);
+		out.toponimi = await doJsonQuery(queryToponimi);
+		out.antroponimi = await doJsonQuery(queryAntroponimi);
+
+		// out.tipo = await doJsonQuery(queryTipo);
+		// out.siglaOVI = await doJsonQuery(querySiglaOVI);
+		// out.raccolta = await doJsonQuery(queryRaccolta);
+	} catch(err){
+		console.log(err);
+	}
+
+	console.log('out', out)
+	return out;
+}
+
+
+// Aggiorna la pagina usando l'oggetto-info passato come parametro
+function updatePage(){
+
+	if(pageInfo.titolo) document.getElementById("title").innerHTML = pageInfo.titolo.titolo.value;
+	
+	if(pageInfo.query1) {
+		if(pageInfo.query1.hasOwnProperty('mittente')) document.getElementById("mittente_id").innerHTML = pageInfo.query1.mittente.value;
+		if(pageInfo.query1.hasOwnProperty('destinatario')) document.getElementById("destinatario_id").innerHTML = pageInfo.query1.destinatario.value;
+		if(pageInfo.query1.hasOwnProperty('luogo_partenza')) document.getElementById("luogo_partenza_id").innerHTML = pageInfo.query1.luogo_partenza.value;
+		if(pageInfo.query1.hasOwnProperty('uriLuogoPartenza')) document.getElementById("luogo_partenza_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoPartenza.value));
+		if(pageInfo.query1.hasOwnProperty('luogo_arrivo')) document.getElementById("luogo_arrivo_id").innerHTML = pageInfo.query1.luogo_arrivo.value;
+		if(pageInfo.query1.hasOwnProperty('uriLuogoArrivo')) document.getElementById("luogo_arrivo_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoArrivo.value));
+		if(pageInfo.query1.hasOwnProperty('data_partenza')) document.getElementById("data_partenza_id").innerHTML = pageInfo.query1.data_partenza.value;
+		if(pageInfo.query1.hasOwnProperty('data_arrivo')) document.getElementById("data_arrivo_id").innerHTML = pageInfo.query1.data_arrivo.value;
+		
+	}
+
+	/*if(pageInfo.query1){
+		document.getElementById("mittente_id").innerHTML = pageInfo.query1.mittente.value;
+		//document.getElementById("mittente_btn").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query1.mittente.value));
+	}
+	if(pageInfo.query1){
+		document.getElementById("destinatario_id").innerHTML = pageInfo.query1.destinatario.value;
+		//document.getElementById("destinatario_btn").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query1.destinatario.value));
+	}
+	if(pageInfo.query1){
+		document.getElementById("imageASPO").innerHTML = createEmbed(pageInfo.query1.subject.value);
+	}
+	if(pageInfo.query1){
+		document.getElementById("luogo_partenza_id").innerHTML = pageInfo.query1.luogo_partenza.value;
+		document.getElementById("luogo_partenza_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoPartenza.value));
+	}
+	if(pageInfo.query1){
+		document.getElementById("luogo_arrivo_id").innerHTML = pageInfo.query1.luogo_arrivo.value;
+		document.getElementById("luogo_arrivo_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoArrivo.value));
+	}
+	if(pageInfo.query1) document.getElementById("data_partenza_id").innerHTML = pageInfo.query1.data_partenza.value;
+	if(pageInfo.query1) document.getElementById("data_arrivo_id").innerHTML = pageInfo.query1.data_arrivo.value;
+	*/
+	if(pageInfo.descrizione) document.getElementById("descrizione_id").innerHTML = pageInfo.descrizione.descrizione.value;
+	if(pageInfo.areaLinguistica) document.getElementById("lingua_id").innerHTML = pageInfo.areaLinguistica.lingua.value;
+	if(pageInfo.areaLinguistica) document.getElementById("area_linguistica_id").innerHTML = pageInfo.areaLinguistica.area_linguistica.value;
+	if(pageInfo.segnatura){
+		document.getElementById("segnatura_id").innerHTML = pageInfo.segnatura.segnatura_OVI.value;
+		document.getElementById("segnatura_btn").innerHTML = createButton("fa fa-link", "Link ASPO", "schedaASPO('SEGN')".replace("SEGN", thisUrlParams.link));
+	}
+	if(pageInfo.edizione){
+		document.getElementById("edizione_id").innerHTML = pageInfo.edizione.edizione.value;
+		document.getElementById("edizione_btn").innerHTML = createButton("fa fa-comments", "Cita Edizione", "schedaEdizione('EDIZ')".replace("EDIZ", pageInfo.edizione.edizione.value));
+	}
+	if(pageInfo.testo) document.getElementById("trascrizione_id").innerHTML = pageInfo.testo.testo_lemmatizzato.value;
+	//
+	if(pageInfo.antroponimi && pageInfo.antroponimi.length){
+		const listaAntroponimi = pageInfo.antroponimi.map(elem => elem.antroponimo.value);
+		document.getElementById("antroponimi").innerHTML = formatListAsLi(listaAntroponimi);
+	}
+	if(pageInfo.toponimi && pageInfo.toponimi.length){
+		const listaToponimi = pageInfo.toponimi.map(elem => elem.toponimo.value);
+		document.getElementById("toponimi").innerHTML = formatListAsLi(listaToponimi);
+	}
+
+	if(pageInfo.query2) {
+		if(pageInfo.query2.hasOwnProperty('mittente')) document.getElementById("mittente_id_ASPO").innerHTML = pageInfo.query2.mittente.value;
+		if(pageInfo.query2.hasOwnProperty('uriSender')) document.getElementById("mittente_btn_ASPO").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query2.uriSender.value));
+		if(pageInfo.query2.hasOwnProperty('destinatario')) document.getElementById("destinatario_id_ASPO").innerHTML = pageInfo.query2.destinatario.value;
+		if(pageInfo.query2.hasOwnProperty('uriReceiver')) document.getElementById("destinatario_btn_ASPO").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query2.uriReceiver.value));
+		if(pageInfo.query2.hasOwnProperty('placeSend')) document.getElementById("luogo_partenza_id_ASPO").innerHTML = pageInfo.query2.placeSend.value;
+		if(pageInfo.query2.hasOwnProperty('placeReceive')) document.getElementById("luogo_arrivo_id_ASPO").innerHTML = pageInfo.query2.placeReceive.value;
+		if(pageInfo.query2.hasOwnProperty('timeSpanSend')) document.getElementById("data_partenza_id_ASPO").innerHTML = pageInfo.query2.timeSpanSend.value;
+		if(pageInfo.query2.hasOwnProperty('timeSpanReceive')) document.getElementById("data_arrivo_id_ASPO").innerHTML = pageInfo.query2.timeSpanReceive.value;
+		if(pageInfo.query2.hasOwnProperty('material')) document.getElementById("consistenzaASPO").innerHTML = pageInfo.query2.material.value;
+		if(pageInfo.query2.hasOwnProperty('dimension')) document.getElementById("dimensioneASPO").innerHTML = pageInfo.query2.dimension.value;
+		if(pageInfo.query2.hasOwnProperty('identifier')) document.getElementById("segnatura_id_ASPO").innerHTML = pageInfo.query2.identifier.value;
+		if(pageInfo.query2.hasOwnProperty('currentLocation')) document.getElementById("ownerASPO").innerHTML = pageInfo.query2.currentLocation.value;
+		
+	}
+
+	if(pageInfo.query1){
+		document.getElementById("imageASPO").innerHTML = createEmbed(pageInfo.query1.subject.value);
+	}
+}
+
+// Mini-utility per formattare liste
+function formatListAsLi(thisList){
+	toRet = "";
+	thisList.forEach(value => toRet += "<li>" + value + "</li>");
+	return toRet;
+}
+
+// Buttons
+function createButton(buttonClass, text, onClickFunction){
+	htmlCode = '\
+		<button class="btn btn-default" type="button" onclick="<FUNCTION>">\
+		<i class="<CLASS>" aria-hidden="true">\
+			<p class="btn-text"><TEXT></p>\
+		</i>\
+		</button>\
+		'.replace("<CLASS>", buttonClass).replace("<TEXT>", text).replace("<FUNCTION>", onClickFunction);
+	return htmlCode;
+}
+
+function createEmbed(link) {
+	image = link.replace("scheda", "imageView") + "/#main";
+	htmlCode = '\
+		<embed id="imageEmb" src="<LINK>"> \
+		'.replace("<LINK", image);
+	return htmlCode;
+}
+
+function schedaPersona(info){
+	window.open("Persona.html?link="+info);
+}
+
+function schedaMappa(info){
+	window.open("Luogo.html?link="+info);
+}
+
+function schedaASPO(info){
+	window.open(info);
+}
+
+function schedaEdizione(info){
+	alert("Hi! I've been clicked.\n I've been passed: '" + info + "' as a paramater");
+}
+
+function show_OVI(){
+	document.getElementById("OVI_info").style.display = "block";
+    document.getElementById("ASPO_info").style.display = "none";
+}
+
+function show_ASPO(){
+	document.getElementById("OVI_info").style.display = "none";
+    document.getElementById("ASPO_info").style.display = "block";
+}
+
+var header = document.getElementById("choice_buttons");
+var btns = header.getElementsByClassName("btn");
+for (var i = 0; i < btns.length; i++) {
+  btns[i].addEventListener("click", function() {
+  var current = document.getElementsByClassName("active");
+  current[0].className = current[0].className.replace(" active", "");
+  this.className += " active";
+  });
+}

+ 202 - 0
js/lettera_query.js

@@ -0,0 +1,202 @@
+
+// Recupero 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;
+}
+
+// Esegue una query sull'endpoint SPARQL il cui testo completo deve essere fornito nel parametro-stringa 'query'
+// Restituisce una lista di oggetti json nel formato di Virtuoso
+// Il parametro opzionale 'isUnique', se messo a 'true' controlla che ci sia un unico risultato (un array di
+// lunghezza 1) e se non è così restituisce un errore.
+async function doJsonQuery(query, isUnique = false){
+
+    queryURL = prepareQueryURL(query);
+
+    response = await $.ajax({//OGGETTO
+
+        url: queryURL,
+        dataType: "json",
+        success: function (data){},
+        error: function (e) {
+            console.log("Exception in query:", e);
+        }
+    });
+
+    let out = response['results']['bindings'];
+    if(!isUnique) return out;
+    if(!out.length) throw "ERROR: Letter not found";
+    if(out.length>1) throw "ERROR: ambiguity in search -- multiple letters matching search parameters";
+    return out[0];
+
+}
+
+// Nuova funzione per l'NLP
+function loadPageNLP()
+{
+     window.location="nlp.html?link=" + thisUrlParams.link;
+}
+
+// Nuova funzione per Button EVT
+function loadPageEVT()
+{
+     window.location="http://restore.ovi.cnr.it/mockup/evt/index.html";
+}
+
+// Nuova funzione per Button LOD
+function loadPageLOD()
+{
+     window.location="http://dev.restore.ovi.cnr.it/lodlive/?" + thisUrlParams.link;
+}
+
+
+////////////////////
+// TESTI DELLE QUERY
+////////////////////
+
+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 dat: <http://datini.archiviodistato.prato.it/la-ricerca/scheda/> \
+PREFIX mpp: <http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/> \
+PREFIX aut: <http://palazzopretorio.comune.prato.it/it/opere/autori/>"
+
+query1 = prefixes + " SELECT DISTINCT ?subject ?mittente ?destinatario ?data_partenza ?data_arrivo ?uriLuogoPartenza ?luogo_partenza ?uriLuogoArrivo ?luogo_arrivo \
+WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> \
+GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?subject crm:P25i_moved_by ?mov_ev .} \
+?send rdfs:subClassOf ?mov_ev ; \
+rdf:type crm:EL2_Send_Letter . \
+OPTIONAL {?send crm:P4_has_time-span ?time_spanA . \
+?time_spanA rdfs:label ?data_partenza . } \
+OPTIONAL {?send crm:P27_moved_from ?uriLuogoPartenza . \
+?uriLuogoPartenza rdfs:label ?luogo_partenza . } \
+OPTIONAL {?send crm:P01_has_domain ?uriMittente . \
+?uriMittente crm:P02_has_range ?mittente . } \
+ \
+?receive rdfs:subClassOf ?mov_ev; \
+rdf:type crm:EL3_Receive_Letter . \
+OPTIONAL {?receive crm:P4_has_time-span ?time_spanB . \
+?time_spanB rdfs:label ?data_arrivo . } \
+OPTIONAL {?receive crm:P26_moved_to ?uriLuogoArrivo . \
+?uriLuogoArrivo rdfs:label ?luogo_arrivo . } \
+OPTIONAL {?receive crm:P01_has_domain ?receiver . \
+?receiver crm:P02_has_range ?destinatario . } \
+} LIMIT 1"
+
+query2 = prefixes + " SELECT DISTINCT ?uriSender ?mittente ?uriReceiver ?destinatario ?timeSpanSend ?timeSpanReceive ?placeSend ?placeReceive ?identifier ?material ?dimension ?currentLocation \
+WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> . \
+GRAPH <http://dev.restore.ovi.cnr.it:8890/aspo/datini/item> {?subject crm:P25i_moved_by ?mov_ev .} \
+?send rdfs:subClassOf ?mov_ev ; \
+rdf:type crm:EL2_Send_Letter . \
+?receive rdfs:subClassOf ?mov_ev ; \
+rdf:type crm:EL3_Receive_Letter . \
+\
+OPTIONAL {?subject crm:P54_has_current_permanent_location ?uriCurrentLocation . \
+?uriCurrentLocation rdfs:label ?currentLocation . } \
+OPTIONAL {?subject crm:P45_consist_of ?uriMaterial . \
+?uriMaterial rdfs:label ?material . } \
+OPTIONAL {?subject crm:P43_has_dimension ?uriDimension . \
+?uriDimension rdfs:label ?dimension . } \
+OPTIONAL {?subject crm:P1_is_identified_by ?uriIdentifier . \
+?uriIdentifier rdfs:label ?identifier . \
+?identifier bif:contains 'Segnatura'} \
+\
+OPTIONAL {?send crm:P4_has_time-span ?time_spanS . \
+?time_spanS rdfs:label ?timeSpanSend } \
+OPTIONAL {?receive crm:P4_has_time-span ?time_spanR . \
+?time_spanR rdfs:label ?timeSpanReceive } \
+\
+OPTIONAL {?send crm:P27_moved_from ?placeS . \
+?placeS rdfs:label ?placeSend } \
+OPTIONAL {?receive crm:P26_moved_to ?placeR . \
+?placeR rdfs:label ?placeReceive } \
+\
+OPTIONAL {?send crm:P01_has_domain ?pcS . \
+?pcS crm:P02_has_range ?uriSender . \
+?uriSender rdfs:label ?mittente } \
+\
+OPTIONAL {?receive crm:P01_has_domain ?pcR . \
+?pcR crm:P02_has_range ?uriReceiver . \
+?uriReceiver rdfs:label ?destinatario } \
+} LIMIT 1"
+
+querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
+WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
+crm:P1_is_identified_by ?segnatura_ASPO . \
+?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
+?segnatura crm:P2_has_type ?tipo_segnatura ; \
+rdfs:label ?segnatura_OVI . \
+?tipo_segnatura rdfs:label \"Segnatura OVI\"} LIMIT 1"
+
+queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
+WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
+?language crm:P3_has_note ?area ; \
+rdfs:label ?lingua . \
+?area rdfs:label ?area_linguistica \
+} LIMIT 1"
+
+
+queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
+WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
+?description rdfs:label ?descrizione \
+} LIMIT 1"
+
+queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
+WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
+?type rdf:type crm:E55_Type; \
+rdfs:label ?tipologia . \
+} LIMIT 1"
+
+querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
+WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
+?id rdf:type crm:E42_Identifier; \
+crm:P2_has_type ?type ; \
+rdfs:label ?sigla_OVI . \
+?type rdfs:label 'Sigla OVI'. \
+} LIMIT 1"
+
+queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
+WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
+?title rdf:type crm:E35_Title; \
+rdfs:label ?titolo . \
+} LIMIT 1"
+
+queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
+WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
+} LIMIT 1"
+
+queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
+WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
+crm:P1_is_identified_by ?edition_id . \
+?edition_id rdfs:label ?edizione; \
+crm:P139_has_alternative_form ?ed_abbr . \
+?ed_abbr rdfs:label ?edizione_abbreviata \
+} LIMIT 1"
+
+queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
+WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
+crm:P2_has_type ?racc_type ; \
+rdfs:label ?raccolta . \
+?racc_type rdfs:label 'Raccolta'. \
+} LIMIT 1"
+
+queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
+WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
+?link_toponimo rdfs:label ?toponimo ; \
+crm:P2_has_type 'Toponimo' . \
+}"
+
+queryAntroponimi = prefixes + "SELECT DISTINCT * \
+WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
+?link_antroponimo rdfs:label ?antroponimo; \
+crm:P2_has_type 'Antroponimo'}"

+ 809 - 0
js/search.js

@@ -0,0 +1,809 @@
+$(document).ready(function () {
+	//#######################################
+
+	const graphArray = [
+	["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"], 
+	["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
+	["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
+	["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
+	["ASPO - Autori ASPO", "http://dev.restore.ovi.cnr.it:8890/aspo/actors"],
+	["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
+	["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
+	["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
+	["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"],
+	["Luoghi", "http://dev.restore.ovi.cnr.it:8890/mpp/places"]
+	];
+
+	var graph_selector = document.getElementById("graph_selector");
+
+	let x = graphArray.length;
+
+	for(var i=0; i<x; i++) {
+		   var opt = document.createElement("option");
+		   opt.value= graphArray[i][1];
+		   opt.innerHTML = graphArray[i][0]; // whatever property it has
+
+		   // then append it to the select element
+		   graph_selector.add(opt);
+		}
+
+	var search_name = "";
+	var testo = "";
+
+	function results_retrieveData() {
+
+		search_name = testo;
+
+		var g = document.getElementById("graph_selector");
+		var graph = g.value;
+
+		var search_graph = "?g";
+		var gg = "?g";
+
+		if (graph != "") {
+			search_graph = '<' + graph + '>';
+			gg = "";
+		} 
+
+
+		//var query='SELECT DISTINCT ?nome WHERE {  ?autore <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> .   ?autore <http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by> ?nomeid.   ?nomeid <http://www.w3.org/2000/01/rdf-schema#label> ?nome . FILTER regex(?nome, "'+ search_name +'") }' ;
+		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/>"
+
+		queryMMO = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label (group_concat(distinct ?type ;separator=', ') as ?types) (group_concat(distinct ?id ;separator=' - ') as ?identifiers) \
+		WHERE {GRAPH "+ search_graph +" { ?subject ?property ?object } \
+		?subject rdf:type crm:E22_Man-Made_Object . \
+		OPTIONAL {?subject crm:P2_has_type ?type } \
+		OPTIONAL {?subject crm:P1_is_identified_by ?uri_id . \
+		?uri_id rdfs:label ?id . } \
+		{?subject rdfs:label ?label . \
+		?label bif:contains  \"\' "+ search_name + " \'\"  . \
+		} UNION { \
+		?subject crm:P1_is_identified_by ?uri_id ; \
+		rdfs:label ?label . \
+		?uri_id rdfs:label ?id . \
+		?id bif:contains \"\' "+ search_name + " \'\"  } \
+		} ORDER BY ?types"
+
+		queryInfObj = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?Physical_Object ?subject ?label ?id (group_concat(distinct ?type ;separator=', ') as ?types) (SAMPLE(?object_Label) AS ?text) \
+		WHERE { \
+		GRAPH "+ search_graph +" {?subject rdf:type crm:E73_Information_Object ; \
+		rdfs:label ?label .} \
+		OPTIONAL {?Physical_Object crm:P128_carries ?subject .} \
+		OPTIONAL {?subject crm:P1_is_identified_by ?id_subject . \
+		?id_subject rdfs:label ?id ; \
+		rdf:type crm:E42_Identifier . } \
+		OPTIONAL {?subject crm:P2_has_type ?entity_type . \
+		?entity_type rdfs:label ?type .} \
+		{?subject ?property ?object_Label . \
+		?object_Label bif:contains \"\' "+ search_name + " \'\" . \
+		} UNION { \
+        VALUES ?object_type {crm:E1_Entity crm:E1_CRM_Entity crm:E41_Appellation crm:E62_String} \
+		?subject ?property ?object  . \
+		?object rdfs:label ?object_Label . \
+		?object rdf:type ?object_type . \
+		?object_Label bif:contains \"\' "+ search_name + " \'\" . \
+		} \
+		FILTER NOT EXISTS { ?property rdfs:label 'label' } \
+		} ORDER BY ?id ?types"
+
+		queryPerson = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?name ?label \
+		WHERE {GRAPH "+ search_graph +" { ?subject ?property ?object } \
+		?subject rdfs:label ?label; \
+                rdf:type crm:E21_Person ; \
+                foaf:name ?name . \
+		?label bif:contains \"\' "+ search_name + " \'\" . \
+		}"
+
+		queryPlace = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label \
+		WHERE {GRAPH "+ search_graph +" { ?subject ?property ?object } \
+		{?subject rdfs:label ?label ; \
+		rdf:type crm:E53_Place ; \
+		crm:P168_place_is_defined_by ?coords . \
+		?label bif:contains \"\' "+ search_name + " \'\"  . \
+		} UNION { \
+		?subject crm:P1_is_identified_by ?toponimo . \
+		?toponimo crm:P2_has_type 'Toponimo' ; \
+		rdfs:label ?label . \
+		?label bif:contains \"\' "+ search_name + " \'\"  . \
+		} \
+		}"
+
+
+		//query = 'SELECT DISTINCT '+ search_graph +' AS ?graph ?link ?label ?entity ?object ?objLab WHERE { GRAPH '+ search_graph +' { ?link <http://www.w3.org/2000/01/rdf-schema#label> ?label ; <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> '+ search_entity +' . ?label bif:contains "\'' + search_name + '\'" .} '+ search_entity +' <http://www.w3.org/2000/01/rdf-schema#label> ?entity . FILTER (langMatches( lang(?entity), "en" )) OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?object } OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?link_object . ?link_object <http://www.w3.org/2000/01/rdf-schema#label> ?objLab }} limit 100';
+       
+		var ManMadeObject_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryMMO) + '&output=json';
+
+		var InformationObject_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryInfObj) + '&output=json';
+
+		var Persons_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryPerson) + '&output=json';
+
+		var Places_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryPlace) + '&output=json';
+
+		$.ajax({
+
+			url: ManMadeObject_url + '&callback=?',
+			dataType: "json",
+			success: function (data) {
+				MMO_handle_json(data);
+			},
+			error: function (e) {}
+		});
+
+
+		$.ajax({
+
+			url: InformationObject_url + '&callback=?',
+			dataType: "json",
+			success: function (data) {
+				InfObj_handle_json(data);
+			},
+			error: function (e) {}
+		});
+
+		$.ajax({
+
+			url: Persons_url + '&callback=?',
+			dataType: "json",
+			success: function (data) {
+				Person_handle_json(data);
+			},
+			error: function (e) {}
+		});
+
+		$.ajax({
+
+			url: Places_url + '&callback=?',
+			dataType: "json",
+			success: function (data) {
+				Place_handle_json(data);
+			},
+			error: function (e) {}
+		});
+
+	}
+
+	function rewrite_graph(graph) {
+
+		var graph_name = ""
+
+		if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/datini") {
+			graph_name = "Archivio di Stato di Prato"; 
+		}
+		else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale") {
+			graph_name = "Archivio di Stato di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi") {
+			graph_name = "Archivio di Stato di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli") {
+			graph_name = "Archivio di Stato di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/aspo/actors") {
+			graph_name = "Archivio di Stato di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/mpp/martini") {
+			graph_name = "Museo di Palazzo Pretorio di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale") {
+			graph_name = "Museo di Palazzo Pretorio di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/mpp/datini") {
+			graph_name = "Museo di Palazzo Pretorio di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/mpp/authors") {
+			graph_name = "Museo di Palazzo Pretorio di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/ovi/datini") {
+			graph_name = "Opera del Vocabolario Italiano";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/ovi/datini/trascr") {
+			graph_name = "Opera del Vocabolario Italiano";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/places") {
+			graph_name = "Luoghi";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/mpp/places") {
+			graph_name = "Museo di Palazzo Pretorio di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/label/toponimi") {
+			graph_name = "Toponimi Archivio di Stato di Prato";
+		}
+		else if (graph ==  "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica") {
+			graph_name = "Onomastica Datini";
+		}
+		else {graph_name = graph;
+		}
+
+		return graph_name;
+	}
+
+	function MMO_handle_json(json) {
+
+		console.log(json); 
+
+		$('#wb_Shape1').text("");
+		$('#wb_Image1').text("");
+		$('#Man-Made_Object').text("");
+		$(".results").css("display", "block");
+		$('#n_mmo').text("");
+
+		var i = 0;
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var object = ""; /*Inserisci VALUE TIPOLOGIA*/
+
+				var graph = value['graph']['value'];
+				var graph_name = rewrite_graph(graph);
+				var mmoType = "";
+				var mmoId = "";
+				var object_button = "";
+
+				if (value.hasOwnProperty('types')) {
+						mmoType = value['types']['value'];
+					}
+
+				if (value.hasOwnProperty('identifiers')) {
+						mmoId = value['identifiers']['value'];
+					}
+				
+				if (mmoType.includes("Opera d'Arte")) {
+					object_button  += '<button type="button" id="' + value['subject']['value'] + 
+					'" class="artwork btn btn-default" alt="opera d\'arte" title="' + value['label']['value'] + 
+					'"><i class="fas fa-paint-brush"></i><p class="btn-text">Scheda Opera d\'Arte</p></button>';
+				} else {
+					object_button  += '<button type="button" id="' + value['subject']['value'] + 
+					'" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] + 
+					'"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
+				}
+
+				object += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
+				'<a href=' + value['subject']['value'] + ' target="_blank">' + value['label']['value'] + '</a><br />' +
+				'<i>' + mmoType + ' ' + mmoId + '</i></div>' +
+				'<div class="col">' + object_button + '</div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
+				/*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
+				/*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>'; 
+
+				i++;
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#Man-Made_Object').append(object);
+
+			});
+
+		$('#n_mmo').append(i);
+
+		if (i==0) {
+			var message = '<p>Nessun Oggetto Fisico trovato</p>';
+			$('#Man-Made_Object').append(message);
+		}
+
+	}
+
+	function InfObj_handle_json(json) {
+
+		console.log(json); 
+
+		$('#Information_Object').text("");
+		$('#n_io').text("");
+
+		var i = 0;
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var information = ""; /*Inserisci VALUE TIPOLOGIA*/
+
+				var graph = value['graph']['value'];
+				var graph_name = rewrite_graph(graph);
+
+				var tipo = "";
+				var id = "";
+				var infObject_button = "";
+
+				var myString = value['text']['value'];
+				var str = myString.replace(/<[^>]*>?/gm, '');
+				let string_text = str.toLowerCase();
+				let string_len = str.length;
+				var word = testo;
+				let ind = string_text.indexOf(word);
+				let length = word.length;
+				var wl = ind + length;
+				/*var start = 0;
+				var end = 0
+
+				var bb = pp - 50;
+				var ee = pp + length + 150;*/
+
+				var pp = ind;
+				before = str.substring(0, ind);
+				after = str.substring(wl, string_len);
+
+				let bb = before.lastIndexOf(".");
+				let point = bb + pp;
+				let ee = str.indexOf(".", point);
+				
+				console.log(bb, ee);
+				
+				if (bb < 0) {
+					start = 0;
+				} else {
+					start = bb+1;
+				}
+
+				if (ee < 0) {
+					end = string_len;
+				} else {
+					end = ee;
+				}
+
+				console.log(start, bb, end, ee);
+				
+
+				/*if (bb<=0) {
+						start = 0;
+				} else {
+						start = bb;
+				}
+
+
+				if (ee>=string_len) {
+						end = string_len;
+				} else {
+						end = ee;
+				}*/
+
+				first_chunk = str.substring(start, ind);
+				highlight = str.substring(ind, wl);
+				second_chunk = str.substring(wl, end);
+
+				var snippet = first_chunk + "<span class='sharp'>" + highlight + "</span>" + second_chunk ;
+
+				console.log(snippet);
+
+				if (value.hasOwnProperty('types')) {
+						tipo = value['types']['value'];
+					}
+
+				if (value.hasOwnProperty('id')) {
+						id = " (" + value['id']['value'] + ")";
+					}
+				
+				if (tipo.includes("lettera")) {
+					infObject_button  += '<button type="button" id="' + value['subject']['value'] + 
+					'" class="lettera btn btn-default" alt="lettera" title="' + value['label']['value'] + 
+					'"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
+				} else {
+					infObject_button  += '<button type="button" id="' + value['Physical_Object']['value'] + 
+					'" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] + 
+					'"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
+				}
+
+
+				information += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>'+ snippet+'</p>' + 
+				'In: ' + graph_name + ';<br />' +
+				'<a href=' + value['subject']['value'] + ' target="_blank">' + value['label']['value'] + id + 
+				'</a>;<br /><i>' + tipo + '</i><br /></div>' + 
+				'<div class="col">' + infObject_button + '</div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
+				/*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
+				/*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>'; 
+
+				i++;
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#Information_Object').append(information);
+
+			});
+
+		$('#n_io').append(i);
+
+		if (i==0) {
+			var message = '<p>Nessun Oggetto Informativo trovato</p>';
+			$('#Information_Object').append(message);
+		}
+
+	}
+
+	function Person_handle_json(json) {
+
+		console.log(json); 
+
+		$('#Person').text("");
+		$('#n_ps').text("");
+		
+		var i = 0;
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var person = ""; /*Inserisci VALUE TIPOLOGIA*/
+				var graph = value['graph']['value'];
+				var graph_name = rewrite_graph(graph);
+
+				person += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
+				'<a href=' + value['subject']['value'] + ' target="_blank">' + value['name']['value'] + '</a></div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="persona btn btn-default" alt="persona" title="' + 
+				value['name']['value'] + '"><i class="fa fa-user"></i><p class="btn-text">Scheda Persona</p></button></div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
+				/*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
+				/*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>'; 
+
+				i++;
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#Person').append(person);
+
+			});
+
+		$('#n_ps').append(i);
+
+		if (i==0) {
+			var message = '<p>Nessuna Persona trovata</p>';
+			$('#Person').append(message);
+		}
+
+	}
+
+	function Place_handle_json(json) {
+
+		console.log(json); 
+
+		$('#Place').text("");
+		$('#n_pl').text("");
+		
+		var i = 0;
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var place = ""; /*Inserisci VALUE TIPOLOGIA*/
+				var graph = value['graph']['value'];
+				var graph_name = rewrite_graph(graph);
+
+				place += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
+				'<a href=' + value['subject']['value'] + ' target="_blank">' + value['label']['value'] + '</a></div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="luogo btn btn-default" alt="luogo" title="' + 
+				value['label']['value'] + '"><i class="fa fa-map"></i><p class="btn-text">Scheda Luogo</p></button></div>' +
+				'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
+				/*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
+				/*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>'; 
+
+				i++;
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#Place').append(place);
+
+			});
+
+		$('#n_pl').append(i);
+
+		if (i==0) {
+			var message = '<p>Nessun Luogo trovato</p>';
+			$('#Place').append(message);
+		}
+
+	}
+
+	$('#ClipArt1').click(function () {
+		testo = $('input#TextArea1').val();
+		results_retrieveData();
+		search_name = "";
+	});
+  
+    $('input#TextArea1').keypress(function(e) {
+      var key = e.which;
+      if (key == 13) // the enter key code
+          {
+            $('#ClipArt1').click();
+            return false;
+          }
+    });
+
+	//onlick hyperlink button
+
+	$(document).on("click", ".hyp", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		$("#myModal").empty();
+		$("#myModal").css("display", "block");
+		$('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
+			link + "</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
+
+		
+
+	});
+
+	$(document).on("click", ".lettera", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		window.open("lettera.html?link="+this.id);
+		
+
+	});
+
+	$(document).on("click", ".object", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		window.open("object.html?link="+this.id);
+		
+
+	});
+
+	$(document).on("click", ".artwork", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		window.open("OA.html?link="+this.id);
+		
+
+	});
+
+	$(document).on("click", ".persona", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		window.open("Persona.html?link="+this.id);
+		
+
+	});
+
+	$(document).on("click", ".luogo", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		window.open("Luogo.html?link="+this.id);
+		
+
+	});
+
+	$(document).on("click", ".close", function (ev) {
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		$("#myModal").css("display", "none");
+
+	});
+
+	$(document).on("click", ".back", function (ev) {
+
+		$("#myTab").css("display", "none");
+
+	});
+
+	$(document).on("click", ".cit", function (ev) {
+		
+		var author ="RESTORE. smart access to digital heritage and memory"
+
+		var year = new Date().getFullYear()
+
+		var today = new Date();
+		var dd = String(today.getDate()).padStart(2, '0');
+		var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
+		var yyyy = today.getFullYear();
+
+		today = dd + '/' + mm + '/' + yyyy;
+
+		var link = this.id;
+		//alert(nome_autore);
+		//$('#myModal').text("");
+		$("#myModal").empty();
+		$("#myModal").css("display", "block");
+		$('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" + 
+			author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
+
+		
+
+	});
+
+	$(document).on("click", ".scheda", function (ev) {
+
+		var link = this.id;
+		var title = this.title;
+
+		//alert(nome_autore);
+		$("#myTab").empty();
+		$("#myTab").css("display", "block");
+		$('#myTab').append("<div class='tab-content'><span class='back'>&lt; Indietro</span><br /><h2><a href='" + link + "' target='_blank'>" + title + "</a></h2><div id='tab_container'><h3>Relazioni dirette</h3><br /><table id='info_link' class='table table-hover'></table><br /><table id='info_ico' class='table table-hover'></table><br /><h3>Relazioni inverse</h3><br /><table id='info_obj' class='table table-hover'></table></div></div>");
+
+		/*var query_a = 'SELECT DISTINCT ?label WHERE { {<' + link +
+		 '> ?p ?object. OPTIONAL {?object ?property ?label . FILTER(?property = <http://www.w3.org/2004/02/skos/core#prefLabel> || ?property = <http://www.w3.org/2000/01/rdf-schema#label>) FILTER (langMatches( lang(?label), "en" )) } } UNION {<'+ link +
+		 '> ?p ?object. OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel .?object <http://www.w3.org/2000/01/rdf-schema#label> ?label } FILTER (?p != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>) FILTER (langMatches( lang(?propertyLabel), "en" ))  }}';
+		*/
+		var query_a = 'SELECT DISTINCT ?propLab ?object ?label WHERE {{<' + link + 
+		'> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.cidoc-crm.org/cidoc-crm/P62_depicts>) FILTER (langMatches( lang(?propLab), "en" ))} UNION {<' + link + 
+		'> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.w3.org/2000/01/rdf-schema#label>) FILTER(!regex(?property, "cidoc"))}}';
+		var object_url_a = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_a) + '&output=json';
+
+		var query_b = 'SELECT DISTINCT ?subject ?label ?property ?propertyLabel WHERE {?subject ?property <' + link + 
+		'> ; <http://www.w3.org/2000/01/rdf-schema#label> ?label . ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel . FILTER (langMatches( lang(?propertyLabel), "en" ))}';
+		var object_url_b = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_b) + '&output=json';
+
+		var query_c = 'SELECT DISTINCT ?object ?label WHERE {{<' + link + '> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2000/01/rdf-schema#label> ?label .} UNION {<' + link + 
+		'> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . FILTER (langMatches(lang(?label), "it" )) }}';
+		var object_url_c = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_c) + '&output=json';
+
+
+		$.ajax({//SOGGETTO
+
+			url: object_url_a + '&callback=?',
+			dataType: "json",
+			success: function (data_a) {
+				object_info_a(data_a);
+			},
+			error: function (e) {}
+		});
+
+		$.ajax({//OGGETTO
+
+			url: object_url_b + '&callback=?',
+			dataType: "json",
+			success: function (data_b) {
+				object_info_b(data_b);
+			},
+			error: function (e) {}
+		});
+
+		$.ajax({//ICONCLASS
+
+			url: object_url_c + '&callback=?',
+			dataType: "json",
+			success: function (data_c) {
+				object_info_c(data_c);
+			},
+			error: function (e) {}
+		});
+		
+	});
+
+	function object_info_a(json) {
+
+		console.log(json); 
+
+		var j = 0;
+
+		$('#info_link').text("");
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+				var autore_a = "";
+				var object = "";
+				var object_type = value['object']['type'];
+				if (object_type == "typed-literal" || object_type == "literal"){
+					object = '<td>'+ value['object']['value'] + '</td>';
+				}
+				else{
+					object = '<td style="width:60%;"><a href="'+ value['object']['value'] +'" target="_blank">'+ value['label']['value'] +'</a></td><td>' +
+					'<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
+					'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td>';
+				}
+
+				autore_a += /*INIZIO DIV*/ '<tr><td style="width:25%;">' + value['propLab']['value'] + '</td>' + object + '</tr>';/*FINE DIV*/ 
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+				j++;
+
+				$('#info_link').append(autore_a);
+
+			});
+
+		if (j==0) {
+			var message_a = '<tr id="error"><td><p>Non sono presenti relazioni dirette per questa risorsa</p></td></tr>';
+			$('#info_link').append(message_a);
+		}
+
+	}
+	
+	function object_info_b(json) {
+
+		console.log(json); 
+
+		var k = 0;
+
+		$('#info_obj').text("");
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+
+				var autore_b = "";
+
+				autore_b += /*INIZIO DIV*/ '<tr><td style="width:60%;"><a href="' + value['subject']['value'] + '" target="_blank">' + value['label']['value'] + '</a></td><td style="width:25%;">' + value['propertyLabel']['value'] + '</td><td>' + 
+				'<button type="button" id="' + value['subject']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
+				'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
+				/*FINE DIV*/ 
+
+				k++;
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#info_obj').append(autore_b);
+
+			});
+
+		if (k==0) {
+			var message_b = '<tr id="error"><td><p>Non sono presenti relazioni inverse per questa risorsa</p></td></tr>';
+			$('#info_obj').append(message_b);
+		}
+
+	}
+
+	function object_info_c(json) {
+
+		console.log(json); 
+
+		$('#info_ico').text("");
+
+		$.each(
+			json['results']['bindings'],
+			function (index, value) {
+
+				var autore_c = "";
+
+				autore_c += /*INIZIO DIV*/ '<tr><td style="width:25%;">depicts</td><td style="width:60%;"><a href="' + value['object']['value'] + '">' + value['label']['value'] + '</a></td><td>' + 
+				'<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
+				'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
+				/*FINE DIV*/ 
+
+				/*onclick=copy__Text("' + value['link']['value'] + '")*/
+
+				$('#info_ico').append(autore_c);
+
+			});
+
+	}
+
+	//VISUALIZZAZIONI DATI DELL'AUTORE
+	
+
+	//FUNZIONE LETTURA LUNGHEZZA FILE JSON
+	/*
+	function objLength(obj){
+		var i=0;
+		for (var x in obj){
+		if(obj.hasOwnProperty(x)){
+		  i++;
+		}
+		} 
+		return i;
+	}
+	*/
+
+	//#######################################
+});
+
+function copyToClipboard(text) {
+    var sampleTextarea = document.createElement("textarea");
+    document.body.appendChild(sampleTextarea);
+    sampleTextarea.value = text; //save main text in it
+    sampleTextarea.select(); //select textarea contenrs
+    document.execCommand("copy");
+    document.body.removeChild(sampleTextarea);
+}
+
+function myFunction(){
+    var copy = document.getElementById("myInput");
+    copyText = copy.textContent;
+    copyToClipboard(copyText);
+
+    //copyToClipboard(copyText.value);
+}
+