//query ontoSparqlQuery=`PREFIX rdfs: PREFIX ecrm: PREFIX hdn: PREFIX lemon: PREFIX orl: PREFIX xsd: PREFIX ontolex: PREFIX olires: SELECT (?form as ?IRIForma) ?Rappresentazione (?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 . FILTER regex(?Rappresentazione,"^farò$","i") . FILTER langMatches(lang(?Rappresentazione),"it") }` 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 getStatememts(){ return data21 } 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"}} } `