query sottocategorie verbale (in progress)

This commit is contained in:
cesare 2022-09-30 16:51:43 +02:00
parent 0d27fafedc
commit 73a54eb3bf
1 changed files with 83 additions and 3 deletions

View File

@ -96,13 +96,23 @@ function getStatements(){
} }
function buildSQ(stquery) { function buildSQ(stquery) {
//const sparqlgen = sparqljs.Generator; //alert (stquery['EsprLogica'])
//const generator = new sparqlgen({orl: "http://www.w3.org/2000/01/rdf-schema#" })
var SparqlParser = sparqljs.Parser; var SparqlParser = sparqljs.Parser;
var parser = new SparqlParser(); var parser = new SparqlParser();
const parsedquery =parser.parse(ontoSparqlQuery); const parsedquery =parser.parse(ontoSparqlQuery);
const lf = document.getElementById("lemma_forma"); const lf = document.getElementById("lemma_forma");
const ftxt = document.getElementById("queryText"); 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() != "") {
if (ftxt.value.trim().slice(-1) !=='*') if (ftxt.value.trim().slice(-1) !=='*')
@ -117,7 +127,9 @@ function buildSQ(stquery) {
else{ else{
parsedquery.where.splice(1, 1) parsedquery.where.splice(1, 1)
} }
//categorie grammaticali //categorie grammaticali
/*
mycg=document.getElementById("grammtypes1") mycg=document.getElementById("grammtypes1")
if (mycg !=null && mycg.value != "all"){ if (mycg !=null && mycg.value != "all"){
parsedquery.where[0].triples.push(JSON.parse(data21)[mycg.value]); parsedquery.where[0].triples.push(JSON.parse(data21)[mycg.value]);
@ -132,12 +144,74 @@ function buildSQ(stquery) {
} }
} }
} }*/
return (parsedquery) 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"}}, 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"}}, "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"}}, "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"}},
@ -152,5 +226,11 @@ data21 = `{"verbovolgare": {"subject": {"termType": "Variable", "value":"form"},
"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"}} "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"], 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"]}` "sostantivovolgare": ["pippo,2", "pluto,2"]}`