wn-ts-node
Version:
Wordnet interface library - TypeScript port
126 lines (125 loc) • 4.9 kB
JavaScript
import i from "fs/promises";
import a from "path";
import g from "better-sqlite3";
import "./legacy-Ck0fAcao.js";
import "kysely";
import "./logger-ClUC0kzz.js";
import { f as l, v as u } from "./validation-Y6A--MpB.js";
class p {
db;
constructor(e) {
this.db = new g(e);
}
async getLexicons() {
return this.db.prepare("SELECT * FROM lexicons").all();
}
async getWords(e) {
return this.db.prepare("SELECT * FROM words WHERE lexicon = ?").all(e);
}
async getSynsets(e) {
return this.db.prepare("SELECT * FROM synsets WHERE lexicon = ?").all(e);
}
async getSenses(e) {
return this.db.prepare("SELECT * FROM senses WHERE word_id = ?").all(e);
}
async getForms(e) {
return this.db.prepare("SELECT * FROM forms WHERE word_id = ?").all(e);
}
async getWordTags(e) {
return this.db.prepare("SELECT tag FROM forms WHERE word_id = ? AND tag IS NOT NULL").all(e);
}
async getFormTags(e) {
return this.db.prepare("SELECT tag FROM forms WHERE id = ? AND tag IS NOT NULL").all(e);
}
async getSenseRelations(e) {
return this.db.prepare("SELECT * FROM relations WHERE source_id = ?").all(e);
}
async getSenseExamples(e) {
return this.db.prepare("SELECT * FROM examples WHERE sense_id = ?").all(e);
}
async getSenseCounts(e) {
return [];
}
async getSyntacticBehaviours(e) {
return [];
}
async getDefinitions(e) {
return this.db.prepare("SELECT * FROM definitions WHERE synset_id = ?").all(e);
}
async getILIDefinitions(e) {
return [];
}
async getSynsetRelations(e) {
return this.db.prepare("SELECT * FROM relations WHERE source_id = ?").all(e);
}
async getSynsetExamples(e) {
return this.db.prepare("SELECT * FROM examples WHERE synset_id = ?").all(e);
}
close() {
this.db.close();
}
}
const c = {
async loadFile(s) {
return i.readFile(s, "utf-8");
},
async saveFile(s, e) {
const n = a.dirname(s);
await i.mkdir(n, { recursive: !0 }), await i.writeFile(s, e, "utf-8");
},
generateOutputPath(s) {
const e = a.basename(s, ".xml"), n = a.join(process.cwd(), "temp", "validation");
return a.join(n, `${e}-reconstructed.xml`);
}
};
Object.assign(l, c);
async function m(s, e, n = {}) {
Object.assign(l, c);
const r = new p(s);
try {
return await u(r, e, n);
} finally {
r.close();
}
}
async function S(s) {
if (s.length < 2) {
console.log("Usage: validate <database-path> <original-xml-path> [options]"), console.log(""), console.log("Options:"), console.log(" --output <path> Save reconstructed XML to specified path"), console.log(" --no-reconstruct Don't save reconstructed XML"), console.log(" --detailed-diff Show detailed differences"), console.log(" --ignore-order Ignore element order differences"), console.log(" --ignore-whitespace Ignore whitespace differences");
return;
}
const e = s[0], n = s[1], r = {};
(!e || !n) && (console.error("❌ Missing required arguments: database-path and original-xml-path"), process.exit(1));
for (let t = 2; t < s.length; t++)
switch (s[t]) {
case "--output":
const o = s[++t];
o && (r.outputPath = o);
break;
case "--no-reconstruct":
r.outputReconstructed = !1;
break;
case "--detailed-diff":
r.detailedDiff = !0;
break;
case "--ignore-order":
r.ignoreOrder = !0;
break;
case "--ignore-whitespace":
r.ignoreWhitespace = !0;
break;
}
try {
const t = await m(e, n, r);
console.log(`
=== LMF Data Integrity Validation Results ===`), console.log(`Original File: ${t.originalFile}`), t.reconstructedFile && console.log(`Reconstructed File: ${t.reconstructedFile}`), console.log(`Success: ${t.success ? "✅ PASSED" : "❌ FAILED"}`), console.log(""), console.log("Summary:"), console.log(` Total Elements: ${t.summary.totalElements}`), console.log(` Matching Elements: ${t.summary.matchingElements}`), console.log(` Missing Elements: ${t.summary.missingElements}`), console.log(` Extra Elements: ${t.summary.extraElements}`), console.log(` Attribute Mismatches: ${t.summary.attributeMismatches}`), t.differences.length > 0 && (console.log(""), console.log("Differences:"), t.differences.slice(0, 20).forEach((o, d) => {
console.log(` ${d + 1}. ${o.type}: ${o.path}`), console.log(` Details: ${o.details}`), o.original && o.reconstructed && (console.log(` Original: ${o.original}`), console.log(` Reconstructed: ${o.reconstructed}`)), console.log("");
}), t.differences.length > 20 && console.log(` ... and ${t.differences.length - 20} more differences`)), process.exit(t.success ? 0 : 1);
} catch (t) {
console.error(`❌ Validation failed: ${t}`), process.exit(1);
}
}
export {
p as NodeDatabaseAdapter,
S as runValidationCLI,
m as validateLMFDataIntegrityFromSQLite
};