Browse Source

Carica file su 'js'

Alessia 2 years ago
parent
commit
f6dbc1794d
2 changed files with 374 additions and 0 deletions
  1. 170 0
      js/lettera.js
  2. 204 0
      js/lettera_query.js

+ 170 - 0
js/lettera.js

@@ -0,0 +1,170 @@
+
+// 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){
+		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){
+		console.log(pageInfo.segnatura.segnatura_OVI.value);
+		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;
+		
+	}
+}
+
+// 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";
+  });
+}

+ 204 - 0
js/lettera_query.js

@@ -0,0 +1,204 @@
+
+// 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 ; \
+crm:P4_has_time-span ?time_spanA; \
+crm:P27_moved_from ?uriLuogoPartenza; \
+crm:P01_has_domain ?uriMittente . \
+\
+?time_spanA rdfs:label ?data_partenza . \
+?uriLuogoPartenza rdfs:label ?luogo_partenza . \
+?uriMittente crm:P02_has_range ?mittente . \
+ \
+?receive rdfs:subClassOf ?mov_ev; \
+rdf:type crm:EL3_Receive_Letter ; \
+crm:P4_has_time-span ?time_spanB; \
+crm:P26_moved_to ?uriLuogoArrivo; \
+crm:P01_has_domain ?receiver . \
+ \
+?time_spanB rdfs:label ?data_arrivo . \
+?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
+?receiver crm:P02_has_range ?destinatario . \
+}"
+
+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 } \
+}"
+
+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\"}"
+
+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 \
+}"
+
+
+queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
+WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
+?description rdfs:label ?descrizione \
+}"
+
+queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
+WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
+?type rdf:type crm:E55_Type; \
+rdfs:label ?tipologia . \
+}"
+
+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'. \
+}"
+
+queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
+WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
+?title rdf:type crm:E35_Title; \
+rdfs:label ?titolo . \
+}"
+
+queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
+WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
+}"
+
+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 \
+}"
+
+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'. \
+}"
+
+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'}"