wn-ts-node
Version:
Wordnet interface library - TypeScript port
1,568 lines (1,433 loc) • 63.4 kB
TypeScript
import { Kysely } from 'kysely';
import { KyselyQueryService as KyselyQueryService_2 } from './index.js';
import { z } from 'zod';
export declare const __version__ = "0.1.1";
/**
* Add a lexical resource to the database
*/
export declare function add(path: string, options?: AddOptions): Promise<boolean>;
export declare const addLexicalResource: typeof add;
export declare type AddOptions = z.infer<typeof AddOptionsSchema>;
declare const AddOptionsSchema: z.ZodObject<{
force: z.ZodOptional<z.ZodBoolean>;
progress: z.ZodOptional<z.ZodAny>;
parser: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
/**
* Shared database configuration interfaces for wn-ts ecosystem
*
* This provides common configuration types that both Node.js and Web implementations
* can use, eliminating duplication across packages.
*/
/**
* Base database configuration interface
*/
declare interface BaseDatabaseConfig {
/**
* Whether the database is read-only
*/
readonly?: boolean;
/**
* Whether to force recreation of the database
*/
forceRecreate?: boolean;
/**
* Whether to enable verbose logging
*/
verbose?: boolean;
}
declare abstract class BaseKyselyQueryService {
protected db: Kysely<Database>;
protected defaultStrategy: QueryStrategy;
protected defaultOptions: QueryOptions;
constructor(db: Kysely<Database>, options?: {
strategy?: QueryStrategy;
});
private updateDefaultOptions;
private getOptionsForStrategy;
getLexicons(options?: {
ids?: string[];
id?: string;
language?: string;
version?: string;
}): Promise<Lexicon[]>;
getLexiconById(id: string): Promise<Lexicon | undefined>;
getWords(options?: WordQuery & QueryOptions): Promise<Word[]>;
getWordById(id: string): Promise<Word | undefined>;
getWordsByFormFast(form: string, options?: {
pos?: PartOfSpeech;
lexicon?: string;
maxResults?: number;
}): Promise<Word[]>;
getWordsByFormFuzzyFast(form: string, options?: {
pos?: PartOfSpeech;
lexicon?: string;
maxResults?: number;
}): Promise<Word[]>;
getSynsets(options?: SynsetQuery & QueryOptions): Promise<Synset[]>;
getSynsetsV1(options?: SynsetQuery): Promise<Synset[]>;
getSynsetsV2(options?: SynsetQuery): Promise<Synset[]>;
getSynsetsV3(options?: SynsetQuery): Promise<Synset[]>;
getSynsetsV4(options?: SynsetQuery): Promise<Synset[]>;
private queryCache;
private cacheHits;
private cacheMisses;
getSynsetsV5(options?: SynsetQuery): Promise<Synset[]>;
getSynsetsV6(options?: SynsetQuery): Promise<Synset[]>;
getSynsetsFast(options?: SynsetQuery): Promise<Synset[]>;
getSynsetById(id: string, options?: QueryOptions): Promise<Synset | undefined>;
getSynsetsByFormFast(form: string, options?: {
pos?: PartOfSpeech;
lexicon?: string;
maxResults?: number;
} & QueryOptions): Promise<Synset[]>;
getSenses(options?: SenseQuery & QueryOptions): Promise<Sense[]>;
getSensesV1(options?: SenseQuery & QueryOptions): Promise<Sense[]>;
getSensesV5(options?: SenseQuery & QueryOptions): Promise<Sense[]>;
getSensesV6(options?: SenseQuery & QueryOptions): Promise<Sense[]>;
getSenseById(id: string): Promise<Sense | undefined>;
getDefinitionsBySynsetId(synsetId: string): Promise<any[]>;
getIliById(id: string): Promise<ILI | undefined>;
getIlis(options?: {
status?: string;
}): Promise<ILI[]>;
getStatistics(): Promise<{
totalWords: number;
totalSynsets: number;
totalSenses: number;
totalILIs: number;
totalLexicons: number;
}>;
batchInsert<T extends keyof Database>(tableName: T, data: Database[T][]): Promise<void>;
abstract createTables(): Promise<void>;
protected transformLexiconRecord(record: any): Lexicon;
protected transformWordRecord(record: Database['words']): Promise<Word>;
protected transformSynsetRecordV1(record: any): Promise<Synset>;
protected transformSynsetRecordV2(record: any): Promise<Synset>;
protected transformSynsetRecordFast(record: any): Promise<Synset>;
protected transformSynsetRecord(record: any, options?: QueryOptions): Promise<Synset>;
protected transformSenseRecord(record: any): Sense;
protected transformIliRecord(record: any): ILI;
getWordsByLexicon(lexiconId: string): Promise<any[]>;
getSensesByWordId(wordId: string): Promise<any[]>;
getSynsetsByLexicon(lexiconId: string): Promise<any[]>;
getExamplesBySynsetId(synsetId: string): Promise<any[]>;
getSensesBySynsetId(synsetId: string): Promise<any[]>;
getWordsByIds(wordIds: string[]): Promise<Word[]>;
getWordsBySynsetAndLanguage(synsetId: string, language?: string): Promise<Word[]>;
getWordsByIliAndLanguage(ili: string, language?: string): Promise<Word[]>;
getWordsByIliAndLexiconPrefix(ili: string, lexiconPrefix: string): Promise<Word[]>;
getRelationsBySynsetId(synsetId: string): Promise<any[]>;
/**
* Get forms for a specific word
*/
getFormsByWordId(wordId: string): Promise<any[]>;
}
/**
* Generic batch insert function using Kysely.
* Inserts data in chunks and handles conflicts by doing nothing.
*
* @param db The Kysely database instance.
* @param tableName The name of the table to insert into.
* @param data An array of objects to insert.
* @param chunkSize The size of each chunk for batch insertion.
*/
export declare function batchInsert<T extends keyof Database>(db: Kysely<Database>, tableName: T, data: any[], chunkSize?: number): Promise<void>;
export declare interface BilingualQueryOptions {
/** Source language code (e.g., 'en', 'fr') */
sourceLanguage: string;
/** Target language code (e.g., 'en', 'fr') */
targetLanguage: string;
/** Whether to include definitions in results */
includeDefinitions?: boolean;
/** Whether to include examples in results */
includeExamples?: boolean;
/** Maximum number of translations to return per language */
maxTranslations?: number;
}
declare interface CheckConstraint {
name: string;
condition: string;
}
/**
* Clear the cached project index (useful for testing)
*/
export declare function clearProjectIndexCache(): void;
declare interface ColumnRequirement {
name: string;
type: string;
nullable: boolean;
defaultValue?: string | number | boolean | null;
autoIncrement?: boolean;
unique?: boolean;
}
export declare const config: ConfigManager;
/**
* Concrete Node.js implementation of ConfigManager
* Extends the abstract ConfigManager from wn-ts-core
*/
export declare class ConfigManager extends ConfigManager_2 {
private _dataDirectory;
private _projects;
private _allowMultithreading;
constructor();
get dataDirectory(): string;
set dataDirectory(path: string);
get databasePath(): string;
get downloadDirectory(): string;
get allowMultithreading(): boolean;
set allowMultithreading(value: boolean);
get index(): Record<string, any>;
getCachePath(url: string): string;
addProject(id: string, type?: string, label?: string, language?: string, license?: string, error?: string): void;
addProjectVersion(id: string, version: string, url?: string, error?: string, license?: string): void;
getProjectInfo(arg: string): any;
loadIndex(path: string): void;
ensureDirectory(path: string): void;
isDirectory(path: string): boolean;
splitLexiconSpecifier(spec: string): [string, string];
update(data: Record<string, any>): void;
}
/**
* Abstract configuration manager interface
* Environment-specific packages will provide concrete implementations
*/
declare abstract class ConfigManager_2 {
abstract get dataDirectory(): string;
abstract set dataDirectory(path: string);
abstract get downloadDirectory(): string;
abstract get allowMultithreading(): boolean;
abstract set allowMultithreading(value: boolean);
abstract get index(): Record<string, ProjectConfig>;
abstract getCachePath(url: string): string;
abstract addProject(id: string, type?: string, label?: string, language?: string, license?: string, error?: string): void;
abstract addProjectVersion(id: string, version: string, url?: string, error?: string, license?: string): void;
abstract getProjectInfo(arg: string): ProjectInfo;
abstract loadIndex(path: string): void;
abstract ensureDirectory(path: string): void;
abstract isDirectory(path: string): boolean;
abstract splitLexiconSpecifier(spec: string): [string, string];
abstract update(data: Record<string, any>): void;
}
export declare class ConfigurationError extends WnError {
constructor(message: string);
}
declare type ConflictResolutionStrategy = 'merge' | 'override' | 'skip' | 'manual' | 'rollback';
declare interface ConstraintRequirement {
name: string;
table: string;
type: 'primary_key' | 'foreign_key' | 'unique' | 'check' | 'not_null';
definition: string;
}
export declare type Count = z.infer<typeof CountSchema>;
declare const CountSchema: 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>;
/**
* Create a minimal LMF document for testing.
*
* @returns Minimal LMF document
*/
export declare function createMinimalLMF(): LMFDocument;
/**
* Create a translation helper instance
*
* @param wordnetClient - WordNet client instance
* @returns TranslationHelper instance
*/
export declare function createTranslationHelper(wordnetClient: WordNetCore): TranslationHelper;
/**
* Shared database types for wn-ts ecosystem
*
* This file defines the common database schema types that both Node.js and Web
* implementations can use, eliminating duplication across packages.
*/
declare interface Database {
lexicons: LexiconTable;
words: WordTable;
synsets: SynsetTable;
senses: SenseTable;
definitions: DefinitionTable;
relations: RelationTable;
examples: ExampleTable;
ilis: IliTable;
forms: FormTable;
}
export declare class DatabaseError extends WnError {
constructor(message: string);
}
declare interface DataRequirement {
table: string;
records: Record<string, unknown>[];
condition?: string;
upsert?: boolean;
}
export 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>;
declare interface DefinitionTable {
id: string;
synset_id: string;
language: string;
text: string;
source?: string;
}
/**
* Download a project from the web
*/
export declare function download(projectId: string, options?: DownloadOptions): Promise<string>;
export declare class DownloadError extends Error {
status: number;
statusText: string;
constructor(message: string, status: number, statusText: string);
}
/**
* Download file with progress callback
*/
export declare function downloadFile(_url: string, _destination: string, _options?: DownloadOptions_2): Promise<void>;
export declare type DownloadOptions = z.infer<typeof DownloadOptionsSchema>;
/**
* Download utilities for file downloads
* This is a stub for browser environments.
* The Node.js implementation is in 'wn-ts-node/src/utils/download.ts'.
*/
declare interface DownloadOptions_2 {
timeout?: number;
onProgress?: (progress: number) => void;
}
declare const DownloadOptionsSchema: z.ZodObject<{
force: z.ZodOptional<z.ZodBoolean>;
progress: z.ZodOptional<z.ZodAny>;
timeout: z.ZodOptional<z.ZodNumber>;
}, z.core.$strip>;
/**
* Duplicate handling configuration
*/
declare interface DuplicateHandlingConfig {
strategy: DuplicateStrategy;
mergeFields?: {
definitions?: boolean;
examples?: boolean;
relations?: boolean;
forms?: boolean;
pronunciations?: boolean;
tags?: boolean;
counts?: boolean;
};
uniqueKeys?: {
words?: ('id' | 'lemma' | 'index' | 'pos')[];
synsets?: ('id' | 'ili')[];
senses?: ('id' | 'wordId-synsetId')[];
};
logDuplicates?: boolean;
trackStatistics?: boolean;
}
/**
* Duplicate handling strategies
*/
declare type DuplicateStrategy = 'keep-first' | 'keep-last' | 'merge' | 'skip' | 'error';
export declare type Example = z.infer<typeof ExampleSchema>;
declare const ExampleSchema: z.ZodObject<{
id: z.ZodString;
language: z.ZodString;
text: z.ZodString;
source: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare interface ExampleTable {
id: string;
synset_id?: string;
sense_id?: string;
language: string;
text: string;
source?: string;
}
/**
* Export data from the database
*/
export declare function export(options?: ExportOptions): Promise<any>;
export declare type ExportOptions = z.infer<typeof ExportOptionsSchema>;
declare const ExportOptionsSchema: z.ZodObject<{
format: z.ZodEnum<{
json: "json";
xml: "xml";
csv: "csv";
}>;
output: z.ZodOptional<z.ZodString>;
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strip>;
declare interface ForeignKeyRequirement {
column: string;
referencedTable: string;
referencedColumn: string;
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT';
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT';
}
export declare type Form = z.infer<typeof FormSchema>;
declare const FormSchema: z.ZodObject<{
id: z.ZodString;
writtenForm: z.ZodString;
script: z.ZodOptional<z.ZodString>;
tag: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
declare interface FormTable {
id: string;
word_id: string;
written_form: string;
script?: string;
tag?: string;
}
/**
* Get a specific project by ID
*/
export declare function getProject(projectId: string): Project | undefined;
/**
* Get all available projects
*/
export declare function getProjects(): Project[];
/**
* Check if a project version has an error
*/
export declare function getProjectVersionError(projectId: string, version: string): string | undefined;
/**
* Get available versions for a project
*/
export declare function getProjectVersions(projectId: string): string[];
/**
* Get download URL for a specific project version
*/
export declare function getProjectVersionUrls(projectId: string, version: string): string[];
declare interface HealthCheckResult {
isHealthy: boolean;
score: number;
issues: HealthIssue[];
recommendations: HealthRecommendation[];
timestamp: number;
}
declare interface HealthIssue {
id: string;
type: 'missing_schema' | 'missing_data' | 'conflict' | 'performance' | 'integrity';
severity: 'low' | 'medium' | 'high' | 'critical';
title: string;
description: string;
affectedTables: string[];
suggestedFix: string;
estimatedTime: number;
}
declare interface HealthRecommendation {
id: string;
type: 'schema' | 'data' | 'performance' | 'maintenance';
priority: 'low' | 'medium' | 'high' | 'critical';
title: string;
description: string;
benefits: string[];
estimatedEffort: number;
implementation: string;
}
export declare type ILI = z.infer<typeof ILISchema>;
export declare function ili(id: string): Promise<ILI>;
export declare function ilis(status?: string): Promise<ILI[]>;
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>;
declare interface IliTable {
id: string;
definition?: string;
status: string;
superseded_by?: string;
note?: string;
meta?: string;
}
declare interface IndexRequirement {
name: string;
table: string;
columns: string[];
type: 'primary' | 'unique' | 'index' | 'fulltext';
condition?: string;
}
/**
* Check if a file is a valid LMF file
*/
export declare function isLMF(filePath: string): Promise<boolean>;
declare interface KyselyDatabase {
db: Kysely<Database>;
executeSchemaModification: (sql: string) => Promise<void>;
getTableInfo: (tableName: string) => Promise<unknown[]>;
getIndexInfo: (tableName: string) => Promise<unknown[]>;
getConstraintInfo: (tableName: string) => Promise<unknown[]>;
}
export declare class KyselyQueryService extends BaseKyselyQueryService {
constructor(db: Kysely<Database>, options?: {
strategy?: QueryStrategy;
});
createTables(): Promise<void>;
deleteLexicon(lexiconId: string): Promise<void>;
deleteWordsByLexicon(lexiconId: string): Promise<void>;
deleteSynsetsByLexicon(lexiconId: string): Promise<void>;
}
export declare class KyselyWordnet extends LocalBaseWordnet {
private nodeDatabase;
private queryService;
private strategy;
constructor(lexicon?: string | string[], options?: Partial<NodeWordnetConfig>);
initialize(): Promise<void>;
private configureSQLite;
getWord(id: string): Promise<Word | undefined>;
getSynset(id: string): Promise<Synset | undefined>;
synset(id: string): Promise<Synset | undefined>;
getSense(id: string): Promise<Sense | undefined>;
getIli(id: string): Promise<ILI | undefined>;
words(query?: WordQuery): Promise<Word[]>;
synsets(query?: SynsetQuery): Promise<Synset[]>;
senses(query?: SenseQuery): Promise<Sense[]>;
lexicons(): Promise<Lexicon[]>;
getStatistics(): Promise<{
totalWords: number;
totalSynsets: number;
totalSenses: number;
totalILIs: number;
totalLexicons: number;
}>;
ilis(status?: string): Promise<ILI[]>;
synsetsByILI(iliId: string): Promise<Synset[]>;
getProjects(): Promise<Project[]>;
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>;
morphy(form: string, pos?: PartOfSpeech): Promise<Record<PartOfSpeech, Set<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[]>;
getRawDatabase(): Promise<Kysely<Database>>;
executeRawQuery<T = any>(_sqlString: string, _params?: any[]): Promise<T[]>;
executeRawTransaction<T>(callback: (db: Kysely<Database>) => Promise<T>): Promise<T>;
batchInsertWords(words: any[]): Promise<void>;
batchInsertSynsets(synsets: any[]): Promise<void>;
batchInsertSenses(senses: any[]): Promise<void>;
batchInsertForms(forms: any[]): Promise<void>;
batchInsertDefinitions(definitions: any[]): Promise<void>;
batchInsertExamples(examples: any[]): Promise<void>;
batchInsertRelations(relations: any[]): Promise<void>;
batchInsertILIs(ilis: any[]): Promise<void>;
batchInsertLexicons(lexicons: any[]): Promise<void>;
close(): Promise<void>;
/**
* Get the query service for direct database operations
*/
getQueryService(): KyselyQueryService;
/**
* Get words by ILI and language using the query service
*/
getWordsByIliAndLanguage(ili: string, language?: string): Promise<Word[]>;
}
export declare type Lexicon = z.infer<typeof LexiconSchema>;
/**
* Lexicon interface
*/
declare interface Lexicon_2 {
id: string;
label: string;
language: string;
email?: string | undefined;
license?: string | undefined;
version?: string | undefined;
url?: string | undefined;
citation?: string | undefined;
logo?: string | undefined;
requires?: string[] | undefined;
confidence?: number | undefined;
metadata?: Record<string, any> | undefined;
}
export declare function lexicons(): Promise<Lexicon[]>;
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>;
declare interface LexiconTable {
id: string;
label: string;
language: string;
email?: string;
license?: string;
version?: string;
url?: string;
citation?: string;
logo?: string;
metadata?: string;
}
declare type LifecycleEvent = 'kernel:init' | 'lexicon:loaded' | 'lexicon:updated' | 'data:loaded' | 'data:updated' | 'plugin:added' | 'plugin:removed' | 'schema:changed';
declare interface LifecycleEventData {
'kernel:init': {
kernel: WordNetCore;
};
'lexicon:loaded': {
lexicon: Lexicon;
source: string;
};
'lexicon:updated': {
lexicon: Lexicon;
changes: string[];
};
'data:loaded': {
source: string;
recordCount: number;
};
'data:updated': {
table: string;
operation: 'insert' | 'update' | 'delete';
count: number;
};
'plugin:added': {
pluginName: string;
methods: string[];
};
'plugin:removed': {
pluginName: string;
};
'schema:changed': {
modifications: string[];
};
}
declare type LifecycleHook<T extends LifecycleEvent = LifecycleEvent> = (event: T, data: LifecycleEventData[T], kernel: WordNetCore) => Promise<void> | void;
declare class LifecycleManager {
private hooks;
private pluginDependencies;
private pluginPriorities;
constructor();
/**
* Register a plugin's lifecycle hooks
*/
registerPlugin(plugin: PluginLifecycle): void;
/**
* Unregister a plugin's lifecycle hooks
*/
unregisterPlugin(pluginName: string): void;
/**
* Emit a lifecycle event and run all registered hooks in priority order
*/
emit<T extends LifecycleEvent>(event: T, data: LifecycleEventData[T], kernel: WordNetCore): Promise<void>;
/**
* Validate that plugin dependencies are satisfied
*/
private validateDependencies;
/**
* Get all registered plugins
*/
getRegisteredPlugins(): string[];
/**
* Get hooks for a specific event
*/
getHooksForEvent(event: LifecycleEvent): Array<{
plugin: string;
priority: number;
}>;
}
/**
* LMF Document structure
*/
export declare interface LMFDocument {
lmfVersion: string;
lexicons: Lexicon_2[];
synsets: Synset[];
words: Word[];
senses: Sense[];
}
/**
* LMF Load Options
*/
export declare interface LMFLoadOptions {
progress?: (progress: number) => void;
debug?: boolean;
strictForeignKeys?: boolean;
duplicateHandling?: DuplicateHandlingConfig;
}
/**
* Load an LMF XML file and parse it into TypeScript data structures.
* Supports both local file paths and URLs.
*
* @param filePathOrURL - Path to the LMF XML file or URL
* @param options - Loading options
* @returns Parsed LMF document
*/
export declare function loadLMF(filePathOrURL: string, options?: LMFLoadOptions): Promise<LMFDocument>;
/**
* Load the project index from the TOML file
*/
export declare function loadProjectIndex(): ProjectIndex;
declare abstract class LocalBaseWordnet {
protected database: NodeKyselyDatabase;
protected initialized: boolean;
protected lexicon: string[];
protected expand: string[];
protected normalizer?: (form: string) => string;
constructor(lexicon?: string | string[], options?: any);
abstract initialize(): Promise<void>;
protected getDb(): Kysely<Database>;
abstract getWord(id: string): Promise<Word | undefined>;
abstract getSynset(id: string): Promise<Synset | undefined>;
abstract getSense(id: string): Promise<Sense | undefined>;
abstract getIli(id: string): Promise<ILI | undefined>;
protected getSynsetOrUndefined(id: string): Promise<Synset | undefined>;
abstract words(query?: any): Promise<Word[]>;
abstract synsets(query?: any): Promise<Synset[]>;
abstract senses(query?: any): Promise<Sense[]>;
abstract lexicons(): Promise<Lexicon[]>;
normalizeForm(form: string): Promise<string>;
}
/**
* Node.js specific database configuration
*/
export declare interface NodeDatabaseConfig extends BaseDatabaseConfig {
/**
* Database file path
*/
filename: string;
/**
* Whether the file must exist
*/
fileMustExist?: boolean;
/**
* Database timeout in milliseconds
*/
timeout?: number;
}
export declare class NodeKyselyDatabase implements NodeKyselyDatabaseInterface {
private db;
private sqliteDb;
private config;
constructor(config: NodeDatabaseConfig);
initialize(): Promise<void>;
getDatabase(): Kysely<Database>;
close(): Promise<void>;
/**
* Get the underlying better-sqlite3 database instance
* This is useful for operations that need direct SQLite access
*/
getSqliteDatabase(): any;
/**
* Execute a raw SQL query (useful for complex operations)
*/
executeRaw(sql: string, params?: any[]): Promise<any[]>;
/**
* Execute a raw SQL query that returns a single row
*/
executeRawSingle(sql: string, params?: any[]): Promise<any>;
/**
* Begin a transaction
*/
beginTransaction(): Promise<void>;
/**
* Commit a transaction
*/
commitTransaction(): Promise<void>;
/**
* Rollback a transaction
*/
rollbackTransaction(): Promise<void>;
/**
* Check if the database is in a transaction
*/
isInTransaction(): boolean;
/**
* Get database statistics
*/
getDatabaseStats(): Promise<{
pageCount: number;
pageSize: number;
pageCountBytes: number;
freelistCount: number;
freelistCountBytes: number;
cacheSize: number;
cacheSizeBytes: number;
cacheUsed: number;
cacheUsedBytes: number;
}>;
/**
* Optimize the database
*/
optimize(): Promise<void>;
}
export declare interface NodeKyselyDatabaseInterface {
getDatabase(): Kysely<Database>;
initialize(): Promise<void>;
close(): Promise<void>;
}
export declare interface NodeWordnetConfig extends NodeDatabaseConfig {
journalMode?: 'DELETE' | 'WAL' | 'MEMORY' | 'OFF';
synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';
cacheSize?: number;
tempStore?: 'DEFAULT' | 'FILE' | 'MEMORY';
mmapSize?: number;
foreignKeys?: boolean;
recursiveTriggers?: boolean;
forceRecreate?: boolean;
strategy?: QueryStrategy;
}
/**
* Node.js implementation of WordNetCore interface
* Bridges the new kernel architecture with existing KyselyWordnet
*/
export declare class NodeWordNetCore implements WordNetCore {
private kyselyWordnet;
constructor(lexicon?: string | string[], options?: Partial<NodeWordnetConfig>);
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[]>;
lexicons(): Promise<any[]>;
synsetsByILI(iliId: string): Promise<Synset[]>;
getWord(form: string): Promise<Word[]>;
getSynset(id: string): Promise<any | null>;
getSenses(wordId: string): Promise<Sense[]>;
getDefinitions(synsetId: string): Promise<any[]>;
getRelations(synsetId: string, type?: string): Promise<any[]>;
initialize(): Promise<void>;
close(): Promise<void>;
getKyselyWordnet(): KyselyWordnet;
}
/**
* Kernel-based WordNet for Node.js
* Provides the new plugin system with full type safety
*/
export declare class NodeWordNetKernel {
private wordnet;
private core;
constructor(lexicon?: string | string[], options?: Partial<NodeWordnetConfig>);
initialize(): Promise<void>;
close(): Promise<void>;
words(query?: any): Promise<any[]>;
word(wordId: string): Promise<any>;
synsets(query?: any): Promise<any[]>;
synset(synsetId: string): Promise<any>;
senses(query?: any): Promise<any[]>;
sense(senseId: string): Promise<any>;
ili(iliId: string): Promise<any>;
ilis(status?: string): Promise<any[]>;
synsetsByILI(iliId: string): Promise<any[]>;
getHypernyms(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getHyponyms(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getMeronyms(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getHolonyms(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getEntailments(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getSimilarTos(synsetId: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
}>>;
getRelationsByType(synsetId: string, relationType: string): Promise<Array<{
id: string;
lemma: string;
pos: string;
language: string;
type: string;
}>>;
getAllRelations(synsetId: string): Promise<Array<{
id: string;
source_id: string;
target_id: string;
type: string;
source_lemma: string;
target_lemma: string;
direction: 'incoming' | 'outgoing';
}>>;
getPathSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
getWuPalmerSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
getLeacockChodorowSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
getJaccardSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
getBestSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
findMostSimilar(synsetId: string, limit?: number): Promise<Array<{
id: string;
similarity: number;
}>>;
getCrossLingualSimilarity(synset1: string | any, synset2: string | any): Promise<number>;
getTranslations(synsetId: string, targetLanguage?: string): Promise<Array<{
id: string;
language: string;
lexicon: string;
lemma: string;
pos: string;
}>>;
getTranslationsByWord(wordForm: string, sourceLanguage: string, targetLanguage: string): Promise<Array<{
sourceSynset: string;
ili: string;
translations: Array<{
lemma: string;
pos: string;
lexicon: string;
}>;
}>>;
getAvailableLanguages(synsetId: string): Promise<Array<{
language: string;
word_count: number;
}>>;
getSynsetsByIli(ili: string): Promise<Array<{
id: string;
language: string;
lexicon: string;
pos: string;
words: string;
}>>;
getTranslationConfidence(synset1: string, synset2: string): Promise<number>;
getTranslationSuggestions(wordForm: string, sourceLanguage: string, targetLanguage: string): Promise<Array<{
sourceSynset: string;
ili: string;
confidence: number;
targetWords: string[];
}>>;
get schemaManager(): any;
getPlugins(): string[];
has(pluginName: string): boolean;
getCore(): NodeWordNetCore;
getWordnet(): WordNetWithPlugins<readonly [typeof similarity, typeof translation]>;
}
/**
* Legacy parseLMFXML function - kept for backward compatibility
* This should be deprecated in favor of using the new parser interface
*
* @deprecated Use a specific parser implementation instead
*/
export declare function parseLMFXML(xmlContent: string, options?: LMFLoadOptions): LMFDocument;
export declare type PartOfSpeech = 'n' | 'v' | 'a' | 'r' | 's' | 'c' | 'p' | 'i' | 'x' | 'u';
declare interface Plugin<TMethods extends Record<string, PluginMethod> = Record<string, PluginMethod>> {
name: string;
methods: TMethods;
lifecycle?: PluginLifecycle;
}
declare interface PluginLifecycle {
name: string;
hooks: {
[K in LifecycleEvent]?: LifecycleHook<K>;
};
dependencies?: string[];
priority?: number;
}
declare type PluginMethod<TCore = WordNetKernel, TArgs extends any[] = any[], TReturn = any> = (core: TCore, ...args: TArgs) => TReturn;
declare interface PluginSchemaRequirements {
pluginName: string;
tables: TableRequirement[];
indexes: IndexRequirement[];
constraints: ConstraintRequirement[];
data: DataRequirement[];
dependencies: string[];
conflicts: string[];
}
export declare type Project = z.infer<typeof ProjectSchema>;
declare interface ProjectConfig {
type?: string;
label?: string | undefined;
language?: string | undefined;
license?: string | undefined;
error?: string | undefined;
versions: Record<string, ProjectVersion>;
}
export declare class ProjectError extends WnError {
constructor(message: string);
}
export declare interface ProjectIndex {
[projectId: string]: {
type?: string;
label: string;
language?: string;
license?: string;
description?: string;
url?: string;
citation?: string;
metadata?: Record<string, unknown>;
versions: {
[version: string]: ProjectVersion_2;
};
};
}
declare interface ProjectInfo {
id: string;
version: string;
type: string;
label: string;
language: string;
license: string;
resource_urls: string[];
cache?: string | undefined;
}
export declare const projects: (client?: Wordnet) => Promise<any[]>;
declare const ProjectSchema: z.ZodObject<{
id: z.ZodString;
label: z.ZodString;
description: z.ZodOptional<z.ZodString>;
url: z.ZodOptional<z.ZodString>;
license: z.ZodOptional<z.ZodString>;
citation: z.ZodOptional<z.ZodString>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, z.core.$strip>;
/**
* Environment-agnostic configuration interfaces for wn-ts-core
* Concrete implementations will be provided by environment-specific packages
*/
export declare interface ProjectVersion {
resource_urls?: string[];
error?: string;
license?: string;
}
declare interface ProjectVersion_2 {
url?: string;
urls?: string[];
error?: string;
}
export declare type Pronunciation = z.infer<typeof PronunciationSchema>;
declare const PronunciationSchema: 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>;
declare interface QueryOptions {
strategy?: QueryStrategy;
includeDefinitions?: boolean;
includeExamples?: boolean;
includeRelations?: boolean;
includeSenses?: boolean;
}
/**
* Query optimization strategies for different performance requirements
* Strategy names are flexible and can be query-specific (e.g., 'v1', 'v2', 'optimized', 'fast', etc.)
*/
declare type QueryStrategy = string;
/**
* Quick translation function for simple use cases
*
* @param wordnetClient - WordNet client instance
* @param word - Word to translate
* @param fromLang - Source language
* @param toLang - Target language
* @returns Promise<string[]> Array of translated words
*/
export declare function quickTranslate(wordnetClient: WordNetCore, word: string, fromLang: string, toLang: string): Promise<string[]>;
export 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>;
declare interface RelationTable {
id: string;
source_id: string;
target_id: string;
type: string;
source?: string;
}
/**
* Remove a lexical resource from the database
*/
export declare function remove(lexiconId: string): Promise<boolean>;
declare interface SchemaModification {
id: string;
type: 'table' | 'column' | 'index' | 'constraint' | 'data';
operation: 'create' | 'alter' | 'drop' | 'insert' | 'update' | 'delete';
table?: string;
column?: string;
sql: string;
rollbackSql: string;
dependencies: string[];
conflicts: string[];
priority: number;
estimatedTime: number;
}
export declare type Sense = z.infer<typeof SenseSchema>;
export declare function sense(id: string): Promise<Sense>;
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>;
export declare function senses(form?: string, pos?: PartOfSpeech, options?: {
lexicon?: string;
}): Promise<Sense[]>;
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 interface SenseTable {
id: string;
word_id: string;
synset_id: string;
source?: string;
sensekey?: string;
adjposition?: string;
subcategory?: string;
domain?: string;
register?: string;
}
/**
* Similarity module for WordNet (Core Module)
*/
declare const similarity: Plugin;
export declare type Synset = z.infer<typeof SynsetSchema>;
export declare function synset(id: string): Promise<Synset>;
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>;
export declare function synsets(query: SynsetQuery): Promise<Synset[]>;
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>;
declare interface SynsetTable {
id: string;
ili?: string;
pos: string;
language: string;
lexicon: string;
}
declare interface TableRequirement {
name: string;
columns: ColumnRequirement[];
primaryKey?: string[];
uniqueKeys?: string[][];
foreignKeys?: ForeignKeyRequirement[];
checks?: CheckConstraint[];
}
export declare type Tag = z.infer<typeof TagSchema>;
declare const TagSchema: z.ZodObject<{
id: z.ZodString;
category: z.ZodString;
value: z.ZodString;
}, z.core.$strip>;
declare const translation: Plugin;
/**
* Convenience class for easy translation queries
*/
export declare class TranslationHelper {
private wordnetClient;
constructor(wordnetClient: WordNetCore);
/**
* Get translations for a word from one language to another
*
* @param word - The word to translate
* @param options - Translation options
* @returns Promise<TranslationResult>
*
* @example
* ```typescript
* const helper = new TranslationHelper(wordnetClient);
* const result = await helper.translateWord('computer', {
* sourceLanguage: 'en',
* targetLanguage: 'fr',
* includeDefinitions: true,
* includeExamples: true
* });
* console.log(result.translations.fr.words); // ['ordinateur']
* ```
*/
translateWord(word: string, options: BilingualQueryOptions): Promise<TranslationResult>;
/**
* Get bidirectional translations between two languages
*
* @param word - The word to translate
* @param language1 - First language code
* @param language2 - Second language code
* @param options - Additional options
* @returns Promise<{ [language1]: TranslationResult, [language2]: TranslationResult }>
*/
getBidirectionalTranslations(word: string, language1: string, language2: string, options?: Omit<BilingualQueryOptions, 'sourceLanguage' | 'targetLanguage'>): Promise<{
[language1]: TranslationResult;
[language2]: TranslationResult;
}>;
/**
* Get all available languages in the database
*
* @returns Promise<string[]> Array of language codes
*/
getAvailableLanguages(): Promise<string[]>;
/**
* Check if a language is available for translation
*
* @param language - Language code to check
* @returns Promise<boolean>
*/
isLanguageAvailable(language: string): Promise<boolean>;
}
export declare interface TranslationResult {
sourceWord: string;
sourceLanguage: string;
translations: Record<string, {
words: string[];
definitions: string[];
examples: string[];
}>;
}
/**
* Core error classes for the wn-ts library
*/
export declare class WnError extends Error {
constructor(message: string);
}
export declare class WnWarning extends Error {
constructor(message: string);
}
export declare type Word = z.infer<typeof WordSchema>;
export declare function word(id: string): Promise<Word>;
export 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>;
get