modifiche query sparql e query testo

This commit is contained in:
cesare 2024-02-13 10:08:28 +01:00
parent 3fe867261d
commit 4ccb789ac9
2 changed files with 6 additions and 163 deletions

View File

@ -1437,7 +1437,7 @@ function resetFrasi(){
var resultsInCantica=[] var resultsInCantica=[]
var resultsInCanto=[] var resultsInCanto=[]
console.log('frase length '+searchwords.length) console.log('frase, l. '+searchwords.length)
if(noContext || inf.length) if(noContext || inf.length)
executeLocalSearch(searchwords, formeprima, (formeprima.length-searchwords.length), cantiche[0], inf, resultsInCantica, resultsInCanto) executeLocalSearch(searchwords, formeprima, (formeprima.length-searchwords.length), cantiche[0], inf, resultsInCantica, resultsInCanto)
if(noContext || pur.length) if(noContext || pur.length)
@ -1475,7 +1475,7 @@ function resetFrasi(){
break break
} }
for (var frind=0; frind<testo.length; frind++){ for (var frind=0; frind<testo.length; frind++){
if (testo[frind].toLowerCase()!=forme[ip+frind].split('_')[0].toLowerCase()){ if (testo[frind].toLowerCase()!=forme[ip+frind].split('_')[0].toLowerCase().replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"")){
fnd=false; fnd=false;
break break
} }

View File

@ -99,7 +99,7 @@ PREFIX olires:<https://dantenetwork.it/ontology/olires/current/>
PREFIX comm: <http://dantenetwork.it/data/commedia/> PREFIX comm: <http://dantenetwork.it/data/commedia/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/> PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?clatype ?clafunction ?clfr ?clto ?cl ?sentence ?cltext ?pos ?clocc SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?clatype ?clafunction ?clfr ?clto ?cl ?sentence ?pos ?clocc
WHERE { WHERE {
FILTER(REGEX(?Rappresentazione, "^buon$", "i")) . FILTER(REGEX(?Rappresentazione, "^buon$", "i")) .
FILTER(LANGMATCHES(LANG(?Rappresentazione), "it")) FILTER(LANGMATCHES(LANG(?Rappresentazione), "it"))
@ -407,13 +407,13 @@ function buildSQ(stquery) {
var parsedquery = parser.parse(ontoSparqlQuery); var parsedquery = parser.parse(ontoSparqlQuery);
console.log(stquery) console.log(stquery)
if (stquery['EsprLogica'] != null && stquery['EsprLogica'].length > 1) { if (stquery['QueryAvanzata'] == 1 && stquery['EsprLogica'] != null && stquery['EsprLogica'].length > 1) {
parsedquery = parser.parse(ontoSparqlQueryMultCond) parsedquery = parser.parse(ontoSparqlQueryMultCond)
buildSPQuery(stquery) buildSPQuery(stquery)
return multipleCondSpQuery; return multipleCondSpQuery;
} }
if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) { if (stquery['QueryAvanzata'] == 1 && stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) {
clause = stquery['EsprLogica'] clause = stquery['EsprLogica']
filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto'])) filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto']))
@ -462,68 +462,7 @@ function buildSQ(stquery) {
if (stquery['Clausola0']['queryText'] != "" && stquery['Clausola0']['Attiva'] == 1) { if (stquery['Clausola0']['queryText'] != "" && stquery['Clausola0']['Attiva'] == 1) {
searchtext = stquery['Clausola0']['queryText'] searchtext = stquery['Clausola0']['queryText']
let strval = searchtext let strval = searchtext
if (stquery['Clausola0']['lemma_forma'] == 'testo'){
let prefixes=new Object()
prefixes['orl']= 'https://dantenetwork.it/ontology/orl/current/'
prefixes['ontolex']= 'http://www.w3.org/ns/lemon/ontolex#'
prefixes['olires']= 'https://dantenetwork.it/ontology/olires/current/'
prefixes['xsd']='http://www.w3.org/2001/XMLSchema#'
let qry=new Object()
let variables=[]
let where=[]
let whereobject=new Object()
whereobject["type"]= "bgp"
let triples=[]
qry['queryType']='SELECT'
let testo_tkns=strval.split(' ')
var longest = testo_tkns.reduce(
function(a, b) {
return a.length > b.length ? a : b;
}
);
optind=testo_tkns.indexOf(longest)
for (tknid in testo_tkns){
if (tknid>0 && tknid==optind){
triples.unshift(getTestoWhereTriple('reg'+tknid, 'https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom', 'pos'+tknid))
triples.unshift(getTestoWhereTriple('fa'+tknid, 'https://dantenetwork.it/ontology/olires/current/OccursInRegion', 'reg'+tknid))
triples.unshift(getTestoWhereTriple('fa'+tknid, 'https://dantenetwork.it/ontology/orl/current/occurrenceOf', 'cat'+tknid))
triples.unshift(getTestoWhereTriple('cat'+tknid, 'http://www.w3.org/ns/lemon/ontolex#writtenRep', 'Rappresentazione'+tknid))
}
else{
triples.push(getTestoWhereTriple('cat'+tknid, 'http://www.w3.org/ns/lemon/ontolex#writtenRep', 'Rappresentazione'+tknid))
triples.push(getTestoWhereTriple('fa'+tknid, 'https://dantenetwork.it/ontology/orl/current/occurrenceOf', 'cat'+tknid))
triples.push(getTestoWhereTriple('fa'+tknid, 'https://dantenetwork.it/ontology/olires/current/OccursInRegion', 'reg'+tknid))
triples.push(getTestoWhereTriple('reg'+tknid, 'https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom', 'pos'+tknid))
}
where.push(getTestoWhereTextFilter('Rappresentazione'+tknid, testo_tkns[tknid]))
}
for (tknid in testo_tkns){
let variable=new Object()
variable['termType']="Variable"
variable['value']="pos"+tknid
variables.push(variable);
if (tknid==0)
continue
where.push(getTestoWherePosFilter('pos0', 'pos'+tknid, tknid))
}
//testo_tkns.sort((a,b)=> {return b.length-a.length})
whereobject["triples"]=triples
where.push(whereobject)
qry['variables']=variables
qry['where']=where
qry['type']="query"
qry['prefixes']=prefixes
const sparqlGenerator = sparqljs.Generator;
console.log(new sparqlGenerator().stringify(qry))
}
if (stquery['Clausola0']['opzioni_testo'] == 'parola') { if (stquery['Clausola0']['opzioni_testo'] == 'parola') {
strval = "^" + searchtext.trim() + "$"; strval = "^" + searchtext.trim() + "$";
} }
@ -555,102 +494,6 @@ function buildSQ(stquery) {
//Crea le triple per WHERE se cerco il testo
function getTestoWherePosFilter(pos1, pos2, dist){
let filterpos=new Object()
filterpos['type']='filter'
let filterexpr= new Object()
filterexpr['type']='operation'
filterexpr['operator']='='
let exprargs=[]
let arg1= new Object()
arg1['type']="functionCall"
let arg1func=new Object()
arg1func['termType']="NamedNode"
arg1func['value']="http://www.w3.org/2001/XMLSchema#int"
arg1['function']=arg1func
let arg1args= []
let arg1argsarg1= new Object()
arg1argsarg1['type']="operation"
arg1argsarg1['operator']="+"
let arg1argsarg1args=[]
let arg1argsarg1argsarg1=new Object()
arg1argsarg1argsarg1['termType']="Variable"
arg1argsarg1argsarg1['value']=pos1
let arg1argsarg1argsarg2=new Object()
arg1argsarg1argsarg2['termType']="Literal"
arg1argsarg1argsarg2['value']=dist
let datatype=new Object()
datatype['termType']='NamedNode'
datatype['value']="http://www.w3.org/2001/XMLSchema#integer"
arg1argsarg1argsarg2["datatype"]=datatype
arg1argsarg1args.push(arg1argsarg1argsarg1)
arg1argsarg1args.push(arg1argsarg1argsarg2)
arg1argsarg1['type']='operation'
arg1argsarg1['operator']='+'
arg1argsarg1['args']=arg1argsarg1args
arg1args.push(arg1argsarg1)
arg1['args']=arg1args
arg1['distinct']='false'
let arg2= new Object()
arg2["termType"]= "Variable",
arg2["value"]= pos2
exprargs.push(arg1)
exprargs.push(arg2)
filterexpr['args']=exprargs
filterpos['expression']=filterexpr
return filterpos
}
function getTestoWhereTextFilter(term, val){
let filtertext=new Object()
filtertext['type']='filter'
let filterexpr= new Object()
filterexpr['type']='operation'
filterexpr['operator']='regex'
let exprargs=[]
let arg1= new Object()
arg1['termType']="Variable"
arg1['value']=term
let arg2= new Object()
arg2['termType']="Literal"
arg2['value']=val
let arg3= new Object()
arg3['termType']="Literal"
arg3['value']='i'
let datatype=new Object()
datatype['termType']='NamedNode'
datatype['value']="http://www.w3.org/2001/XMLSchema#string"
arg2['datatype']=datatype
arg3['datatype']=datatype
exprargs.push(arg1)
exprargs.push(arg2)
exprargs.push(arg3)
filterexpr['args']=exprargs
filtertext['expression']=filterexpr
return filtertext
}
function getTestoWhereTriple(s, p, o){
let tri=new Object()
let sub=new Object()
let pred=new Object()
let ob=new Object()
sub["termType"]="Variable"
sub["value"]=s
pred["termType"]="NamedNode"
pred["value"]=p
ob["termType"]="Variable"
ob["value"]=o
tri["subject"]= sub
tri["predicate"]= pred
tri["object"]= ob
return (tri)
}
//Filtro Contesto //Filtro Contesto