diff --git a/index_5.0.html b/index_5.0.html index 3e9126f..1da15cf 100644 --- a/index_5.0.html +++ b/index_5.0.html @@ -44,7 +44,7 @@ - + diff --git a/js/browseMgr_5.0.js b/js/browseMgr_5.0.js index c288f3d..17c6d8f 100644 --- a/js/browseMgr_5.0.js +++ b/js/browseMgr_5.0.js @@ -640,7 +640,7 @@ $(document).ready(function() { } - function getNumCurrentCantica() { + /*function getNumCurrentCantica() { var mcanto = cantoDisplayed.replace("#", '') var cantica = '' @@ -652,7 +652,7 @@ $(document).ready(function() { cantica = '3' return (cantica + '_' + mcanto.split('_')[1]) - } + }*/ @@ -762,7 +762,7 @@ $(document).ready(function() { emphResults() } function loadFrasi() { - + var stp $(cantoDisplayed).find(' .sentencetag').each(function() { $(this).attr('style', 'display: d-flex;'); }) @@ -999,7 +999,7 @@ $(document).ready(function() { const tmplistaidcomm=getListaIdCommenti() var idref=comments.Id if(tmplistaidcomm.length && tmplistaidcomm.includes(idref)){ - var noteCard = $('
'); + var noteCard = $('
'); } else var noteCard = $('
'); @@ -1474,7 +1474,7 @@ $(document).ready(function() { //var latestPhraseId = ""; var telive=getListaRis() for (var ve of telive) { - let idve = ve + //let idve = ve $(ve).removeClass("mark ") minim.contents().find(ve).removeClass("mark ") } @@ -1922,7 +1922,7 @@ $(document).ready(function() { var resultsInCanto = [] var cantica = 'Nessuna' var canto = 'Canto 0' - var numverso=0 + //var numverso=0 var pos=0 seachbBindingsStream.on('data', (binding) => { @@ -1940,10 +1940,10 @@ $(document).ready(function() { canto = 'Canto 0' //numero del verso - if (binding.has('NumeroVerso')) + /*if (binding.has('NumeroVerso')) numverso = binding.get('NumeroVerso').value; else - numverso = 0 + numverso = 0*/ //posizione del frammento if (binding.has('pos')) pos = binding.get('pos').value; diff --git a/js/dataMgr_5.0.js b/js/dataMgr_5.0.js new file mode 100644 index 0000000..7f069c2 --- /dev/null +++ b/js/dataMgr_5.0.js @@ -0,0 +1,350 @@ +import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm'; + + +//import * as arrow from 'https://cdn.skypack.dev/apache-arrow@9' + + +var rif_commentatori = []; +var rif_autori = []; +var rif_areetematiche = []; +var rif_fonti = []; +var listaidversi = [] +var listaidcommenti=[] +const cantobadgeclassBis = 'badge badge-outline-warning badge-pill' + +const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles(); + +// Select a bundle based on browser checks +const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES); + +const worker_url = URL.createObjectURL( + new Blob([`importScripts("${bundle.mainWorker}");`], { type: 'text/javascript' }) +); + +// Instantiate the asynchronus version of DuckDB-wasm +const worker = new Worker(worker_url); +const logger = new duckdb.ConsoleLogger(); +const db = new duckdb.AsyncDuckDB(logger, worker); +await db.instantiate(bundle.mainModule, bundle.pthreadWorker); +URL.revokeObjectURL(worker_url); + +console.log('datamgr init done') + + +//await db.registerFileURL('remote.parquet', 'http://localhost:8000/js/data/riferimenti_3.parquet', DuckDBDataProtocol.HTTP, false); + +/*const res = await fetch('http://localhost:8000/js/data/riferimenti_3.parquet'); + +await db.registerFileBuffer('buffer.parquet', new Uint8Array(await res.arrayBuffer()));*/ + +const conn = await db.connect(); + +await conn.query(` + CREATE TABLE riferimenti AS + SELECT * FROM "https://lida.dantenetwork.it/js/data/riferimenti_3.parquet"; + CREATE TABLE commedia AS + SELECT * FROM "https://lida.dantenetwork.it/js/data/com.parquet"; + +`); + +var table = await conn.query(` + select distinct Aut from riferimenti order by Aut COLLATE NOCASE; +`); +const result = table.toArray().map((row) => row.toJSON()); +rif_autori = result.map((x) => x['Aut']); +//console.log(rif_autori) + + +var table = await conn.query(` + select distinct Com from riferimenti; +`); +const result2 = table.toArray().map((row) => row.toJSON()); +rif_commentatori = result2.map((x) => x['Com']); + + + +var table = await conn.query(` + select distinct CA from riferimenti order by CA; +`); +const result3 = table.toArray().map((row) => row.toJSON()); + +rif_areetematiche = result3.map((x) => x['CA']); + + +var table1 = await conn.query(` + select distinct TiFo from riferimenti order by TiFo COLLATE NOCASE; +`); +const result4 = table1.toArray().map((row) => row.toJSON()); +//console.log(result4) +rif_fonti = result4.map((x) => x['TiFo']); + +//console.log(rif_fonti) +var tableP = await conn.query(` + select * from commedia limit 10; +`); +const result5 = tableP.toArray().map((row) => row.toJSON()); +console.log(result5) + +await conn.close(); + +console.log('done') + +opzioniRiferimenti() + +export function getListaRis() { + return listaidversi; +} +export function getListaIdCommenti() { + return listaidcommenti; +} +export function cleanListaRis() { + listaidversi = []; + listaidcommenti=[] +} +export function getFontiS() { + + return rif_fonti +} + +export function getAreeTematicheS() { + + return rif_areetematiche +} + +export function getAutoriFontiCitazioniS() { + + return rif_autori +} + +export function getCommentatoriS() { + + return rif_commentatori +} + +export async function getVersiConCitazioni(canticapar = '', cantopar = '') { + + //let citcantiche = ['Inferno', 'Purgatorio', 'Paradiso'] + if (canticapar == '') { + return + } + const tconn = await db.connect(); + var table = await tconn.query(` + select Ann as Annotazione, Com as Commentario, FrN as frammentoNota, AC as AutoreCitazione, + F as FonteCitazione, LF as LuogoFonteCitazione, NF as NotaFonteCitazione, + TF as TestoFonteCitazione, UF as URLFonteCitazione, NaRi as NaturaRiferimento, + RCC as RapportoCommentoCommentatoreText, RSO as RapportoSoggettoOggetto, + Aut as NomeAutoreCitazione, TiFo as TitoloFonteCitazione, Verso as VersoCitazione, CA as AreaTematica, + TiCi as TipoCitazione, CEP as CitEpisodi, CIM as CitImmagini, CTE as CitTeorie, + CMO as CitMotivi, CST as CitStilemi, CTO as CitTopografie, CPER as CitPersonaggi, IdRiferimento as Id + from riferimenti + where Cantica='${canticapar}' and Canto='${cantopar}' order by verso; + `); + + var result4 = table.toArray().map((row) => row.toJSON()); + + + await tconn.close(); + return result4 + +} +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 result4 = rs.toArray().map((row) => row.toJSON()); + + await tconn.close(); + var resxcantica = Object.groupBy(result4, ({ Cantica }) => Cantica); + + 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 = $(''); + 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 = $(''); + 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 + +} + +function opzioniRiferimenti() { + $.each(rif_commentatori, function(i, p) { + if (!!p && p.length > 2) { + $('#Commentatore100').append($('') + .val(p).html(p)); + }; + }); + $.each(rif_fonti, function(i, p) { + if (!!p && p.length > 2) { + $('#Fonte100').append($('') + .val(p).html(p)); + }; + }); + $.each(rif_autori, function(i, p) { + if (!!p && p.length > 2) { + $('#Autore_Fonte100').append($('') + .val(p).html(p)); + }; + }); + $.each(rif_areetematiche, function(i, p) { + if (!!p && p.length > 2) { + $('#Area_Tematica100').append($('') + .val(p).html(p)); + }; + }); + +}; + +function filtroContesto(marray, cantica, op) { + var filtrost = '' + if (marray.every((val, i, arr) => val === 1)) { + 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) + canto = '0' + canto + if (ic == 0) + filtrost += op+" (Cantica='"+cantica+"' and (Canto='" + canto + "'" + else + filtrost += " or Canto='" + canto + "'" + + } + if (tearr.length) + filtrost += "))" + 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 rs = await tconn.query(querycnt) + var result4 = rs.toArray().map((row) => row.toJSON()); + + + console.log(result4) + console.log('-----------------------------------------') + + + await tconn.close(); + +} diff --git a/js/script_5.0.js b/js/script_5.0.js index 7a232f0..00ea950 100644 --- a/js/script_5.0.js +++ b/js/script_5.0.js @@ -688,10 +688,10 @@ $(document).ready(function() { const condLIplaceholderText2d = 'Trascina qui almeno 2 clausole o condizioni, oppure attiva le clausole inattive'; const condLIplaceholderPart1 = '
  • '; - const listaCommentatori = getCommentatoriS(); + /*const listaCommentatori = getCommentatoriS(); const listaAutoriFontiCitazioni = getAutoriFontiCitazioniS(); const listaAreeTematiche = getAreeTematicheS(); - const listaFonti = getFontiS(); + const listaFonti = getFontiS();*/ // Variabili e costanti funzionali- var minimapScrolling = false; @@ -724,10 +724,10 @@ $(document).ready(function() { // Funzione per popolare i menu delle opzioni di ricerca riferimenti $(document).ready(function() { - setTimeout(function() { fillOpzioniRiferimenti(); }, 100); + //setTimeout(function() { fillOpzioniRiferimenti(); }, 100); }); - function fillOpzioniRiferimenti() { + /*function fillOpzioniRiferimenti() { $.each(listaCommentatori, function (i, p) { if ( !!p && p.length > 2) { $('#Commentatore100').append($('') @@ -754,7 +754,7 @@ $(document).ready(function() { }); addClaContext(100); updateClaRifListItem(100,100); - }; + }; */