From 0dbde2b4a91887b644898aecc00ac153bd918c0c Mon Sep 17 00:00:00 2001 From: cesare Date: Wed, 19 Feb 2025 17:50:55 +0100 Subject: [PATCH] query, in progress --- js/browseMgr_5.1.js | 197 +++++++++++++++++++------------------ js/sparqltemplates.js | 129 +++++++++++++++--------- js/utilsMgr_5.1.js | 114 ++++++++++++--------- yasgui/index.html | 2 +- yasgui/index_its_lida.html | 38 +++---- 5 files changed, 271 insertions(+), 209 deletions(-) diff --git a/js/browseMgr_5.1.js b/js/browseMgr_5.1.js index d85d7ab..34f8d38 100644 --- a/js/browseMgr_5.1.js +++ b/js/browseMgr_5.1.js @@ -1,9 +1,9 @@ /** * */ -import { getVersiConCitazioni, queryRiferimenti, getListaRis, cleanListaRis, getFormaCntxt, getListaIdCommenti, queryRiferimentimul} from './dataMgr_5.1.js'; +import { getVersiConCitazioni, queryRiferimenti, getListaRis, cleanListaRis, getFormaCntxt, getListaIdCommenti, queryRiferimentimul } from './dataMgr_5.1.js'; import { getJsonQuery, emptyStructCard } from './script_5.1.js'; -import {resetGraphStr} from './syntgraph_5.1.js' +import { resetGraphStr } from './syntgraph_5.1.js' export var resetResult; @@ -35,12 +35,12 @@ $(document).ready(function() { } const dialogaltri = 'diaAltri' var listaClausoleRisultatoContesti = [] - - var listaRisultatiCommenti=[] + + var listaRisultatiCommenti = [] const sparqlGenerator = sparqljs.Generator; const myEngine = new Comunica.QueryEngine(); - + //const sparqlEndpoint = "https://hdnlab1.isti.cnr.it/fuseki/commedia/query"; const sparqlEndpoint = "https://lida.dantenetwork.it/fuseki/commedia/query"; @@ -57,12 +57,12 @@ $(document).ready(function() { var loadedCanti = new Set(); const openSTag = "{" const closeSTag = "}" - + cantoDisplayed = "#InfernoCanto_1"; - + var prevCantoDisplayed = "#InfernoCanto_1"; var contextLength = 3; - + var idCitazione = "citazioneFrase"; initCitazioni(); @@ -213,7 +213,7 @@ $(document).ready(function() { var setVersicontestoExp = new Set() for (var forma of versiContestoExp) { if (!setVersicontestoExp.has(forma.verso)) { - divVersoExp = createDivVersoLI(forma.cantica+1, forma.verso, forma.canto) + divVersoExp = createDivVersoLI(forma.cantica + 1, forma.verso, forma.canto) $(reit).append(divVersoExp) setVersicontestoExp.add(forma.verso) } @@ -272,7 +272,7 @@ $(document).ready(function() { }) - + /* * Costruzione e visualizzazione del risultato in frasi. */ @@ -296,7 +296,7 @@ $(document).ready(function() { //listarisultati.sort(function(a, b){return a - b}); showFrasi(start, offset) - + if (vistaPeriodi) { loadFrasi(); } @@ -355,11 +355,11 @@ $(document).ready(function() { res.sort(function(a, b) { return a - b }); return (res) } - if (listaClausoleRisultatoContesti.length && !listarisultati.length ) { - var lim=endcont - if (listaClausoleRisultatoContesti.length<=endcont) - lim=listaClausoleRisultatoContesti.length-1 - for (let i=startcont; i<=lim; i++){ + if (listaClausoleRisultatoContesti.length && !listarisultati.length) { + var lim = endcont + if (listaClausoleRisultatoContesti.length <= endcont) + lim = listaClausoleRisultatoContesti.length - 1 + for (let i = startcont; i <= lim; i++) { res.push(listaClausoleRisultatoContesti[i]) } //res.sort(function(a, b) { puno = a[0].split('-')[3]; pdue = b[0].split('-')[3]; return parseInt(puno) - parseInt(pdue) }); @@ -389,20 +389,20 @@ $(document).ready(function() { continue; } var versiContesto = '' - var ctxpivot=0 + var ctxpivot = 0 if (!Array.isArray(risultato)) { risultato = parseInt(risultato) versiContesto = getFormaContext(risultato, contextLength); - ctxpivot=risultato + ctxpivot = risultato } - else{ + else { versiContesto = getFraseContext(risultato, contextLength); - if(versiContesto.length){ - var tmind=Math.floor(versiContesto.length/2); - ctxpivot=versiContesto[tmind]['posizione'] + if (versiContesto.length) { + var tmind = Math.floor(versiContesto.length / 2); + ctxpivot = versiContesto[tmind]['posizione'] } } - + var setVersicontesto = new Set() divVerso = '' @@ -519,7 +519,7 @@ $(document).ready(function() { //rimuove il grafo sintattico se c'è' resetGraphStr() emptyStructCard() - + $(cantoDisplayed).css("display", "none"); @@ -542,8 +542,8 @@ $(document).ready(function() { //$("#" + $(this).attr('name').replace(" ", "_")).css("display", "block"); $("#" + $(this).attr('name').replace(" ", "_")).attr('style', 'display: d-flex;') - var telive=getListaRis() - for (var tel of telive){ + var telive = getListaRis() + for (var tel of telive) { $(tel).addClass("mark ") } @@ -650,8 +650,8 @@ $(document).ready(function() { return (cantica + '_' + mcanto.split('_')[1]) }*/ - - + + function loadPeriodo(idperiodo) { @@ -853,52 +853,52 @@ $(document).ready(function() { async function initCitazioni() { //"#InfernoCanto_1" - var idcantica='1' + var idcantica = '1' var mcanto = cantoDisplayed.replace("#", '') var cantica = '' if (mcanto.startsWith('Inf')) cantica = 'Inferno' - if (mcanto.startsWith('Pur')){ + if (mcanto.startsWith('Pur')) { cantica = 'Purgatorio' - idcantica='2' + idcantica = '2' } - - if (mcanto.startsWith('Par')) { + + if (mcanto.startsWith('Par')) { cantica = 'Paradiso' - idcantica='3' + idcantica = '3' } var canto = mcanto.split('_')[1] var idCommento = "Commento_" + idcantica + "_" + canto + "_"; - var idverso=cantica+'_Canto_'+canto+'_' - var idminimap=cantica+'Canto_'+canto + var idverso = cantica + '_Canto_' + canto + '_' + var idminimap = cantica + 'Canto_' + canto /*console.log(myid)*/ if (canto.length == 1) canto = '0' + canto //commentsJson = getVersiConCitazioniJson(cantica, canto) - + /* */ - var mresult =await getVersiConCitazioni(cantica, canto) - - commentsSQL= Object.groupBy(mresult, ({ VersoCitazione }) => VersoCitazione); - - var tmpkeys=[] - - for (const ke in commentsSQL){ + var mresult = await getVersiConCitazioni(cantica, canto) + + commentsSQL = Object.groupBy(mresult, ({ VersoCitazione }) => VersoCitazione); + + var tmpkeys = [] + + for (const ke in commentsSQL) { //console.log(ke.split('-')[0]) - var t=ke.split('-')[0] + var t = ke.split('-')[0] if (tmpkeys.indexOf(t) == -1) tmpkeys.push(t) - else + else continue - var pio=$( "#"+idCommento+t) - if(pio.length) + var pio = $("#" + idCommento + t) + if (pio.length) break; - var elverso=$( "#"+idverso+t)//$("li[value='"+t+"']") + var elverso = $("#" + idverso + t)//$("li[value='"+t+"']") //console.log(elverso) - createCommentSpan(idCommento+t, elverso, commentsSQL[ke].length) + createCommentSpan(idCommento + t, elverso, commentsSQL[ke].length) } - + drawMinimap("#" + idminimap, false) //console.log (commentsSQL) } @@ -937,7 +937,7 @@ $(document).ready(function() { $("#noteCard0")[0].remove(); } var id = cid.substr(9); - id=parcid.at(-1) + id = parcid.at(-1) var collapseNote; var gruppoVersi; var versText = ""; @@ -947,11 +947,11 @@ $(document).ready(function() { var currentGroup; allGrouplKeys.sort().some(function(k) { - if (k == id || k.startsWith(id+'-')){ //~k.indexOf(id + '-')) { + if (k == id || k.startsWith(id + '-')) { //~k.indexOf(id + '-')) { //console.log('gruppo commenti '+k) console.log(commentsSQL[k].length) //gruppoVersi = k.split("_").slice(-1)[0] - gruppoVersi=k + gruppoVersi = k if (gruppoVersi.includes("-")) { versText = ", Versi " + gruppoVersi; } else { @@ -959,9 +959,9 @@ $(document).ready(function() { } currentGroup = createNoteGroup(cantica, getRoman(parcid[2]), versText, k, commentsSQL[k].length) - commentsSQL[k].forEach(function(value, i) { - currentGroup.append(createNoteEntry(value, k, i)) - }); + commentsSQL[k].forEach(function(value, i) { + currentGroup.append(createNoteEntry(value, k, i)) + }); commentArea.append(currentGroup); } $('#tab-list #vis0-tab').tab('show') @@ -993,14 +993,14 @@ $(document).ready(function() { } function createNoteEntry(comments, id, pos) { - const tmplistaidcomm=getListaIdCommenti() - var idref=comments.Id - if(tmplistaidcomm.length && tmplistaidcomm.includes(idref)){ - var noteCard = $('
'); + const tmplistaidcomm = getListaIdCommenti() + var idref = comments.Id + if (tmplistaidcomm.length && tmplistaidcomm.includes(idref)) { + var noteCard = $('
'); } else - var noteCard = $('
'); - + var noteCard = $('
'); + var collapseCardBody = $('
'); var divCampiSingoli = $('
'); //createNoteHeader(noteCard, comments, id, pos, cantica, parcid, saveVersoCitazione); @@ -1190,7 +1190,7 @@ $(document).ready(function() { function createModuleCommentatore(collapse, commento, num, id, pos) { - let tmpcomm = commento + let tmpcomm = commento let jsonCommento = JSON.parse(tmpcomm.replaceAll("'", '"').replaceAll("+", '"')); /*var minLength = (($('#displaynote').width() / ($('#Test').width() / 32)) * 2 * 1.63);*/ var divContent = $('
'); @@ -1198,9 +1198,9 @@ $(document).ready(function() { var nota = ''; var lenmod = 0 for (var el in jsonCommento) { - - var tmpcc=JSON.parse(jsonCommento[el]) - console.log(' el '+tmpcc) + + var tmpcc = JSON.parse(jsonCommento[el]) + console.log(' el ' + tmpcc) var urlCommento = tmpcc["Commento"]; var esitoCommento = tmpcc.Rapporto; @@ -1284,8 +1284,8 @@ $(document).ready(function() { var id = cid.split('_').at(-1) - for (const [keyt, value] of Object.entries(commentsSQL)) { - if (keyt == id || keyt.startsWith(id+'-')) { + for (const [keyt, value] of Object.entries(commentsSQL)) { + if (keyt == id || keyt.startsWith(id + '-')) { return true } } @@ -1301,9 +1301,9 @@ $(document).ready(function() { function numberOfCommentsJson(cid) { var cntc = 0 - var id=cid.split('_').at(-1) - for (const keyt in commentsSQL){ - if (keyt==id) { + var id = cid.split('_').at(-1) + for (const keyt in commentsSQL) { + if (keyt == id) { cntc = commentsSQL[keyt].length break } @@ -1469,20 +1469,20 @@ $(document).ready(function() { //manageMM (cantoDisplayed) //var currPage = 0; //var latestPhraseId = ""; - var telive=getListaRis() + var telive = getListaRis() for (var ve of telive) { //let idve = ve $(ve).removeClass("mark ") minim.contents().find(ve).removeClass("mark ") } - const tmplistaidcomm=getListaIdCommenti() - for (var idco of tmplistaidcomm){ + const tmplistaidcomm = getListaIdCommenti() + for (var idco of tmplistaidcomm) { //$('[name="' + cantica + 'Canto ' + k + '"]') $('[name="' + idco + '"]').removeClass('border-success ') } cleanListaRis() drawMinimap(cantoDisplayed, true) - + } /*function manageMM(name) { @@ -1507,14 +1507,14 @@ $(document).ready(function() { unitaRicerca = 'forma' else unitaRicerca = jsonQuery['unitaRicerca'] - if (unitaRicerca=='riferimento'){ - var esprLR=jsonQuery.EsprLogicaRif - if(esprLR.length && esprLR.length==1){ - listaRisultatiCommenti=queryRiferimenti(jsonQuery[esprLR[0].trim()], cantoDisplayed) + if (unitaRicerca == 'riferimento') { + var esprLR = jsonQuery.EsprLogicaRif + if (esprLR.length && esprLR.length == 1) { + listaRisultatiCommenti = queryRiferimenti(jsonQuery[esprLR[0].trim()], cantoDisplayed) return } - else{ - listaRisultatiCommenti=queryRiferimentimul(jsonQuery, cantoDisplayed) + else { + listaRisultatiCommenti = queryRiferimentimul(jsonQuery, cantoDisplayed) } return } @@ -1906,15 +1906,12 @@ $(document).ready(function() { //alert(query) $("#loader").fadeIn(300); - //$("#searchcomm2").prop("disabled", true); - //$("#searchcomm2").html(' Searching...'); + try { var seachbBindingsStream = await myEngine.queryBindings(query, { sources: [{ type: 'sparql', value: sparqlEndpoint },], }); } catch (err) { $("#loader").fadeOut(300); - //$("#searchcomm2").prop("disabled", false); - //$("#searchcomm2").html(' Search'); console.log(err.message); }; @@ -1927,7 +1924,7 @@ $(document).ready(function() { var cantica = 'Nessuna' var canto = 'Canto 0' //var numverso=0 - var pos=0 + var pos = 0 seachbBindingsStream.on('data', (binding) => { //cantica @@ -1981,6 +1978,16 @@ $(document).ready(function() { resultsInCantica.push(cantica); resultsInCanto.push(cantica + canto) } + + //cambiare! + for (var ip=1; ip<10; ip++){ + if (binding.has('pos'+ip)){ + var tp=binding.get('pos'+ip).value; + if (!result.has(tp)) + result.add(tp) + } + } + //cambiare! if (unitaRicerca != 'frase' && pos == -1) { unitaRicerca = 'frase' } @@ -2027,7 +2034,7 @@ $(document).ready(function() { //if (!resSent.has(fraseItems[0] + '-' + fraseItems[3])) { let tmpocc = fraseItems.slice(-1) - if (resClauses.filter(clocc => clocc == tmpocc[0]).length == 0 || tmpocc[0]=='') { + if (resClauses.filter(clocc => clocc == tmpocc[0]).length == 0 || tmpocc[0] == '') { resClauses.push(tmpocc[0]); //resSent.add(fraseItems[0] + '-' + fraseItems[3]+'-'+fraseItems[1] + '-' + fraseItems[2]); resSentence.add(fraseItems[1] + '-' + fraseItems[2]); @@ -2135,8 +2142,8 @@ $(document).ready(function() { } tempr.forEach(y => listaClausoleRisultatoContesti.push(listaClausoleRisultato.filter(x => (x.split('-')[0] == y) && x.split('-').length > 1))) - } - + } + //aggiunge badge con totale risultati accanto alle cantiche var totResultN = showBadgeInCantica(resultsInCantica) @@ -2155,18 +2162,18 @@ $(document).ready(function() { showBadgeInCanto(resultsInCanto) console.log('badge end...') - //calcolo numero dei contesti - countResultContexts() + //calcolo numero dei contesti + countResultContexts() $("#loader").fadeOut(300); // mostra lista risultati //$.manageResultList(0, showOffset); $("#cantica0").trigger("click"); - + }); //var queryExecuted = true; //$(cantoDisplayed).attr('style', 'display: d-flex;'); -/* $("#cantica0").trigger("click"); - $("#vistaFrasi").css("display", "none");*/ + /* $("#cantica0").trigger("click"); + $("#vistaFrasi").css("display", "none");*/ } catch (err) { diff --git a/js/sparqltemplates.js b/js/sparqltemplates.js index 8e80de3..16b858b 100644 --- a/js/sparqltemplates.js +++ b/js/sparqltemplates.js @@ -109,8 +109,8 @@ WHERE { }` - //Query per advanced search con obiettivo = 'Frase' - const clausetargetquery = ` +//Query per advanced search con obiettivo = 'Frase' +const clausetargetquery = ` PREFIX ecrm: PREFIX xsd: PREFIX olires: @@ -127,8 +127,8 @@ WHERE { ecrm:P148i_is_component_of ?canto. ?cl syntit:hasClauseType ?clatype; syntit:hasClauseFunction ?clafun. - ?seocc olires:occurrenceOf ?sentence; - olires:occursInRegion ?frag. + #?seocc olires:occurrenceOf ?sentence; + # olires:occursInRegion ?frag. ?claocc olires:occurrenceOf ?cl; olires:occursInRegion ?fragcl. ?fragcl olires:fragmentRegionFrom ?clfr; @@ -137,15 +137,15 @@ WHERE { ?canto ecrm:P102_has_title ?t_canto; olires:hasNumber ?num. ?cantica ecrm:P102_has_title ?t_cantica; - olires:hasStructuralComponent ?canto. - BIND(CONCAT(STR(?clafun), ';') AS ?clafunction) - BIND(STR(?clatype) AS ?clt) - FILTER (?clto > ?pos && ?clfr ?pos && ?clfr", + "args": [ + { + "termType": "Variable", + "value": "clto" + }, + { + "termType": "Variable", + "value": "pos_" + } + ] + }, + { + "type": "operation", + "operator": "<", + "args": [ + { + "termType": "Variable", + "value": "clfr" + }, + { + "termType": "Variable", + "value": "pos_" + } + ] + } + ] + } +} +` + //Query per advanced search con obiettivo = 'Periodo' const sentencetargetquery = ` PREFIX ecrm: @@ -219,13 +259,13 @@ SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?sentence ?clfr ?clto ?claf olires:hasNumber ?num. ?cantica ecrm:P102_has_title ?t_cantica; olires:hasStructuralComponent ?canto. - #BIND(concat(str(?clatype1),";", str(?clatype2)) AS ?clatype) + #BIND((str(?clatype1),";", str(?clatype2)) AS ?clatype) #BIND(COALESCE(?posgen,-1) AS ?pos) } ` -const sentencetargetstatement_posCoalesce=JSON.parse(`{ +const sentencetargetstatement_posCoalesce = JSON.parse(`{ "type": "bind", "variable": { "termType": "Variable", @@ -253,8 +293,8 @@ const sentencetargetstatement_posCoalesce=JSON.parse(`{ }`) -const sentencetarget_functionbind= -` +const sentencetarget_functionbind = + ` { "type": "bind", "variable": { @@ -269,8 +309,8 @@ const sentencetarget_functionbind= } ` -const sentencetarget_occbind= -` +const sentencetarget_occbind = + ` { "type": "bind", "variable": { @@ -285,8 +325,8 @@ const sentencetarget_occbind= } ` -const sentencetarget_posbind= -` +const sentencetarget_posbind = + ` { "type": "bind", "variable": { @@ -361,8 +401,8 @@ const sentencetarget_morphgroup = `{"type": "group", ] } ` - - const sentencetarget_morphgroup_short = `{"type": "group", + +const sentencetarget_morphgroup_short = `{"type": "group", "patterns": [{"type": "bgp", "triples": [ {"subject": {"termType": "Variable","value": "fa"}, @@ -388,31 +428,31 @@ const sentencetarget_morphgroup = `{"type": "group", ] } ` - - const sentencetarget_posVariable=`{ + +const sentencetarget_posVariable = `{ "termType": "Variable", "value": "pos" }` - -const lemma_writtenrepresentation = `{"subject": {"termType": "Variable", "value":"cf"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#writtenRep"}, "object": {"termType": "Variable", "value": "lm"}}` -const lemma_canonicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#canonicalForm"}, "object": {"termType": "Variable", "value": "cf"}}` -const lemma_lexicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#lexicalForm"}, + +const lemma_writtenrepresentation = `{"subject": {"termType": "Variable", "value":"cf"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#writtenRep"}, "object": {"termType": "Variable", "value": "lm"}}` +const lemma_canonicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#canonicalForm"}, "object": {"termType": "Variable", "value": "cf"}}` +const lemma_lexicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#lexicalForm"}, "object": {"termType": "Variable", "value": "form"}}` -const occurrenceof_form=`{"subject": {"termType": "Variable","value": "fa"}, +const occurrenceof_form = `{"subject": {"termType": "Variable","value": "fa"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, "object": {"termType": "Variable","value": "form"}}` -const clauseocc_hascomponent_formocc=`{"subject": {"termType": "Variable","value": "cloccu"}, +const clauseocc_hascomponent_formocc = `{"subject": {"termType": "Variable","value": "cloccu"}, "predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"}, - "object": {"termType": "Variable","value": "fa"}}` - -const occurrenceof_clause=`{"subject": {"termType": "Variable","value": "cloccu"}, + "object": {"termType": "Variable","value": "fa"}}` + +const occurrenceof_clause = `{"subject": {"termType": "Variable","value": "cloccu"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, "object": {"termType": "Variable","value": "cl"}}` - + //DEFAULT QUERY PER SPARQL EDITOR -const defaultEditorQuery=`# ESEMPIO: i periodi della Commedia con una frase con tipo sintattico 'Subordinata Causale' +const defaultEditorQuery = `# ESEMPIO: i periodi della Commedia con una frase con tipo sintattico 'Subordinata Causale' PREFIX ecrm: PREFIX syntit: @@ -430,5 +470,4 @@ WHERE { olires:hasStructuralComponent ?q_canto. } order by ?Cantica ?Canto` - - \ No newline at end of file + diff --git a/js/utilsMgr_5.1.js b/js/utilsMgr_5.1.js index 89b3c52..cf7a3db 100644 --- a/js/utilsMgr_5.1.js +++ b/js/utilsMgr_5.1.js @@ -150,14 +150,14 @@ function getFraseContext(fraseids, numversi = 3) { for (i = startindex; i < listaforme.length; i++) { var tmpos = listaforme[i].split('_')[2] - + if (parseInt(tmpos) == parseInt(fraseid.split('-')[2])) { pos = i; break; } } - console.log (fraseid +" - " + parseInt(fraseid.split('-')[2])+ ' - '+pos) - + console.log(fraseid + " - " + parseInt(fraseid.split('-')[2]) + ' - ' + pos) + var pos2 = pos if (fraseids.length > 1) @@ -367,8 +367,8 @@ function getStatements() { var theguiQ = '' var multipleCondSpQuery = '' var bindConcatStatement = '' -var clauseTypeBindConcatStatement='' -var clausePosCoalesceStatement='' +var clauseTypeBindConcatStatement = '' +var clausePosCoalesceStatement = '' var occBindConcatStatement = '' var posBindConcatStatement = '' @@ -377,25 +377,25 @@ var filters = [] var unionop = `{"union": {"type": "union", "patterns":[]}, "bgp": {"type": "bgp", "triples":[]}, "group": {"type": "group", "patterns":[]}}` +var idtoken = 0; function parseJsonClause(op, tokens, nowhere) { //alert(op) var idp = -1 - if (nowhere[0].type == 'filter' && nowhere[0].expression.args[0].value == 'Rappresentazione') { + + /*if (nowhere[0].type != null && nowhere[0].type == 'filter' && nowhere[0].expression.args[0].value == 'Rappresentazione') { //nowhere.splice(0, 1) nowhere.splice(0, 2) - } + }*/ if (op.trim() == 'OR') { - //nowhere.splice(1, 0, JSON.parse(unionop)['union']) nowhere.splice(0, 0, JSON.parse(unionop)['union']) + nowhere.splice(1, 0, clausePosCoalesceStatement) idp = 0 } if (op.trim() == 'AND') { - //nowhere.splice(1, 0, JSON.parse(unionop)['group']) nowhere.splice(0, 0, JSON.parse(unionop)['group']) - //idp = 1 idp = 0 } @@ -403,12 +403,12 @@ function parseJsonClause(op, tokens, nowhere) { te_op = tokens[mtoken] if ('TERM' in te_op) { cond = theguiQ[te_op['TERM']] - - multipleCondSpQuery = buildStatementClause(cond, multipleCondSpQuery, -1, nowhere[idp].patterns, mtoken) + idtoken += 1; + multipleCondSpQuery = buildStatementClause(cond, multipleCondSpQuery, -1, nowhere[idp].patterns, idtoken, op.trim()) } else - parseJsonClause(Object.keys(te_op)[0], te_op[Object.keys(te_op)[0]], nowhere.at(-1).patterns) + parseJsonClause(Object.keys(te_op)[0], te_op[Object.keys(te_op)[0]], nowhere[0].patterns) } @@ -422,20 +422,24 @@ function buildSPQuery(guiquery) { var SparqlParser = sparqljs.Parser; var spqparser = new SparqlParser(); multipleCondSpQuery = spqparser.parse(ontoSparqlQueryMultCond); - + bindConcatStatement = JSON.parse(sentencetarget_functionbind); + occBindConcatStatement = JSON.parse(sentencetarget_occbind); + posBindConcatStatement = JSON.parse(sentencetarget_posbind); + clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); + if (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { - multipleCondSpQuery = spqparser.parse(clausetargetquery); - clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); + multipleCondSpQuery = spqparser.parse(clausetargetquery); + //clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); } if (theguiQ['unitaRicerca'] == 'periodo') {//Multiple Conditions multipleCondSpQuery = spqparser.parse(sentencetargetquery); - bindConcatStatement = JSON.parse(sentencetarget_functionbind); + /*bindConcatStatement = JSON.parse(sentencetarget_functionbind); occBindConcatStatement = JSON.parse(sentencetarget_occbind); - posBindConcatStatement = JSON.parse(sentencetarget_posbind); + posBindConcatStatement = JSON.parse(sentencetarget_posbind);*/ } - + var parser = peg.generate(hdnquerygrammar); var test = guiquery['EsprLogica'].join(" "); @@ -444,21 +448,21 @@ function buildSPQuery(guiquery) { var clauses = parser.parse(test); //here get clauses var jsonclauses = JSON.parse(clauses) - + idtoken = 0 for (const ck of Object.keys(jsonclauses)) { parseJsonClause(ck, jsonclauses[ck], multipleCondSpQuery.where) + /*if (ck.trim()=='OR' && (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso')) { + multipleCondSpQuery.where.push(clausePosCoalesceStatement) + }*/ + } - if (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { + /*if (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { multipleCondSpQuery.where.push(clausePosCoalesceStatement) - /*if (posBindConcatStatement['expression']['args'].length) { - multipleCondSpQuery.where.push(posBindConcatStatement) - multipleCondSpQuery.variables.push(JSON.parse(sentencetarget_posVariable)) - //multipleCondSpQuery.where.push(sentencetargetstatement_posCoalesce) - }*/ + - } + }*/ if (theguiQ['unitaRicerca'] == 'periodo') { multipleCondSpQuery.where.push(bindConcatStatement) multipleCondSpQuery.where.push(occBindConcatStatement) @@ -474,19 +478,19 @@ function buildSPQuery(guiquery) { } //preprocess multiple conditions query -function processMultipleCond(rawquery){ - for (var pc of rawquery['EsprLogica']){ - if (pc.startsWith('Clausola')){ +function processMultipleCond(rawquery) { + for (var pc of rawquery['EsprLogica']) { + if (pc.startsWith('Clausola')) { //console.log(rawquery[pc]) - if ((rawquery[pc]['typeSyntax0'].trim() != 'all' || rawquery[pc]['functionSyntax'].trim() != 'all') && + if ((rawquery[pc]['typeSyntax0'].trim() != 'all' || rawquery[pc]['functionSyntax'].trim() != 'all') && rawquery[pc]['typeGramm0'].trim() == 'all') {//solo filtro sintattico - rawquery[pc]["TipoClausola"]="Sintattico" + rawquery[pc]["TipoClausola"] = "Sintattico" } if ((rawquery[pc]['typeSyntax0'].trim() == 'all' && rawquery[pc]['functionSyntax'].trim() == 'all') && - rawquery[pc]['typeGramm0'].trim() != 'all') {//solo filtro grammaticale - rawquery[pc]["TipoClausola"]="Grammaticale" + rawquery[pc]['typeGramm0'].trim() != 'all') {//solo filtro grammaticale + rawquery[pc]["TipoClausola"] = "Grammaticale" } - + } } return rawquery @@ -505,11 +509,11 @@ function buildSQ(stquery) { console.log(stquery) if (stquery['QueryAvanzata'] == 1 && stquery['EsprLogica'] != null && stquery['EsprLogica'].length > 1) { - var processedquery=processMultipleCond(stquery) + var processedquery = processMultipleCond(stquery) buildSPQuery(processedquery) return multipleCondSpQuery; } - var clausolaS='Clausola0' + var clausolaS = 'Clausola0' if (stquery['QueryAvanzata'] == 1 && stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) { clause = stquery['EsprLogica'] @@ -588,7 +592,7 @@ function buildSQ(stquery) { } if (stquery[clause]['queryText'].trim() != "") - clausolaS=clause + clausolaS = clause } //Simple query @@ -672,7 +676,7 @@ function getFiltroContestoJson(datiContesto) { return [] } -function buildStatementClause(clause, parsedquery, whereind, theplace, token) { +function buildStatementClause(clause, parsedquery, whereind, theplace, token, op) { // var tmpgroup = '' if (clause['TipoClausola'] == "Sintattico") { @@ -762,8 +766,9 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token) { "value": "pos`+ token + `" } ] - }` - if (theguiQ['unitaRicerca'] == 'periodo'){ + }` + + if (theguiQ['unitaRicerca'] == 'periodo') { posBindConcatStatement['expression']['args'].push(JSON.parse(tmppos)) tmppos = `{"termType": "Literal", "value": ";", @@ -775,15 +780,26 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token) { }` posBindConcatStatement['expression']['args'].push(JSON.parse(tmppos)) } - else - { - tmppos=`{ - "termType": "Variable", - "value": "pos`+ token + `" - }` - clausePosCoalesceStatement['expression']['args'].push(JSON.parse(tmppos)) + else { + tmppos = `{ + "termType": "Variable", + "value": "pos`+ token + `" + }` + if (op == 'OR') { + clausePosCoalesceStatement['expression']['args'].push(JSON.parse(tmppos)) + var orfilter=clausepos_filter.replaceAll("pos_", "pos") + if (!parsedquery['where'].includes(JSON.parse(orfilter))) + parsedquery['where'].push(JSON.parse(orfilter)) + } + else{ + parsedquery['variables'].push(JSON.parse(tmppos)) + var andfilter=clausepos_filter.replaceAll("pos_", "pos"+ token) + parsedquery['where'].push(JSON.parse(andfilter)) + } + + } - + tmpgroup = JSON.parse(tmpg) } } diff --git a/yasgui/index.html b/yasgui/index.html index 3429db6..069de78 100644 --- a/yasgui/index.html +++ b/yasgui/index.html @@ -76,7 +76,7 @@ value: defaultEditorQuery }, requestConfig : { - endpoint : "https://hdnlab1.isti.cnr.it/fuseki/commedia/query" + endpoint : "https://lida.dantenetwork.it/fuseki/commedia/query" }, copyEndpointOnNewTab : false, resizeable : true, diff --git a/yasgui/index_its_lida.html b/yasgui/index_its_lida.html index a948ae3..3d5126d 100644 --- a/yasgui/index_its_lida.html +++ b/yasgui/index_its_lida.html @@ -937,91 +937,91 @@ WHERE {
Esempi di query sulla struttura

- + 1 Versetti in cui compare una forma.

- Versetti + 2 Versetti in cui compaiono parole che iniziano con una stringa.

- Le + 3 Le parole più frequenti in un libro.

- Versetti + 4 Versetti che si ripetono più volte.

- Le + 5 Le parole che compaiono in due libri, con il numero di occorrenze.

- Le + 6 Le parole di un libro, che non compaiono in un altro libro.

Esempi di query sul 'livello linguistico'

- Cerco + 7 Cerco in un libro le forme associate ad un lemma.

- Cerco + 8 Cerco in tutta l'opera le forme associate ad un lemma.

- Cerco + 9 Cerco i verbi (lila:verb) presenti in un libro.

- I verbi più frequenti in un libro. + 10 I verbi più frequenti in un libro.

- Cerco + 11 Cerco i versetti di un libro in cui una parola in una specifica posizione abbia categoria grammaticale 'lila:verb' (query distribuita sul dataset di LiLa).

- Cerco + 12 Cerco i versetti di un libro in cui compaiano due parole consecutive che hanno rispettivamente categoria grammaticale 'lila:verb' e 'lila:noun'

- + 13 Le occorrenze delle categorie verbali (lila:POS) delle prime 4 parole dei versetti del libro 'Genesis'.

- + 14 TEST! Le occorrenze delle categorie verbali (lila:POS) nelle sequenze di 4 parole nei versetti del libro 'Genesi'.

- Cerco + 15 Cerco le forme derivate da un lemma secondo le regole definite dall'ontologia "Word Formation Latin" (WFL)

- Termini + 16 Termini con la stessa radice basati sulla proprieta lila:hasBase del lemma cercato.

- Cerca + 17 Cerca le forme associate ai lemmi appartenenti ad un SynSet della risorsa Latin WordNet pubblicata su LiLa

- Cerco + 18 Cerco i verbi (lila:Verb) presenti in un libro e per ciascun lemma visualizzo la definizione nel dizionario Lewis & Short.

- Cerco + 19 Cerco in un capitolo di un libro le forme che hanno una particolare stringa nella definizione del dizionario Lewis & Short.