//query ontoSparqlQuery=`PREFIX rdfs: PREFIX ecrm: PREFIX hdn: PREFIX lemon: PREFIX orl: PREFIX xsd: PREFIX ontolex: PREFIX 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(stquery) { //alert (stquery['EsprLogica']) 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 (stquery['EsprLogica']!='' && stquery['EsprLogica'].length==1){ clause=stquery['EsprLogica'] myquery=buildClause(stquery[clause], parsedquery) //const sparqlGenerator = sparqljs.Generator; //alert (new sparqlGenerator().stringify(myquery)) return (myquery) } if (ftxt.value.trim() != "") { if (ftxt.value.trim().slice(-1) !=='*') strval="^" +ftxt.value.trim()+ "$"; else strval=ftxt.value.trim().slice(0, -1) parsedquery.where[1].expression.args[1].value = strval; 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){ //alert (tmp.querySelector('input[name="cla1'+ename.trim()+'"]:checked').value) } } }*/ return (parsedquery) } function buildClause(clause, parsedquery){ if (clause['queryText'].trim() != "") { if (clause['queryText'].trim().slice(-1) !=='*') strval="^" +clause['queryText'].trim()+ "$"; else strval=clause['queryText'].trim().slice(0, -1) parsedquery.where[1].expression.args[1].value = strval; if (clause['lemma_forma'] == 'lemma') parsedquery.where[1].expression.args[0].value = "lm"; } else{ parsedquery.where.splice(1, 1) } if (clause['typeGramm0'] !=null && clause['typeGramm0'] != "all") parsedquery.where[0].triples.push(JSON.parse(data21)[clause['typeGramm0']]); if (clause['typeGramm0'] !=null && clause['typeGramm0'].trim() == "verbovolgare"){ sctmp=JSON.parse(sottoCategorieVerbi) sctk=Object.keys(sctmp) for (ke in sctk){ //alert (clause[sctk[ke]]) keval=clause[sctk[ke]] if (keval!=null && keval!=''){ sttmts=sctmp[sctk[ke]] subcatstat= buildsubcategoryClause(sttmts[keval]) parsedquery.where[0].triples.push(subcatstat); } } } return parsedquery } function buildsubcategoryClause(sttmnt){ subcattmplate=`{"subject": {"termType": "Variable", "value":"form"}, "predicate": {"termType":"NamedNode"}, "object": {"termType": "NamedNode"}} ` orlprefix='http://dantenetwork.it/ontology/ORL/' predicate=orlprefix+(sttmnt.split(':')[0]) obj=orlprefix+(sttmnt.split(':')[1]) subcatstatement=JSON.parse(subcattmplate) subcatstatement['predicate']['value']=predicate subcatstatement['object']['value']=obj return (subcatstatement) } 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"}} } ` sottoCategorieVerbi=`{"Diatesi": {"Attivo": "TipoDiatesiVerboVolgare:VerboVolgareAttivo", "Passivo": "TipoDiatesiVerboVolgare:VerboVolgarePassivo"}, "Transitivita": {"Intransitivo": "TipoTransitivitàVerboVolgare:VerboVolgareIntransitivo", "Transitivo": "TipoTransitivitàVerboVolgare:VerboVolgareTransitivo"}, "Genere": {"Femminile": "TipoGenereVerboVolgare:GenereFemminileVerboVolgare", "Maschile": "TipoGenereVerboVolgare:GenereMaschileVerboVolgare"}} ` 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"]}`