Public
Edited
May 17, 2023
1 fork
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
4096 * 2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
client
SELECT htid, A, B, C, D FROM blobb LIMIT 10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function display(id) {
if (id === undefined) {
return null;
}
const d = await fetch(
`https://catalog.hathitrust.org/api/volumes/full/htid/${id}.json`
).then((d) => d.json());
const record = d.records[Object.keys(d.records)[0]];
return `<div style="display:flex;flex-direction:row">
<div style="min-width:64px"><img width="100%" src="https://babel.hathitrust.org/cgi/imgsrv/cover?id=${id}" /></div>
<div>
<em>${record.titles[0]}</em>. (${record.publishDates[0]}) <a href="https://babel.hathitrust.org/cgi/pt?id=${id}"><code style="smaller">${id}</code></a>
</div>
</div>`;
}
Insert cell
Insert cell
Insert cell
current
Insert cell
query = {
const query_terms = current.map((d) => `'${d}'`).join(", ");
const search_list = await client.query(
`CREATE OR REPLACE TABLE search_list AS SELECT(UNLIST([${query_terms}])) AS htid`
);
await client.query(
`CREATE OR REPLACE TABLE query AS SELECT * FROM blobb JOIN search_list USING (htid)`
);
if (searchtype === "custom") {
await client.query(
`INSERT INTO query VALUES ('custom', ${custom_text_transform.join(", ")})`
);
}
return client.query("SELECT * FROM query");
}
Insert cell
client_root = {
return DuckDBClient.of();
}
Insert cell
file_cache = ({})
Insert cell
promise_cache = ({})
Insert cell
file_cache
Insert cell
cache_update = {
const promises = [];
for (let file of files) {
if (promise_cache[file]) {
continue;
}
promise_cache[file] = true;
console.log(file);
if (file_cache[file]) continue;
const p = fetch(
`https://files.benschmidt.org/hamming/chunk_${file}.parquet`
)
.then((d) => d.arrayBuffer())
.then((buffer) => {
file_cache[file] = new Uint8Array(buffer);
});
promises.push(p);
}
return Promise.all(promises);
}
Insert cell
client = {
cache_update;
const promises = [];
for (let file of files) {
if (file_cache[file].length === 0) continue;
const registration = (await client_root.db()).registerFileBuffer(
`chunk_${file}.parquet`,
file_cache[file]
);
promises.push(registration);
}
await Promise.all(promises);
const selector = files
.map((d) => `SELECT * FROM chunk_${d}.parquet`)
.join(" UNION ALL ");

await client_root.query("DROP VIEW IF EXISTS blobb");
await client_root.query("CREATE VIEW blobb AS " + selector);
return client_root;
}
Insert cell
search_htmls = {
const v = await Promise.all(
current.map(async (d) => ({
html: await display(d),
htid: d
}))
);

if (searchtype === "custom") {
v.push({
html: `<blockquote>${full_text_input.slice(0, 350)}...</blockquote>`
});
}
return v;
}
Insert cell
htmls = {
return Promise.all(
data.map(async (d) => ({
html: await display(d.htid),
distance: d.distance,
htid: d.htid
}))
);
}
Insert cell
Insert cell
import { DuckDBClient } from "@cmudig/duckdb"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more