137 lines
7.1 KiB
JavaScript
137 lines
7.1 KiB
JavaScript
//query
|
|
ontoSparqlQuery=`PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
PREFIX ecrm: <http://erlangen-crm.org/current/>
|
|
PREFIX hdn: <http://dantenetwork.it/data/commedia/>
|
|
PREFIX lemon: <http://lemon-model.net/lemon#>
|
|
PREFIX orl: <http://dantenetwork.it/ontology/ORL/>
|
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
|
|
PREFIX olires:<https://dantenetwork.it/ontology/OLIRes/>
|
|
|
|
|
|
SELECT (?form as ?IRIForma) (?Rappresentazione as ?Forma) (?lm as ?Lemma) (?textver as ?Verso) ?NumVerso
|
|
(?t_canto as ?Canto) (?t_cantica as ?Cantica)
|
|
|
|
|
|
WHERE {
|
|
?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 .
|
|
?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")
|
|
} ORDER BY ?Cantica ?Canto ?NumVerso
|
|
LIMIT 50`
|
|
//Togliere LIMIT in prod
|
|
|
|
function writesparqlquery(query) {
|
|
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;
|
|
var parser = new SparqlParser();
|
|
return parser.parse(ontoSparqlQuery);
|
|
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
function getStatements(){
|
|
|
|
return data21
|
|
|
|
}
|
|
|
|
function buildSQ() {
|
|
const sparqlgen = sparqljs.Generator;
|
|
const generator = new sparqlgen({orl: "http://www.w3.org/2000/01/rdf-schema#" })
|
|
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 != "") {
|
|
parsedquery.where[1].expression.args[1].value = "^" + ftxt.value + "$";
|
|
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]);
|
|
}
|
|
//alert(generator.stringify(parsedquery))
|
|
return (parsedquery)
|
|
|
|
}
|
|
|
|
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"}}
|
|
}
|
|
` |