@libmorpheus/wasm 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,244 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+ /** Version of the WebAssembly binding and of its npm and JSR packages. */
4
+ export const MORPHEUS_WASM_VERSION: string;
5
+ /** libmorpheus release compiled into the packaged module. */
6
+ export const MORPHEUS_NATIVE_VERSION: string;
7
+ /** C ABI implemented by the packaged module. */
8
+ export const MORPHEUS_NATIVE_ABI_VERSION: 2;
9
+ /** Emscripten release that reproduces the packaged module. */
10
+ export const MORPHEUS_EMSCRIPTEN_VERSION: string;
11
+
12
+ /** ABI version this facade understands. */
13
+ export const ABI_VERSION: 2;
14
+
15
+ export const MorpheusLanguage: Readonly<{ Greek: 0; Latin: 1; Italian: 2 }>;
16
+ export type MorpheusLanguage = typeof MorpheusLanguage[keyof typeof MorpheusLanguage];
17
+
18
+ export const MorpheusStatus: Readonly<{
19
+ Ok: 0;
20
+ InvalidArgument: 1;
21
+ AbiMismatch: 2;
22
+ NoMemory: 3;
23
+ InputTooLong: 4;
24
+ OutOfRange: 5;
25
+ InternalError: 6;
26
+ BufferTooSmall: 7;
27
+ StemlibError: 8;
28
+ ResultLimitExceeded: 9;
29
+ }>;
30
+ export type MorpheusStatus = typeof MorpheusStatus[keyof typeof MorpheusStatus];
31
+
32
+ /** Bit flags customizing `analyze()`; combine with `|`. */
33
+ export const MorpheusOption: Readonly<{
34
+ StrictCase: bigint;
35
+ IgnoreAccents: bigint;
36
+ VerbsOnly: bigint;
37
+ NoCrasis: bigint;
38
+ Quick: bigint;
39
+ HqDictionary: bigint;
40
+ DialectAeolic: bigint;
41
+ DialectAttic: bigint;
42
+ DialectDoric: bigint;
43
+ DialectHomeric: bigint;
44
+ DialectIonic: bigint;
45
+ DialectLesbian: bigint;
46
+ DialectNonHomericEpic: bigint;
47
+ DialectParadigm: bigint;
48
+ DialectEpic: bigint;
49
+ DialectProse: bigint;
50
+ }>;
51
+
52
+ export type MorpheusDialectOption =
53
+ | "Aeolic"
54
+ | "Attic"
55
+ | "Doric"
56
+ | "Homeric"
57
+ | "Ionic"
58
+ | "Lesbian"
59
+ | "NonHomericEpic"
60
+ | "Paradigm"
61
+ | "Epic"
62
+ | "Prose";
63
+
64
+ /** Named form of the analysis options. `strictCase` defaults to `true`. */
65
+ export interface MorpheusAnalyzeOptions {
66
+ strictCase?: boolean;
67
+ ignoreAccents?: boolean;
68
+ verbsOnly?: boolean;
69
+ noCrasis?: boolean;
70
+ quick?: boolean;
71
+ hqDictionary?: boolean;
72
+ dialects?: readonly MorpheusDialectOption[];
73
+ }
74
+
75
+ /** Flags for the historical text output of `analyzeCompat()`. */
76
+ export const MorpheusCompatFlag: Readonly<{
77
+ BufferAnalyses: number;
78
+ CheckPreverb: number;
79
+ KeepBeta: number;
80
+ ShowFullInfo: number;
81
+ DatabaseFormat: number;
82
+ DatabaseShort: number;
83
+ StrictCase: number;
84
+ ParseFormat: number;
85
+ PerseusFormat: number;
86
+ EndingIndex: number;
87
+ IgnoreAccents: number;
88
+ LexiconOutput: number;
89
+ LemmaCount: number;
90
+ VerbsOnly: number;
91
+ }>;
92
+
93
+ export const REQUIRED_STEMLIB_FILES: Readonly<{
94
+ common: readonly string[];
95
+ greek: readonly string[];
96
+ }>;
97
+
98
+ export const LANGUAGE_DIRECTORIES: Readonly<Record<MorpheusLanguage, string>>;
99
+
100
+ /** One structured analysis with the numeric codes of the C ABI. */
101
+ export interface MorpheusRawAnalysis {
102
+ readonly structSize: number;
103
+ readonly partOfSpeech: number;
104
+ readonly dialect: number;
105
+ readonly geographicRegion: number;
106
+ readonly person: number;
107
+ readonly number: number;
108
+ readonly gender: number;
109
+ readonly grammaticalCase: number;
110
+ readonly tense: number;
111
+ readonly mood: number;
112
+ readonly voice: number;
113
+ readonly degree: number;
114
+ readonly raw: string;
115
+ readonly workword: string;
116
+ readonly lemma: string;
117
+ readonly preverb: string;
118
+ readonly augment: string;
119
+ readonly stem: string;
120
+ readonly suffix: string;
121
+ readonly ending: string;
122
+ readonly crasis: string;
123
+ readonly dictionaryForm: string;
124
+ readonly englishForm: string;
125
+ readonly rawPreverb: string;
126
+ readonly domains: string;
127
+ /** Bit set of the 84 engine morph flags, least significant bit first. */
128
+ readonly morphFlags: Uint8Array;
129
+ /** Bit mask of `MORPHEUS_TRUNCATED_*` text fields. */
130
+ readonly truncatedFields: number;
131
+ }
132
+
133
+ /** One generated form with the numeric codes of the C ABI. */
134
+ export interface MorpheusRawGeneration {
135
+ readonly structSize: number;
136
+ readonly partOfSpeech: number;
137
+ readonly dialect: number;
138
+ readonly geographicRegion: number;
139
+ readonly person: number;
140
+ readonly number: number;
141
+ readonly gender: number;
142
+ readonly grammaticalCase: number;
143
+ readonly tense: number;
144
+ readonly mood: number;
145
+ readonly voice: number;
146
+ readonly degree: number;
147
+ readonly surface: string;
148
+ readonly lemma: string;
149
+ readonly morphFlags: Uint8Array;
150
+ readonly truncatedFields: number;
151
+ }
152
+
153
+ /** Filters for `generate()`; zero or omitted traits match everything. */
154
+ export interface MorpheusGenerationOptions {
155
+ resultLimit?: number;
156
+ excludeDuals?: boolean;
157
+ partOfSpeech?: number;
158
+ dialect?: number;
159
+ geographicRegion?: number;
160
+ person?: number;
161
+ number?: number;
162
+ gender?: number;
163
+ grammaticalCase?: number;
164
+ tense?: number;
165
+ mood?: number;
166
+ voice?: number;
167
+ degree?: number;
168
+ }
169
+
170
+ export interface MorpheusCompatOutput {
171
+ readonly text: string;
172
+ readonly analysisCount: number;
173
+ readonly lemmaCount: number;
174
+ }
175
+
176
+ export class MorpheusError extends Error {
177
+ readonly status: MorpheusStatus | number;
178
+ constructor(status: number, message: string);
179
+ }
180
+
181
+ export class MorpheusContext {
182
+ readonly language: MorpheusLanguage;
183
+ readonly closed: boolean;
184
+ analyze(betaCode: string, options?: bigint | number | MorpheusAnalyzeOptions): MorpheusRawAnalysis[];
185
+ analyzeCompat(betaCode: string, flags?: number): MorpheusCompatOutput;
186
+ generate(lemma: string, options?: MorpheusGenerationOptions): MorpheusRawGeneration[];
187
+ close(): void;
188
+ [Symbol.dispose]?(): void;
189
+ }
190
+
191
+ /** Minimal view of the Emscripten module used by the facade. */
192
+ export interface MorpheusEmscriptenModule {
193
+ FS: any;
194
+ HEAPU8: Uint8Array;
195
+ _malloc(size: number): number;
196
+ _free(pointer: number): void;
197
+ UTF8ToString(pointer: number): string;
198
+ stringToUTF8(text: string, pointer: number, maxBytes: number): void;
199
+ lengthBytesUTF8(text: string): number;
200
+ getValue(pointer: number, type: string): number;
201
+ setValue(pointer: number, value: number, type: string): void;
202
+ [symbol: string]: any;
203
+ }
204
+
205
+ export type StemlibEntries =
206
+ | Record<string, Uint8Array | ArrayBuffer | string>
207
+ | Map<string, Uint8Array | ArrayBuffer | string>
208
+ | Iterable<readonly [string, Uint8Array | ArrayBuffer | string]>;
209
+
210
+ export interface FetchStemlibOptions {
211
+ root?: string;
212
+ fetch?: typeof fetch;
213
+ concurrency?: number;
214
+ }
215
+
216
+ export class Morpheus {
217
+ readonly module: MorpheusEmscriptenModule;
218
+ readonly fs: any;
219
+ readonly version: string;
220
+ readonly abiVersion: number;
221
+ readonly analysisSize: number;
222
+ readonly generationSize: number;
223
+ statusMessage(status: number): string;
224
+ mountDirectory(hostPath: string, mountPoint?: string): string;
225
+ writeStemlib(entries: StemlibEntries, root?: string): string;
226
+ fetchStemlib(baseUrl: string | URL, paths: Iterable<string>, options?: FetchStemlibOptions): Promise<string>;
227
+ static requiredFiles(language: MorpheusLanguage): string[];
228
+ open(options: { stemlib?: string; language: MorpheusLanguage }): MorpheusContext;
229
+ closeAll(): void;
230
+ }
231
+
232
+ export interface CreateMorpheusOptions {
233
+ /** Already imported default export of `morpheus.mjs`. */
234
+ factory?: (options?: Record<string, unknown>) => Promise<MorpheusEmscriptenModule>;
235
+ /** Location of `morpheus.mjs` when `factory` is omitted. */
236
+ moduleUrl?: string | URL;
237
+ /** Precompiled module to instantiate instead of fetching and compiling `morpheus.wasm`. */
238
+ wasmModule?: WebAssembly.Module;
239
+ /** Options forwarded to the Emscripten factory (`locateFile`, `wasmBinary`, ...). */
240
+ moduleOptions?: Record<string, unknown>;
241
+ }
242
+
243
+ export function createMorpheus(options?: CreateMorpheusOptions): Promise<Morpheus>;
244
+ export default createMorpheus;