LiDa_Search/js/utils.js

157 lines
7.8 KiB
JavaScript
Raw Normal View History

2021-06-01 11:22:12 +02:00
//query
2022-09-29 14:54:49 +02:00
ontoSparqlQuery=`PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
2021-06-01 11:22:12 +02:00
PREFIX ecrm: <http://erlangen-crm.org/current/>
2022-09-29 14:54:49 +02:00
PREFIX hdn: <http://dantenetwork.it/data/commedia/>
2021-06-01 11:22:12 +02:00
PREFIX lemon: <http://lemon-model.net/lemon#>
2022-09-29 14:54:49 +02:00
PREFIX orl: <http://dantenetwork.it/ontology/ORL/>
2021-06-01 11:22:12 +02:00
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
2022-09-29 14:54:49 +02:00
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires:<https://dantenetwork.it/ontology/OLIRes/>
2021-06-01 11:22:12 +02:00
2022-09-29 15:59:35 +02:00
2022-09-30 09:43:32 +02:00
SELECT (?form as ?IRIForma) (?Rappresentazione as ?Forma) (?lm as ?Lemma) (?textver as ?Verso) ?NumVerso
(?t_canto as ?Canto) (?t_cantica as ?Cantica)
2022-09-29 15:59:35 +02:00
2021-06-01 11:22:12 +02:00
WHERE {
2022-09-29 14:54:49 +02:00
?fa orl:occurrenceOf ?form;
ecrm:P148i_is_component_of ?ver .
?ver ecrm:P190_Has_Symbolic_Content ?textver;
olires:hasNumber ?NumVerso;
ecrm:P148i_is_component_of ?canto .
?canto ecrm:P102_has_title ?t_canto;
ecrm:P148i_is_component_of ?cantica .
?cantica ecrm:P102_has_title ?t_cantica .
?form ontolex:writtenRep ?Rappresentazione .
2022-09-29 15:59:35 +02:00
?lent ontolex:lexicalForm ?form;
ontolex:canonicalForm ?cf .
?cf ontolex:writtenRep ?lm .
FILTER regex(?Rappresentazione,"^farò$","i") .
#FILTER regex(?lm,"^fare$","i") .
FILTER langMatches(lang(?Rappresentazione),"it")
2022-09-30 09:43:32 +02:00
} ORDER BY ?Cantica ?Canto ?NumVerso
LIMIT 50`
//Togliere LIMIT in prod
2021-06-01 11:22:12 +02:00
2022-09-29 14:54:49 +02:00
function writesparqlquery(query) {
2021-06-01 11:22:12 +02:00
return (query);
}
// write the query in natural language
function writesearchValue(form) {
var strq='il lemma';
var strcategoria='in tutte le categorie'
if (form.oggetto.value=='forma')
strq='la forma';
if (form.categoria.value!='all')
strcategoria='nella categoria '+ form.categoria.value;
return `Cerco: ${strq} ${form.query.value}, ${form.tipo.value}, ${strcategoria}`
}
// the basic initial query is parsed
function gimmespq(){
var SparqlParser = sparqljs.Parser;
2022-09-30 09:43:32 +02:00
var parser = new SparqlParser();
2022-09-29 14:54:49 +02:00
return parser.parse(ontoSparqlQuery);
2021-06-01 11:22:12 +02:00
}
// the query is transformed according the form values
function gimmespqfromjson(form){
const sparqlgen = sparqljs.Generator;
const generator = new sparqlgen({orl: "http://www.w3.org/2000/01/rdf-schema#" })
const parsedquery=gimmespq()
if (form.categoria.value!='all')
parsedquery.where[0].triples.push(JSON.parse(data21)[form.categoria.value]);
if (form.query.value!="")
switch(form.tipo.value) {
case 'parola':
parsedquery.where[1].expression.args[1].value="^"+form.query.value+"$";
break;
case 'sottostringa':
parsedquery.where[1].expression.args[1].value=form.query.value;
break;
case 'prefisso':
parsedquery.where[1].expression.args[1].value=form.query.value;
break;
case 'suffisso':
parsedquery.where[1].expression.args[1].value=form.query.value+"$";
break;
default:
parsedquery.where[1].expression.args[1].value="^"+form.query.value+"$";
};
return generator.stringify(parsedquery);
}
2022-09-29 15:17:44 +02:00
function getStatements(){
2022-09-30 09:43:32 +02:00
2022-09-29 14:54:49 +02:00
return data21
2022-09-30 09:43:32 +02:00
}
function buildSQ(stquery) {
//const sparqlgen = sparqljs.Generator;
//const generator = new sparqlgen({orl: "http://www.w3.org/2000/01/rdf-schema#" })
2022-09-30 09:43:32 +02:00
var SparqlParser = sparqljs.Parser;
var parser = new SparqlParser();
const parsedquery =parser.parse(ontoSparqlQuery);
const lf = document.getElementById("lemma_forma");
const ftxt = document.getElementById("queryText");
if (ftxt.value.trim() != "") {
2022-09-30 10:25:52 +02:00
if (ftxt.value.trim().slice(-1) !=='*')
strval="^" +ftxt.value.trim()+ "$";
else
strval=ftxt.value.trim().slice(0, -1)
2022-09-30 10:25:52 +02:00
parsedquery.where[1].expression.args[1].value = strval;
2022-09-30 09:43:32 +02:00
if (lf.value == 'lemma')
parsedquery.where[1].expression.args[0].value = "lm";
}
else{
parsedquery.where.splice(1, 1)
}
//categorie grammaticali
mycg=document.getElementById("grammtypes1")
if (mycg !=null && mycg.value != "all"){
parsedquery.where[0].triples.push(JSON.parse(data21)[mycg.value]);
//test per sottocategorie
lst_sc=JSON.parse(sottoCategorie)[mycg.value]
for (msc in lst_sc){
ename=lst_sc[msc].split(',')[0]
esize=lst_sc[msc].split(',')[1]
tmp=document.getElementById("cla1"+ename)
if (tmp!=null && esize=='2' && tmp.querySelector('input[name="cla1'+ename.trim()+'"]:checked')!=null){
2022-09-30 12:39:43 +02:00
//alert (tmp.querySelector('input[name="cla1'+ename.trim()+'"]:checked').value)
}
2022-09-30 12:39:43 +02:00
}
2022-09-30 09:43:32 +02:00
}
2022-09-30 09:43:32 +02:00
return (parsedquery)
2022-09-29 14:54:49 +02:00
}
data21 = `{"verbovolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaVerboVolgare"}},
"sostantivovolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaSostantivoVolgare"}},
"aggettivovolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaAggettivoVolgare"}},
"avverbiovolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaAvverbioVolgare"}},
"pronomevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaPronomeVolgare"}},
"congiunzionevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/ontology/ORL/FormaCongiunzioneVolgare"}},
"articolovolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaArticoloVolgare"}},
"preposizionevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaPreposizioneVolgare"}},
"interiezionevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaInteriezioneVolgare"}},
"onomasticavolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaOnomasticaVolgare"}},
"citazionevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaCitazioneVolgare"}},
"locuzionevolgare": {"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, "object": {"termType": "NamedNode", "value": "http://dantenetwork.it/resource/ORL/FormaLocuzioneVolgare"}}
2021-06-01 11:22:12 +02:00
}
`
sottoCategorie=`{"verbovolgare": ["Diatesi,2", "Transitivita,2", "Genere,2", "Numero,2", "Pers,1", "Rifl,1", "Coniugazione,n", "Tempi,n", "Persona,n", "Funzione,n", "Declinazione,n"],
"sostantivovolgare": ["pippo,2", "pluto,2"]}`