query con condizioni multiple: in progress
This commit is contained in:
parent
0616f8af26
commit
e6e52c4243
|
@ -39,7 +39,7 @@
|
||||||
<script type="module" src="./js/browseMgr_5.1.js"></script>
|
<script type="module" src="./js/browseMgr_5.1.js"></script>
|
||||||
<script type="text/javascript" src="./js/minimap_4.3.js"></script>
|
<script type="text/javascript" src="./js/minimap_4.3.js"></script>
|
||||||
<script type="text/javascript" src="./js/partext.js"></script>
|
<script type="text/javascript" src="./js/partext.js"></script>
|
||||||
<script type="text/javascript" src="./js/utilsMgr_5.0.js"></script>
|
<script type="text/javascript" src="./js/utilsMgr_5.1.js"></script>
|
||||||
<script type="text/javascript" src="./js/citazionijson.js"></script>
|
<script type="text/javascript" src="./js/citazionijson.js"></script>
|
||||||
<script type="module" src="./js/script_5.1.js"></script>
|
<script type="module" src="./js/script_5.1.js"></script>
|
||||||
<script type="text/javascript" src="./js/sparqltemplates.js"></script>
|
<script type="text/javascript" src="./js/sparqltemplates.js"></script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { getVersiConCitazioni, queryRiferimenti, getListaRis, cleanListaRis, getFormaCntxt, getListaIdCommenti} from './dataMgr_5.0.js';
|
import { getVersiConCitazioni, queryRiferimenti, getListaRis, cleanListaRis, getFormaCntxt, getListaIdCommenti, queryRiferimentimul} from './dataMgr_5.1.js';
|
||||||
import { getJsonQuery, emptyStructCard } from './script_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'
|
||||||
|
|
||||||
|
@ -1509,7 +1509,14 @@ $(document).ready(function() {
|
||||||
else
|
else
|
||||||
unitaRicerca = jsonQuery['unitaRicerca']
|
unitaRicerca = jsonQuery['unitaRicerca']
|
||||||
if (unitaRicerca=='riferimenti'){
|
if (unitaRicerca=='riferimenti'){
|
||||||
listaRisultatiCommenti=queryRiferimenti(jsonQuery.Riferimento100, cantoDisplayed)
|
var esprLR=jsonQuery.EsprLogicaRif
|
||||||
|
if(esprLR.length && esprLR.length==1){
|
||||||
|
listaRisultatiCommenti=queryRiferimenti(jsonQuery[esprLR[0].trim()], cantoDisplayed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
listaRisultatiCommenti=queryRiferimentimul(jsonQuery, cantoDisplayed)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log("got json query, unita ricerca: " + unitaRicerca)
|
console.log("got json query, unita ricerca: " + unitaRicerca)
|
||||||
|
|
|
@ -9,7 +9,7 @@ var rif_autori = [];
|
||||||
var rif_areetematiche = [];
|
var rif_areetematiche = [];
|
||||||
var rif_fonti = [];
|
var rif_fonti = [];
|
||||||
var listaidversi = []
|
var listaidversi = []
|
||||||
var listaidcommenti=[]
|
var listaidcommenti = []
|
||||||
const cantobadgeclassBis = 'badge badge-outline-warning badge-pill'
|
const cantobadgeclassBis = 'badge badge-outline-warning badge-pill'
|
||||||
|
|
||||||
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
||||||
|
@ -99,7 +99,7 @@ export function getListaIdCommenti() {
|
||||||
}
|
}
|
||||||
export function cleanListaRis() {
|
export function cleanListaRis() {
|
||||||
listaidversi = [];
|
listaidversi = [];
|
||||||
listaidcommenti=[]
|
listaidcommenti = []
|
||||||
}
|
}
|
||||||
export function getFontiS() {
|
export function getFontiS() {
|
||||||
|
|
||||||
|
@ -147,10 +147,11 @@ export async function getVersiConCitazioni(canticapar = '', cantopar = '') {
|
||||||
return result4
|
return result4
|
||||||
|
|
||||||
}
|
}
|
||||||
export async function queryRiferimenti(filtro, cid) {
|
function getWhere(filtro) {
|
||||||
if (filtro == null) {
|
if (filtro == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var queryfi = ''
|
||||||
console.log(filtro)
|
console.log(filtro)
|
||||||
var contenuti_riferimento = {
|
var contenuti_riferimento = {
|
||||||
'personaggio': " and CPER !='' and CPER !='no'",
|
'personaggio': " and CPER !='' and CPER !='no'",
|
||||||
|
@ -161,27 +162,27 @@ export async function queryRiferimenti(filtro, cid) {
|
||||||
'stilema': " and CST !='' and CST !='no'",
|
'stilema': " and CST !='' and CST !='no'",
|
||||||
'topografia': " and CTO !='' and CTO !='no'"
|
'topografia': " and CTO !='' and CTO !='no'"
|
||||||
}
|
}
|
||||||
const tconn = await db.connect();
|
|
||||||
var tmpfiltro=''
|
var tmpfiltro = ''
|
||||||
var querytl = 'select IdRiferimento, Cantica, Canto, Verso from riferimenti'
|
|
||||||
var queryfi = ' where '
|
queryfi = ' '
|
||||||
if (filtro.Commentatore != null && filtro.Commentatore.trim() != 'all'){
|
if (filtro.Commentatore != null && filtro.Commentatore.trim() != 'all') {
|
||||||
tmpfiltro=filtro.Commentatore.trim()
|
tmpfiltro = filtro.Commentatore.trim()
|
||||||
tmpfiltro=tmpfiltro.replace("\'", "_")
|
tmpfiltro = tmpfiltro.replace("\'", "_")
|
||||||
queryfi += "Com like'" + tmpfiltro + "'"
|
queryfi += "Com like'" + tmpfiltro + "'"
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
queryfi += "Com like '%'"
|
queryfi += "Com like '%'"
|
||||||
if (filtro.Autore_Fonte != null && filtro.Autore_Fonte.trim() != 'all'){
|
if (filtro.Autore_Fonte != null && filtro.Autore_Fonte.trim() != 'all') {
|
||||||
|
|
||||||
tmpfiltro=filtro.Autore_Fonte
|
tmpfiltro = filtro.Autore_Fonte
|
||||||
tmpfiltro=tmpfiltro.replace("\'", "_")
|
tmpfiltro = tmpfiltro.replace("\'", "_")
|
||||||
//console.log(tmpfiltro)
|
//console.log(tmpfiltro)
|
||||||
queryfi += " and Aut like '" + tmpfiltro.trim()+ "'"
|
queryfi += " and Aut like '" + tmpfiltro.trim() + "'"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filtro.Fonte != null && filtro.Fonte.trim() != 'all')
|
if (filtro.Fonte != null && filtro.Fonte.trim() != 'all')
|
||||||
queryfi += " and TiFo='" + filtro.Fonte.trim() + "'"
|
queryfi += " and TiFo='" + filtro.Fonte.trim() + "'"
|
||||||
|
|
||||||
|
@ -203,28 +204,212 @@ export async function queryRiferimenti(filtro, cid) {
|
||||||
queryfi += " and Ann like '%" + filtro.Testo_Nota.trim() + "%'"
|
queryfi += " and Ann like '%" + filtro.Testo_Nota.trim() + "%'"
|
||||||
if (filtro.contesto != null) {
|
if (filtro.contesto != null) {
|
||||||
var marray = JSON.parse(filtro.contesto);
|
var marray = JSON.parse(filtro.contesto);
|
||||||
var infiltro=false
|
var infiltro = false
|
||||||
var oplog=' and ('
|
var oplog = ' and ('
|
||||||
var tfi=filtroContesto(marray[0], 'Inferno', oplog)
|
var tfi = filtroContesto(marray[0], 'Inferno', oplog)
|
||||||
queryfi+=tfi
|
queryfi += tfi
|
||||||
if (tfi.trim()!='')
|
if (tfi.trim() != '')
|
||||||
infiltro=true
|
infiltro = true
|
||||||
oplog=' or '
|
oplog = ' or '
|
||||||
tfi=''
|
tfi = ''
|
||||||
tfi=filtroContesto(marray[1], 'Purgatorio', oplog)
|
tfi = filtroContesto(marray[1], 'Purgatorio', oplog)
|
||||||
if (tfi!=''){
|
if (tfi != '') {
|
||||||
infiltro=true
|
infiltro = true
|
||||||
queryfi += tfi
|
queryfi += tfi
|
||||||
oplog=' or '
|
oplog = ' or '
|
||||||
}
|
}
|
||||||
tfi=''
|
tfi = ''
|
||||||
tfi=filtroContesto(marray[2], 'Paradiso', oplog)
|
tfi = filtroContesto(marray[2], 'Paradiso', oplog)
|
||||||
if (tfi!=''){
|
if (tfi != '') {
|
||||||
infiltro=true
|
infiltro = true
|
||||||
queryfi += tfi
|
queryfi += tfi
|
||||||
}
|
}
|
||||||
if (infiltro)
|
if (infiltro)
|
||||||
queryfi +=")"
|
queryfi += ")"
|
||||||
|
}
|
||||||
|
return (queryfi)
|
||||||
|
}
|
||||||
|
var tmpc = ''
|
||||||
|
function getWherePart(iclause, query, cls) {
|
||||||
|
console.log(cls)
|
||||||
|
for (var filt in iclause) {
|
||||||
|
if ('TERM' in iclause[filt]) {
|
||||||
|
var rifterm = iclause[filt]['TERM']
|
||||||
|
console.log(getWhere(query[rifterm]))
|
||||||
|
/*tmpc += '('+getWhere(query[rifterm])*/
|
||||||
|
console.log(parseInt(filt) + 1)
|
||||||
|
if (parseInt(filt) == 0) {
|
||||||
|
tmpc += '(' + getWhere(query[rifterm])
|
||||||
|
tmpc += ') '
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
tmpc += cls + ' (' + getWhere(query[rifterm])
|
||||||
|
tmpc += ') '
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var myop = Object.keys(iclause[filt])[0];
|
||||||
|
if (parseInt(filt) > 0)
|
||||||
|
tmpc += ' ' + cls
|
||||||
|
getWherePart(iclause[filt][myop], query, myop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//tmpc+=')'
|
||||||
|
return tmpc
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryRiferimentimul(query, cid) {
|
||||||
|
var wherecl = ' where '
|
||||||
|
var parser = peg.generate(hdnriferquerygrammar);
|
||||||
|
var test = query['EsprLogicaRif'].join(" ");
|
||||||
|
test = test.replaceAll("( ", "(")
|
||||||
|
test = test.replaceAll(" )", ")")
|
||||||
|
var rifclauses = parser.parse(test);
|
||||||
|
var jsonclauses = JSON.parse(rifclauses)
|
||||||
|
tmpc = ''
|
||||||
|
for (var cls in jsonclauses) {
|
||||||
|
wherecl += '('+getWherePart(jsonclauses[cls], query, cls)+')'
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log(wherecl)
|
||||||
|
const tconn = await db.connect();
|
||||||
|
|
||||||
|
var querytl = 'select IdRiferimento, Cantica, Canto, Verso from riferimenti'
|
||||||
|
var rs = await tconn.query(querytl + wherecl)
|
||||||
|
var result4 = rs.toArray().map((row) => row.toJSON());
|
||||||
|
|
||||||
|
await tconn.close();
|
||||||
|
var resxcantica = Object.groupBy(result4, ({ Cantica }) => Cantica);
|
||||||
|
console.log(resxcantica)
|
||||||
|
showResult(resxcantica, cid)
|
||||||
|
}
|
||||||
|
|
||||||
|
function showResult(resxcantica, cid) {
|
||||||
|
listaidversi = []
|
||||||
|
var numcid = cid.split('_')[1]
|
||||||
|
for (var cantica in resxcantica) {
|
||||||
|
var $nctags = $(' .navig-canto')
|
||||||
|
|
||||||
|
console.log(resxcantica[cantica].length)
|
||||||
|
var i = 1;
|
||||||
|
if (cantica == 'Purgatorio')
|
||||||
|
i = 2
|
||||||
|
if (cantica == 'Paradiso')
|
||||||
|
i = 3
|
||||||
|
var spanbadgecantica = $('<span />');
|
||||||
|
spanbadgecantica.attr('class', 'badge badge-warning badge-pill mx-2');
|
||||||
|
spanbadgecantica.append(resxcantica[cantica].length)
|
||||||
|
spanbadgecantica.appendTo($('#cantica' + i + '-badge'))
|
||||||
|
|
||||||
|
|
||||||
|
var tmp = resxcantica[cantica]
|
||||||
|
var resxcanto = Object.groupBy(tmp, ({ Canto }) => Canto);
|
||||||
|
for (var canto in resxcanto) {
|
||||||
|
var tmpv = resxcanto[canto]
|
||||||
|
var spanbadge = $('<span />');
|
||||||
|
spanbadge.attr('class', cantobadgeclassBis);
|
||||||
|
spanbadge.append(resxcanto[canto].length)
|
||||||
|
if (canto.startsWith('0')) {
|
||||||
|
canto = canto.replace('0', '')
|
||||||
|
}
|
||||||
|
spanbadge.appendTo($nctags.filter('[name="' + cantica + 'Canto ' + canto + '"]'))
|
||||||
|
for (const tmpvi of tmpv) {
|
||||||
|
let myveid = '#' + cantica + '_Canto_' + canto + '_' + tmpvi.Verso.split('-')[0]
|
||||||
|
//console.log(myveid)
|
||||||
|
listaidversi.push(myveid)
|
||||||
|
listaidcommenti.push(tmpvi.IdRiferimento)
|
||||||
|
if (cid.includes(cantica) && numcid == canto)
|
||||||
|
$(myveid).addClass("mark ")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
drawMinimap(cid, true)
|
||||||
|
|
||||||
|
}
|
||||||
|
/*console.log(resxcantica)*/
|
||||||
|
return listaidversi
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryRiferimenti(filtro, cid) {
|
||||||
|
if (filtro == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(filtro)
|
||||||
|
var contenuti_riferimento = {
|
||||||
|
'personaggio': " and CPER !='' and CPER !='no'",
|
||||||
|
'episodio': " and CEP !='' and CEP !='no'",
|
||||||
|
'motivo': " and CMO !='' and CMO !='no'",
|
||||||
|
'immagine': " and CIM !='' and CIM !='no'",
|
||||||
|
'teoria': " and CTE !='' and CTE !='no'",
|
||||||
|
'stilema': " and CST !='' and CST !='no'",
|
||||||
|
'topografia': " and CTO !='' and CTO !='no'"
|
||||||
|
}
|
||||||
|
const tconn = await db.connect();
|
||||||
|
var tmpfiltro = ''
|
||||||
|
var querytl = 'select IdRiferimento, Cantica, Canto, Verso from riferimenti'
|
||||||
|
var queryfi = ' where '
|
||||||
|
if (filtro.Commentatore != null && filtro.Commentatore.trim() != 'all') {
|
||||||
|
tmpfiltro = filtro.Commentatore.trim()
|
||||||
|
tmpfiltro = tmpfiltro.replace("\'", "_")
|
||||||
|
queryfi += "Com like'" + tmpfiltro + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
queryfi += "Com like '%'"
|
||||||
|
if (filtro.Autore_Fonte != null && filtro.Autore_Fonte.trim() != 'all') {
|
||||||
|
|
||||||
|
tmpfiltro = filtro.Autore_Fonte
|
||||||
|
tmpfiltro = tmpfiltro.replace("\'", "_")
|
||||||
|
//console.log(tmpfiltro)
|
||||||
|
queryfi += " and Aut like '" + tmpfiltro.trim() + "'"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filtro.Fonte != null && filtro.Fonte.trim() != 'all')
|
||||||
|
queryfi += " and TiFo='" + filtro.Fonte.trim() + "'"
|
||||||
|
|
||||||
|
if (filtro.Area_Tematica != null && filtro.Area_Tematica.trim() != 'all')
|
||||||
|
queryfi += " and CA='" + filtro.Area_Tematica.trim() + "'"
|
||||||
|
|
||||||
|
if (filtro.Tipo_Riferimento != null && filtro.Tipo_Riferimento.trim() != 'all')
|
||||||
|
queryfi += " and NaRi='" + filtro.Tipo_Riferimento.trim().toUpperCase() + "'"
|
||||||
|
if (filtro.Contenuto_Riferimento != null && filtro.Contenuto_Riferimento != 'all')
|
||||||
|
queryfi += contenuti_riferimento[filtro.Contenuto_Riferimento.trim()]
|
||||||
|
|
||||||
|
if (filtro.Rapporto_Testo_Fonte != null && filtro.Rapporto_Testo_Fonte != 'all')
|
||||||
|
queryfi += " and UPPER(RSO)=UPPER('" + filtro.Rapporto_Testo_Fonte.trim() + "')"
|
||||||
|
|
||||||
|
if (filtro.Testo_Fonte != null && filtro.Testo_Fonte.trim() != '')
|
||||||
|
queryfi += " and TF like '%" + filtro.Testo_Fonte.trim() + "%'"
|
||||||
|
|
||||||
|
if (filtro.Testo_Nota != null && filtro.Testo_Nota.trim() != '')
|
||||||
|
queryfi += " and Ann like '%" + filtro.Testo_Nota.trim() + "%'"
|
||||||
|
if (filtro.contesto != null) {
|
||||||
|
var marray = JSON.parse(filtro.contesto);
|
||||||
|
var infiltro = false
|
||||||
|
var oplog = ' and ('
|
||||||
|
var tfi = filtroContesto(marray[0], 'Inferno', oplog)
|
||||||
|
queryfi += tfi
|
||||||
|
if (tfi.trim() != '')
|
||||||
|
infiltro = true
|
||||||
|
oplog = ' or '
|
||||||
|
tfi = ''
|
||||||
|
tfi = filtroContesto(marray[1], 'Purgatorio', oplog)
|
||||||
|
if (tfi != '') {
|
||||||
|
infiltro = true
|
||||||
|
queryfi += tfi
|
||||||
|
oplog = ' or '
|
||||||
|
}
|
||||||
|
tfi = ''
|
||||||
|
tfi = filtroContesto(marray[2], 'Paradiso', oplog)
|
||||||
|
if (tfi != '') {
|
||||||
|
infiltro = true
|
||||||
|
queryfi += tfi
|
||||||
|
}
|
||||||
|
if (infiltro)
|
||||||
|
queryfi += ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = await tconn.query(querytl + queryfi)
|
var rs = await tconn.query(querytl + queryfi)
|
||||||
|
@ -310,16 +495,16 @@ function opzioniRiferimenti() {
|
||||||
function filtroContesto(marray, cantica, op) {
|
function filtroContesto(marray, cantica, op) {
|
||||||
var filtrost = ''
|
var filtrost = ''
|
||||||
if (marray.every((val, i, arr) => val === 1)) {
|
if (marray.every((val, i, arr) => val === 1)) {
|
||||||
return op+ " Cantica='"+cantica+"'"
|
return op + " Cantica='" + cantica + "'"
|
||||||
}
|
}
|
||||||
if (marray.some((val, i, arr) => val === 1)) {
|
if (marray.some((val, i, arr) => val === 1)) {
|
||||||
var tearr = marray.reduce(function(tearr, n, i) { if (n === 1) tearr.push(i); return tearr; }, []);
|
var tearr = marray.reduce(function(tearr, n, i) { if (n === 1) tearr.push(i); return tearr; }, []);
|
||||||
for (const ic in tearr) {
|
for (const ic in tearr) {
|
||||||
var canto = (tearr[ic]+1).toString()
|
var canto = (tearr[ic] + 1).toString()
|
||||||
if ((tearr[ic]+1) < 10)
|
if ((tearr[ic] + 1) < 10)
|
||||||
canto = '0' + canto
|
canto = '0' + canto
|
||||||
if (ic == 0)
|
if (ic == 0)
|
||||||
filtrost += op+" (Cantica='"+cantica+"' and (Canto='" + canto + "'"
|
filtrost += op + " (Cantica='" + cantica + "' and (Canto='" + canto + "'"
|
||||||
else
|
else
|
||||||
filtrost += " or Canto='" + canto + "'"
|
filtrost += " or Canto='" + canto + "'"
|
||||||
|
|
||||||
|
@ -329,22 +514,22 @@ function filtroContesto(marray, cantica, op) {
|
||||||
console.log(filtrost)
|
console.log(filtrost)
|
||||||
}
|
}
|
||||||
return filtrost
|
return filtrost
|
||||||
}
|
}
|
||||||
|
|
||||||
//Contesto
|
//Contesto
|
||||||
|
|
||||||
export async function getFormaCntxt(formaid, numversi = 3) {
|
export async function getFormaCntxt(formaid, numversi = 3) {
|
||||||
const tconn = await db.connect();
|
const tconn = await db.connect();
|
||||||
var querycnt = "select * from commedia where index>=((select index from commedia where Position='"+formaid+"')-25) order by index limit 50"
|
var querycnt = "select * from commedia where index>=((select index from commedia where Position='" + formaid + "')-25) order by index limit 50"
|
||||||
console.log(" "+formaid)
|
console.log(" " + formaid)
|
||||||
var rs = await tconn.query(querycnt)
|
var rs = await tconn.query(querycnt)
|
||||||
var result4 = rs.toArray().map((row) => row.toJSON());
|
var result4 = rs.toArray().map((row) => row.toJSON());
|
||||||
|
|
||||||
|
|
||||||
console.log(result4)
|
console.log(result4)
|
||||||
console.log('-----------------------------------------')
|
console.log('-----------------------------------------')
|
||||||
|
|
||||||
|
|
||||||
await tconn.close();
|
await tconn.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue