wn-ts-node
Version:
Wordnet interface library - TypeScript port
97 lines (96 loc) • 2.39 kB
JavaScript
import { W as g } from "./legacy-Ck0fAcao.js";
import "kysely";
import "./logger-ClUC0kzz.js";
import { h as y, m as w, s as x } from "./synset-utils-BcJkIwOn.js";
import "./config-BpXKwRL1.js";
async function q(t, e) {
const n = {};
e && (n.pos = e);
const s = await t.synsets(n), a = [];
for (const o of s)
(await y(o, t)).length === 0 && a.push(o);
return a;
}
async function v(t, e) {
const n = {};
e && (n.pos = e);
const s = await t.synsets(n), a = [];
for (const o of s)
s.some((r) => r.id !== o.id && r.relations.some(
(c) => c.type === "hypernym" && c.target === o.id
)) || a.push(o);
return a;
}
async function H(t, e) {
const n = await t.synsets({ pos: e });
if (n.length === 0) return 0;
let s = 0;
for (const a of n) {
const o = await w(a, t);
s = Math.max(s, o);
}
return s;
}
async function l(t, e, n = !1) {
const s = [];
async function a(o, i) {
const r = await y(o, e);
if (r.length === 0)
s.push([...i, o]);
else
for (const c of r)
await a(c, [...i, o]);
}
if (await a(t, []), n) {
const o = {
id: "*ROOT*",
pos: t.pos,
definitions: [],
examples: [],
relations: [],
language: t.language,
lexicon: t.lexicon,
memberIds: [],
senseIds: []
};
return s.length === 0 ? [[t, o]] : s.map((i) => [...i, o]);
}
return s;
}
async function M(t, e) {
const n = await l(t, e);
return n.length === 0 ? 0 : Math.min(...n.map((s) => s.length - 1));
}
async function O(t, e, n, s = !1) {
if (t.id === e.id) return [];
if (s) {
const a = await l(t, n, !0), o = await l(e, n, !0);
let i = null;
for (const r of a)
for (const c of o)
for (let h = 0; h < r.length; h++) {
const f = r[h];
if (!f) continue;
const u = c.findIndex((p) => p.id === f.id);
if (u !== -1) {
const p = r.slice(0, h), d = c.slice(0, u).reverse(), m = [...p, f, ...d];
(i === null || m.length < i.length) && (i = m);
}
}
if (i)
return i;
} else {
const a = await x(t, e, n);
if (a.length > 0)
return a;
}
throw new g(`No path found between synsets ${t.id} and ${e.id}`);
}
export {
l as hypernymPaths,
v as leaves,
M as minDepth,
q as roots,
H as taxonomyDepth,
O as taxonomyShortestPath
};