wn-ts-node
Version:
Wordnet interface library - TypeScript port
322 lines (321 loc) • 10.4 kB
JavaScript
import { K as r } from "./index-DslY9aj0.js";
import { c as a } from "./config-BpXKwRL1.js";
class o {
kyselyWordnet;
expand;
defaultNormalizer;
defaultLemmatizer;
initialized = !1;
constructor(e = "*", t = {}) {
this.expand = Array.isArray(t.expand) ? t.expand : t.expand ? [t.expand] : [], this.defaultNormalizer = t.normalizer || this.createDefaultNormalizer(), this.defaultLemmatizer = t.lemmatizer || this.createDefaultLemmatizer();
const { strategy: s, ...i } = t;
this.kyselyWordnet = new r(e, {
filename: a.databasePath,
normalizer: this.defaultNormalizer,
strategy: s ?? "default",
...i
});
}
/**
* Initialize the database if not already initialized
*/
async ensureInitialized() {
this.initialized || (await this.kyselyWordnet.initialize(), this.initialized = !0);
}
/**
* Close the database connection
*/
async close() {
this.initialized && (await this.kyselyWordnet.close(), this.initialized = !1);
}
/**
* Create a default normalizer function
*/
createDefaultNormalizer() {
return (e) => e.toLowerCase().trim();
}
/**
* Create a default lemmatizer function
*/
createDefaultLemmatizer() {
return (e, t) => {
const s = {
n: /* @__PURE__ */ new Set(),
v: /* @__PURE__ */ new Set(),
a: /* @__PURE__ */ new Set(),
r: /* @__PURE__ */ new Set(),
s: /* @__PURE__ */ new Set(),
c: /* @__PURE__ */ new Set(),
p: /* @__PURE__ */ new Set(),
x: /* @__PURE__ */ new Set(),
u: /* @__PURE__ */ new Set(),
i: /* @__PURE__ */ new Set()
};
return t ? s[t] = /* @__PURE__ */ new Set([e]) : Object.keys(s).forEach((i) => {
s[i] = /* @__PURE__ */ new Set([e]);
}), s;
};
}
async lexicons() {
return await this.ensureInitialized(), this.kyselyWordnet.lexicons();
}
// Required WordNetCore interface method
async query(e, t) {
return await this.ensureInitialized(), console.warn("Direct SQL queries not implemented in Wordnet. Use specific methods instead."), [];
}
async synsets(e, t, s) {
if (await this.ensureInitialized(), typeof e == "string") {
const n = { form: e, pos: t, ...s };
return this.kyselyWordnet.synsets(n);
} else
return this.kyselyWordnet.synsets(e);
}
async senses(e, t, s) {
if (await this.ensureInitialized(), typeof e == "string") {
const n = {
wordIdOrForm: e,
pos: t,
lexicon: Array.isArray(s?.lexicon) ? s.lexicon[0] : s?.lexicon
};
return this.kyselyWordnet.senses(n);
} else
return this.kyselyWordnet.senses(e);
}
async words(e, t, s) {
if (await this.ensureInitialized(), typeof e == "string") {
const n = { form: e, pos: t, ...s };
return this.kyselyWordnet.words(n);
} else
return this.kyselyWordnet.words(e);
}
async getWord(e) {
return await this.ensureInitialized(), this.kyselyWordnet.words({ form: e });
}
async getSynset(e) {
return await this.ensureInitialized(), await this.kyselyWordnet.getSynset(e) || null;
}
/**
* Alias for getSynset for consistency with other methods
*/
async getSynsetById(e) {
return this.getSynset(e);
}
async getSenses(e, t, s) {
await this.ensureInitialized();
const i = Array.isArray(s?.lexicon) ? s.lexicon[0] : s?.lexicon;
return this.kyselyWordnet.senses({ wordIdOrForm: e, pos: t, lexicon: i });
}
async getRelations(e, t) {
return await this.ensureInitialized(), console.warn("getRelations not fully implemented in Wordnet class"), [];
}
async getSense(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSense(e);
}
async getIli(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getIli(e);
}
// Add the missing "OrUndefined" methods that tests expect
async getWordOrUndefined(e) {
return this.word(e).catch(() => {
});
}
async getSynsetOrUndefined(e) {
return this.synset(e).catch(() => {
});
}
async getSenseOrUndefined(e) {
return this.sense(e).catch(() => {
});
}
async getStatistics() {
return await this.ensureInitialized(), this.kyselyWordnet.getStatistics();
}
async expandedLexicons() {
return await this.ensureInitialized(), this.expand.length === 0 ? [] : this.kyselyWordnet.lexicons();
}
// Add the missing normalizer and lemmatizer methods that tests expect
async normalizeForm(e) {
return this.defaultNormalizer(e);
}
async morphy(e, t) {
return this.defaultLemmatizer(e, t);
}
async ilis(e) {
return await this.ensureInitialized(), this.kyselyWordnet.ilis(e);
}
async word(e) {
await this.ensureInitialized();
const t = await this.kyselyWordnet.getWord(e);
if (!t)
throw new Error(`Word not found: ${e}`);
return t;
}
async synset(e) {
await this.ensureInitialized();
const t = await this.kyselyWordnet.getSynset(e);
if (!t)
throw new Error(`Synset not found: ${e}`);
return t;
}
async sense(e) {
await this.ensureInitialized();
const t = await this.kyselyWordnet.getSense(e);
if (!t)
throw new Error(`Sense not found: ${e}`);
return t;
}
async ili(e) {
await this.ensureInitialized();
const t = await this.kyselyWordnet.getIli(e);
if (!t)
throw new Error(`ILI not found: ${e}`);
return t;
}
async synsetsByILI(e) {
return await this.ensureInitialized(), this.kyselyWordnet.synsetsByILI(e);
}
// Implement missing abstract methods by delegating to KyselyWordnet
async getProjects() {
return await this.ensureInitialized(), this.kyselyWordnet.getProjects();
}
async searchWords(e) {
return await this.ensureInitialized(), this.kyselyWordnet.searchWords(e);
}
async searchSynsets(e) {
return await this.ensureInitialized(), this.kyselyWordnet.searchSynsets(e);
}
async wordsByForm(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.wordsByForm(e, t);
}
async synsetsByForm(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.synsetsByForm(e, t);
}
async getWordForms(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getWordForms(e);
}
async getWordLemma(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getWordLemma(e);
}
async getDerivedWords(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getDerivedWords(e);
}
async getHypernyms(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getHypernyms(e);
}
async getHyponyms(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getHyponyms(e);
}
async getRelatedSynsets(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.getRelatedSynsets(e, t);
}
async getRelatedSenses(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.getRelatedSenses(e, t);
}
async getShortestPath(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.getShortestPath(e, t);
}
async getSynsetDepth(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSynsetDepth(e);
}
async translateWord(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.translateWord(e, t);
}
async translateSynset(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.translateSynset(e, t);
}
async translateSense(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.translateSense(e, t);
}
async getCrossLingualSynsets(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.getCrossLingualSynsets(e, t);
}
async getDefinitions(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getDefinitions(e);
}
async getExamples(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getExamples(e);
}
async getSenseExamples(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSenseExamples(e);
}
async getSynsetWords(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSynsetWords(e);
}
async getSynsetLemmas(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSynsetLemmas(e);
}
async getSynsetSenses(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getSynsetSenses(e);
}
async hasLexicon(e) {
return await this.ensureInitialized(), this.kyselyWordnet.hasLexicon(e);
}
async getSupportedLanguages() {
return await this.ensureInitialized(), this.kyselyWordnet.getSupportedLanguages();
}
async getLexiconDependencies(e) {
return await this.ensureInitialized(), this.kyselyWordnet.getLexiconDependencies(e);
}
/**
* Get words by ILI and language
*/
async getWordsByIliAndLanguage(e, t) {
return await this.ensureInitialized(), this.kyselyWordnet.getWordsByIliAndLanguage(e, t);
}
// Additional methods that may not be in KyselyWordnet but are required by BaseWordnet
async getLexiconStatistics(e) {
await this.ensureInitialized();
const t = await this.kyselyWordnet.lexicons();
return e ? t.filter((s) => s.id === e).map((s) => ({
lexiconId: s.id,
label: s.label,
language: s.language,
version: s.version || "",
wordCount: 0,
// Would need to implement actual counting
synsetCount: 0,
senseCount: 0,
iliCount: 0
})) : t.map((s) => ({
lexiconId: s.id,
label: s.label,
language: s.language,
version: s.version || "",
wordCount: 0,
synsetCount: 0,
senseCount: 0,
iliCount: 0
}));
}
async getDataQualityMetrics() {
return await this.ensureInitialized(), {
synsetsWithILI: 0,
synsetsWithoutILI: 0,
iliCoveragePercentage: 0,
emptySynsets: 0,
synsetsWithDefinitions: 0,
synsetsWithExamples: 0,
averageSynsetSize: 0
};
}
async getPartOfSpeechDistribution() {
return await this.ensureInitialized(), {};
}
async getSynsetSizeAnalysis() {
return await this.ensureInitialized(), {
averageSize: 0,
maxSize: 0,
minSize: 0,
sizeDistribution: {}
};
}
/**
* Get the query service for direct database operations
*/
async getQueryService() {
return await this.ensureInitialized(), this.kyselyWordnet.getQueryService();
}
}
export {
o as Wordnet
};