116 lines
3.3 KiB
JavaScript
116 lines
3.3 KiB
JavaScript
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=[];
|
|
|
|
|
|
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";
|
|
`);
|
|
|
|
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']);
|
|
|
|
/*rif_commentatori.sort((a, b) => {
|
|
var sre= (a.replace(/^\D+/g, '')-b.replace(/^\D+/g, ''))
|
|
console.log(sre)
|
|
return sre
|
|
})*/
|
|
//console.log(rif_commentatori)
|
|
|
|
|
|
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']);
|
|
//console.log(rif_areetematiche)
|
|
await conn.close();
|
|
|
|
console.log('done')
|
|
|
|
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
|
|
from riferimenti
|
|
where Cantica='${canticapar}' and Canto='${cantopar}' order by verso;
|
|
`);
|
|
|
|
var result4 = table.toArray().map((row) => row.toJSON());
|
|
|
|
|
|
await tconn.close();
|
|
return result4
|
|
|
|
}
|