wn-ts-node
Version:
Wordnet interface library - TypeScript port
494 lines (461 loc) • 16.7 kB
TypeScript
import { KyselyQueryService } from './index.js';
import { z } from 'zod';
declare type Definition = z.infer<typeof DefinitionSchema>;
declare const DefinitionSchema: z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
/**
* Find all hypernym paths for a synset.
*
* @param synset - The synset to find paths for
* @param wordnet - The Wordnet instance
* @returns Array of hypernym paths
*/
export declare function hypernymPaths(synset: Synset, wordnet: Wordnet, simulateRoot?: boolean): Promise<Synset[][]>;
declare type ILI = z.infer<typeof ILISchema>;
declare const ILISchema: z.ZodObject<{
id: z.ZodString;
definition: z.ZodOptional<z.ZodString>;
status: z.ZodEnum<{
standard: "standard";
proposed: "proposed";
deprecated: "deprecated";
}>;
supersededBy: z.ZodOptional<z.ZodString>;
note: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
/**
* Find leaf synsets in a Wordnet.
*
* @param wordnet - The Wordnet instance
* @param pos - Optional part of speech filter
* @returns Array of leaf synsets
*/
export declare function leaves(wordnet: Wordnet, pos?: PartOfSpeech): Promise<Synset[]>;
declare type Lexicon = z.infer<typeof LexiconSchema>;
declare const LexiconSchema: z.ZodObject<{
id: z.ZodString;
label: z.ZodString;
language: z.ZodString;
email: z.ZodOptional<z.ZodString>;
license: z.ZodOptional<z.ZodString>;
version: z.ZodOptional<z.ZodString>;
url: z.ZodOptional<z.ZodString>;
citation: z.ZodOptional<z.ZodString>;
logo: z.ZodOptional<z.ZodString>;
requires: z.ZodOptional<z.ZodArray<z.ZodString>>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, z.core.$strip>;
/**
* Calculate the minimum depth of a synset.
*
* @param synset - The synset to calculate depth for
* @param wordnet - The Wordnet instance
* @returns The minimum depth
*/
export declare function minDepth(synset: Synset, wordnet: Wordnet): Promise<number>;
declare type PartOfSpeech = 'n' | 'v' | 'a' | 'r' | 's' | 'c' | 'p' | 'i' | 'x' | 'u';
declare type Relation = z.infer<typeof RelationSchema>;
declare const RelationSchema: z.ZodObject<{
id: z.ZodString;
type: z.ZodString;
target: z.ZodString;
source: z.ZodOptional<z.ZodString>;
dcType: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
/**
* Find root synsets in a Wordnet.
*
* @param wordnet - The Wordnet instance
* @param pos - Optional part of speech filter
* @returns Array of root synsets
*/
export declare function roots(wordnet: Wordnet, pos?: PartOfSpeech): Promise<Synset[]>;
declare type Sense = z.infer<typeof SenseSchema>;
declare type SenseQuery = z.infer<typeof SenseQuerySchema>;
declare const SenseQuerySchema: z.ZodObject<{
wordIdOrForm: z.ZodOptional<z.ZodString>;
pos: z.ZodOptional<z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>>;
lexicon: z.ZodOptional<z.ZodString>;
strategy: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare const SenseSchema: z.ZodObject<{
id: z.ZodString;
wordId: z.ZodString;
synsetId: z.ZodString;
examples: z.ZodArray<z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
counts: z.ZodArray<z.ZodObject<{
id: z.ZodString;
value: z.ZodNumber;
writtenForm: z.ZodString;
pos: z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>;
}, z.core.$strip>>;
tags: z.ZodArray<z.ZodObject<{
id: z.ZodString;
category: z.ZodString;
value: z.ZodString;
}, z.core.$strip>>;
relations: z.ZodOptional<z.ZodArray<z.ZodObject<{
id: z.ZodString;
type: z.ZodString;
target: z.ZodString;
source: z.ZodOptional<z.ZodString>;
dcType: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>>;
source: z.ZodOptional<z.ZodString>;
sensekey: z.ZodOptional<z.ZodString>;
adjposition: z.ZodOptional<z.ZodString>;
subcategory: z.ZodOptional<z.ZodString>;
domain: z.ZodOptional<z.ZodString>;
register: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare type Synset = z.infer<typeof SynsetSchema>;
declare type SynsetQuery = z.infer<typeof SynsetQuerySchema>;
declare const SynsetQuerySchema: z.ZodObject<{
form: z.ZodOptional<z.ZodString>;
pos: z.ZodOptional<z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>>;
ili: z.ZodOptional<z.ZodString>;
lexicon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
language: z.ZodOptional<z.ZodString>;
searchAllForms: z.ZodOptional<z.ZodBoolean>;
fuzzy: z.ZodOptional<z.ZodBoolean>;
maxResults: z.ZodOptional<z.ZodNumber>;
includeDefinitions: z.ZodOptional<z.ZodBoolean>;
includeExamples: z.ZodOptional<z.ZodBoolean>;
includeRelations: z.ZodOptional<z.ZodBoolean>;
strategy: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare const SynsetSchema: z.ZodObject<{
id: z.ZodString;
ili: z.ZodOptional<z.ZodString>;
pos: z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>;
definitions: z.ZodArray<z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
examples: z.ZodArray<z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
relations: z.ZodArray<z.ZodObject<{
id: z.ZodString;
type: z.ZodString;
target: z.ZodString;
source: z.ZodOptional<z.ZodString>;
dcType: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
iliDefinitions: z.ZodOptional<z.ZodArray<z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>>;
language: z.ZodString;
lexicon: z.ZodString;
memberIds: z.ZodArray<z.ZodString>;
senseIds: z.ZodArray<z.ZodString>;
}, z.core.$strip>;
/**
* Calculate the taxonomy depth for a part of speech.
*
* @param wordnet - The Wordnet instance
* @param pos - Part of speech
* @returns The maximum depth of the taxonomy
*/
export declare function taxonomyDepth(wordnet: Wordnet, pos: PartOfSpeech): Promise<number>;
/**
* Find the shortest path between two synsets.
*
* @param synset1 - The first synset
* @param synset2 - The second synset
* @param wordnet - The Wordnet instance
* @param simulateRoot - Whether to simulate a root for disconnected synsets
* @returns Array of synsets representing the shortest path
*/
export declare function taxonomyShortestPath(synset1: Synset, synset2: Synset, wordnet: Wordnet, simulateRoot?: boolean): Promise<Synset[]>;
declare type Word = z.infer<typeof WordSchema>;
declare class Wordnet implements WordNetCore {
private kyselyWordnet;
private _expand;
private _defaultNormalizer;
private _defaultLemmatizer;
private _initialized;
constructor(lexicon?: string, options?: WordnetOptions);
/**
* Initialize the database if not already initialized
*/
private ensureInitialized;
/**
* Close the database connection
*/
close(): Promise<void>;
/**
* Create a default normalizer function
*/
private _createDefaultNormalizer;
/**
* Create a default lemmatizer function
*/
private _createDefaultLemmatizer;
lexicons(): Promise<Lexicon[]>;
query(_sql: string, _params?: unknown[]): Promise<unknown[]>;
/**
* Get synsets with various query options
*/
synsets(query?: SynsetQuery): Promise<Synset[]>;
synsets(form: string, pos?: PartOfSpeech, options?: {
lexicon?: string | string[];
}): Promise<Synset[]>;
/**
* Get senses with various query options
*/
senses(query?: SenseQuery): Promise<Sense[]>;
senses(form: string, pos?: PartOfSpeech, options?: {
lexicon?: string | string[];
}): Promise<Sense[]>;
/**
* Get words with various query options
*/
words(query?: WordQuery): Promise<Word[]>;
words(form: string, pos?: PartOfSpeech, options?: {
lexicon?: string | string[];
}): Promise<Word[]>;
getWord(form: string): Promise<Word[]>;
getSynset(id: string): Promise<Synset | null>;
/**
* Alias for getSynset for consistency with other methods
*/
getSynsetById(id: string): Promise<Synset | null>;
getSenses(form: string, pos?: PartOfSpeech, options?: {
lexicon?: string | string[];
}): Promise<Sense[]>;
getRelations(_synsetId: string, _relationType?: string): Promise<any[]>;
getSense(id: string): Promise<Sense | undefined>;
getIli(id: string): Promise<ILI | undefined>;
getWordOrUndefined(id: string): Promise<Word | undefined>;
getSynsetOrUndefined(id: string): Promise<Synset | undefined>;
getSenseOrUndefined(id: string): Promise<Sense | undefined>;
getStatistics(): Promise<{
totalWords: number;
totalSynsets: number;
totalSenses: number;
totalILIs: number;
totalLexicons: number;
}>;
expandedLexicons(): Promise<Lexicon[]>;
normalizeForm(form: string): Promise<string>;
morphy(form: string, pos?: PartOfSpeech): Promise<Record<PartOfSpeech, Set<string>>>;
ilis(status?: string): Promise<ILI[]>;
word(wordId: string): Promise<Word>;
synset(synsetId: string): Promise<Synset>;
sense(senseId: string): Promise<Sense>;
ili(iliId: string): Promise<ILI>;
synsetsByILI(iliId: string): Promise<Synset[]>;
getProjects(): Promise<any[]>;
searchWords(query: any): Promise<Word[]>;
searchSynsets(query: any): Promise<Synset[]>;
wordsByForm(form: string, options?: any): Promise<Word[]>;
synsetsByForm(form: string, options?: any): Promise<Synset[]>;
getWordForms(wordId: string): Promise<string[]>;
getWordLemma(wordId: string): Promise<string>;
getDerivedWords(wordId: string): Promise<Word[]>;
getHypernyms(synsetId: string): Promise<Synset[]>;
getHyponyms(synsetId: string): Promise<Synset[]>;
getRelatedSynsets(synsetId: string, relationType: string): Promise<Synset[]>;
getRelatedSenses(senseId: string, relationType: string): Promise<Sense[]>;
getShortestPath(synsetId1: string, synsetId2: string): Promise<Synset[]>;
getSynsetDepth(synsetId: string): Promise<number>;
translateWord(wordId: string, targetLang: string): Promise<Record<string, Word[]>>;
translateSynset(synsetId: string, targetLang: string): Promise<Synset[]>;
translateSense(senseId: string, targetLang: string): Promise<Sense[]>;
getCrossLingualSynsets(iliId: string, targetLangs?: string[]): Promise<Record<string, Synset[]>>;
getDefinitions(synsetId: string): Promise<Definition[]>;
getExamples(synsetId: string): Promise<string[]>;
getSenseExamples(senseId: string): Promise<string[]>;
getSynsetWords(synsetId: string): Promise<Word[]>;
getSynsetLemmas(synsetId: string): Promise<string[]>;
getSynsetSenses(synsetId: string): Promise<Sense[]>;
hasLexicon(lexiconId: string): Promise<boolean>;
getSupportedLanguages(): Promise<string[]>;
getLexiconDependencies(lexiconId: string): Promise<string[]>;
/**
* Get words by ILI and language
*/
getWordsByIliAndLanguage(ili: string, language?: string): Promise<Word[]>;
getLexiconStatistics(lexiconId?: string): Promise<any[]>;
getDataQualityMetrics(): Promise<any>;
getPartOfSpeechDistribution(): Promise<Record<string, number>>;
getSynsetSizeAnalysis(): Promise<any>;
/**
* Get the query service for direct database operations
*/
getQueryService(): Promise<KyselyQueryService>;
}
declare interface WordNetCore {
query(sql: string, params?: unknown[]): Promise<unknown[]>;
words(query?: WordQuery): Promise<Word[]>;
word(wordId: string): Promise<Word>;
synsets(query?: SynsetQuery): Promise<Synset[]>;
synset(synsetId: string): Promise<Synset>;
senses(query?: SenseQuery): Promise<Sense[]>;
sense(senseId: string): Promise<Sense>;
ili(iliId: string): Promise<ILI>;
ilis(status?: string): Promise<ILI[]>;
synsetsByILI(iliId: string): Promise<Synset[]>;
lexicons(): Promise<Lexicon[]>;
getWord(form: string): Promise<Word[]>;
getSynset(id: string): Promise<Synset | null>;
getSenses(wordId: string): Promise<Sense[]>;
getDefinitions(synsetId: string): Promise<Definition[]>;
getRelations(synsetId: string, type?: string): Promise<Relation[]>;
}
declare type WordnetOptions = z.infer<typeof WordnetOptionsSchema>;
declare const WordnetOptionsSchema: z.ZodObject<{
lexicon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
version: z.ZodOptional<z.ZodString>;
expand: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
normalizer: z.ZodOptional<z.ZodAny>;
lemmatizer: z.ZodOptional<z.ZodAny>;
searchAllForms: z.ZodOptional<z.ZodBoolean>;
language: z.ZodOptional<z.ZodString>;
strategy: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare type WordQuery = z.infer<typeof WordQuerySchema>;
declare const WordQuerySchema: z.ZodObject<{
form: z.ZodOptional<z.ZodString>;
pos: z.ZodOptional<z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>>;
lexicon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
language: z.ZodOptional<z.ZodString>;
searchAllForms: z.ZodOptional<z.ZodBoolean>;
fuzzy: z.ZodOptional<z.ZodBoolean>;
maxResults: z.ZodOptional<z.ZodNumber>;
includeInflected: z.ZodOptional<z.ZodBoolean>;
strategy: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare const WordSchema: z.ZodObject<{
id: z.ZodString;
lemma: z.ZodString;
pos: z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>;
forms: z.ZodArray<z.ZodObject<{
id: z.ZodString;
writtenForm: z.ZodString;
script: z.ZodOptional<z.ZodString>;
tag: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
pronunciations: z.ZodArray<z.ZodObject<{
id: z.ZodString;
value: z.ZodString;
variety: z.ZodOptional<z.ZodString>;
notation: z.ZodOptional<z.ZodString>;
geographic: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
tags: z.ZodArray<z.ZodObject<{
id: z.ZodString;
category: z.ZodString;
value: z.ZodString;
}, z.core.$strip>>;
counts: z.ZodArray<z.ZodObject<{
id: z.ZodString;
value: z.ZodNumber;
writtenForm: z.ZodString;
pos: z.ZodEnum<{
n: "n";
v: "v";
a: "a";
r: "r";
s: "s";
c: "c";
p: "p";
i: "i";
x: "x";
u: "u";
}>;
}, z.core.$strip>>;
syntacticBehaviours: z.ZodOptional<z.ZodArray<z.ZodObject<{
id: z.ZodString;
subcategorizationFrame: z.ZodString;
source: z.ZodOptional<z.ZodString>;
senseIds: z.ZodArray<z.ZodString>;
}, z.core.$strip>>>;
language: z.ZodString;
lexicon: z.ZodString;
}, z.core.$strip>;
export { }