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="text/javascript" src="./js/minimap_4.3.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="module" src="./js/script_5.1.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 {resetGraphStr} from './syntgraph_5.1.js'
|
||||
|
||||
|
@ -1509,7 +1509,14 @@ $(document).ready(function() {
|
|||
else
|
||||
unitaRicerca = jsonQuery['unitaRicerca']
|
||||
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
|
||||
}
|
||||
console.log("got json query, unita ricerca: " + unitaRicerca)
|
||||
|
|
|
@ -9,7 +9,7 @@ var rif_autori = [];
|
|||
var rif_areetematiche = [];
|
||||
var rif_fonti = [];
|
||||
var listaidversi = []
|
||||
var listaidcommenti=[]
|
||||
var listaidcommenti = []
|
||||
const cantobadgeclassBis = 'badge badge-outline-warning badge-pill'
|
||||
|
||||
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
||||
|
@ -99,7 +99,7 @@ export function getListaIdCommenti() {
|
|||
}
|
||||
export function cleanListaRis() {
|
||||
listaidversi = [];
|
||||
listaidcommenti=[]
|
||||
listaidcommenti = []
|
||||
}
|
||||
export function getFontiS() {
|
||||
|
||||
|
@ -147,10 +147,11 @@ export async function getVersiConCitazioni(canticapar = '', cantopar = '') {
|
|||
return result4
|
||||
|
||||
}
|
||||
export async function queryRiferimenti(filtro, cid) {
|
||||
function getWhere(filtro) {
|
||||
if (filtro == null) {
|
||||
return
|
||||
}
|
||||
var queryfi = ''
|
||||
console.log(filtro)
|
||||
var contenuti_riferimento = {
|
||||
'personaggio': " and CPER !='' and CPER !='no'",
|
||||
|
@ -161,27 +162,27 @@ export async function queryRiferimenti(filtro, cid) {
|
|||
'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("\'", "_")
|
||||
|
||||
var tmpfiltro = ''
|
||||
|
||||
queryfi = ' '
|
||||
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("\'", "_")
|
||||
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()+ "'"
|
||||
|
||||
queryfi += " and Aut like '" + tmpfiltro.trim() + "'"
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (filtro.Fonte != null && filtro.Fonte.trim() != 'all')
|
||||
queryfi += " and TiFo='" + filtro.Fonte.trim() + "'"
|
||||
|
||||
|
@ -203,28 +204,212 @@ export async function queryRiferimenti(filtro, cid) {
|
|||
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
|
||||
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 '
|
||||
oplog = ' or '
|
||||
}
|
||||
tfi=''
|
||||
tfi=filtroContesto(marray[2], 'Paradiso', oplog)
|
||||
if (tfi!=''){
|
||||
infiltro=true
|
||||
tfi = ''
|
||||
tfi = filtroContesto(marray[2], 'Paradiso', oplog)
|
||||
if (tfi != '') {
|
||||
infiltro = true
|
||||
queryfi += tfi
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
@ -310,16 +495,16 @@ function opzioniRiferimenti() {
|
|||
function filtroContesto(marray, cantica, op) {
|
||||
var filtrost = ''
|
||||
if (marray.every((val, i, arr) => val === 1)) {
|
||||
return op+ " Cantica='"+cantica+"'"
|
||||
return op + " Cantica='" + cantica + "'"
|
||||
}
|
||||
if (marray.some((val, i, arr) => val === 1)) {
|
||||
var tearr = marray.reduce(function(tearr, n, i) { if (n === 1) tearr.push(i); return tearr; }, []);
|
||||
for (const ic in tearr) {
|
||||
var canto = (tearr[ic]+1).toString()
|
||||
if ((tearr[ic]+1) < 10)
|
||||
var canto = (tearr[ic] + 1).toString()
|
||||
if ((tearr[ic] + 1) < 10)
|
||||
canto = '0' + canto
|
||||
if (ic == 0)
|
||||
filtrost += op+" (Cantica='"+cantica+"' and (Canto='" + canto + "'"
|
||||
filtrost += op + " (Cantica='" + cantica + "' and (Canto='" + canto + "'"
|
||||
else
|
||||
filtrost += " or Canto='" + canto + "'"
|
||||
|
||||
|
@ -329,22 +514,22 @@ function filtroContesto(marray, cantica, op) {
|
|||
console.log(filtrost)
|
||||
}
|
||||
return filtrost
|
||||
}
|
||||
}
|
||||
|
||||
//Contesto
|
||||
|
||||
export async function getFormaCntxt(formaid, numversi = 3) {
|
||||
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"
|
||||
console.log(" "+formaid)
|
||||
var querycnt = "select * from commedia where index>=((select index from commedia where Position='" + formaid + "')-25) order by index limit 50"
|
||||
console.log(" " + formaid)
|
||||
var rs = await tconn.query(querycnt)
|
||||
var result4 = rs.toArray().map((row) => row.toJSON());
|
||||
|
||||
|
||||
|
||||
|
||||
console.log(result4)
|
||||
console.log('-----------------------------------------')
|
||||
|
||||
|
||||
|
||||
|
||||
await tconn.close();
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue