lindera 6.1.0 → 7.0.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/README.md +14 -12
- package/index.d.ts +444 -64
- package/index.js +115 -56
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -55,7 +55,6 @@ Download a dictionary archive (e.g. `lindera-ipadic-*.zip`) and specify the extr
|
|
|
55
55
|
|
|
56
56
|
- Node.js `^20.17.0 || ^22.13.0 || >= 23.5.0` : <https://nodejs.org/>
|
|
57
57
|
- Rust : <https://www.rust-lang.org/tools/install>
|
|
58
|
-
- @napi-rs/cli : `npm install -g @napi-rs/cli`
|
|
59
58
|
|
|
60
59
|
## Setup repository
|
|
61
60
|
|
|
@@ -67,7 +66,7 @@ cd lindera
|
|
|
67
66
|
|
|
68
67
|
## Install lindera-nodejs
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
These commands install the npm dependencies and build the library in release mode. The dependencies include the NAPI-RS CLI (`@napi-rs/cli`) at the version `package.json` pins, which `npm run build` runs.
|
|
71
70
|
|
|
72
71
|
```shell
|
|
73
72
|
cd lindera-nodejs
|
|
@@ -75,26 +74,28 @@ npm install
|
|
|
75
74
|
npm run build
|
|
76
75
|
```
|
|
77
76
|
|
|
77
|
+
For a debug build, run `npm run build:debug` instead of `npm run build`.
|
|
78
|
+
|
|
78
79
|
## Quick Start
|
|
79
80
|
|
|
80
81
|
The examples below use CommonJS. The package is also importable from ESM — the
|
|
81
82
|
same named exports are available:
|
|
82
83
|
|
|
83
84
|
```javascript
|
|
84
|
-
import { loadDictionary, Tokenizer } from "lindera";
|
|
85
|
+
import { loadDictionary, Mode, Tokenizer } from "lindera";
|
|
85
86
|
```
|
|
86
87
|
|
|
87
88
|
### Basic Tokenization
|
|
88
89
|
|
|
89
90
|
```javascript
|
|
90
|
-
const { loadDictionary, Tokenizer } = require("lindera");
|
|
91
|
+
const { loadDictionary, Mode, Tokenizer } = require("lindera");
|
|
91
92
|
|
|
92
93
|
// Load dictionary
|
|
93
94
|
// Load dictionary from a local path (download from GitHub Releases)
|
|
94
95
|
const dictionary = loadDictionary("/path/to/ipadic");
|
|
95
96
|
|
|
96
97
|
// Create a tokenizer
|
|
97
|
-
const tokenizer = new Tokenizer(dictionary,
|
|
98
|
+
const tokenizer = new Tokenizer(dictionary, Mode.normal());
|
|
98
99
|
|
|
99
100
|
// Tokenize Japanese text
|
|
100
101
|
const text = "すもももももももものうち";
|
|
@@ -130,11 +131,11 @@ instances (out-of-range reads now yield `undefined` rather than `null`).
|
|
|
130
131
|
### Using Character Filters
|
|
131
132
|
|
|
132
133
|
```javascript
|
|
133
|
-
const { TokenizerBuilder } = require("lindera");
|
|
134
|
+
const { Mode, TokenizerBuilder } = require("lindera");
|
|
134
135
|
|
|
135
136
|
// Create tokenizer builder
|
|
136
137
|
const builder = new TokenizerBuilder();
|
|
137
|
-
builder.setMode(
|
|
138
|
+
builder.setMode(Mode.normal());
|
|
138
139
|
builder.setDictionary("/path/to/ipadic");
|
|
139
140
|
|
|
140
141
|
// Add character filters
|
|
@@ -150,11 +151,11 @@ const tokens = tokenizer.tokenize(text); // Will apply filters automatically
|
|
|
150
151
|
### Using Token Filters
|
|
151
152
|
|
|
152
153
|
```javascript
|
|
153
|
-
const { TokenizerBuilder } = require("lindera");
|
|
154
|
+
const { Mode, TokenizerBuilder } = require("lindera");
|
|
154
155
|
|
|
155
156
|
// Create tokenizer builder
|
|
156
157
|
const builder = new TokenizerBuilder();
|
|
157
|
-
builder.setMode(
|
|
158
|
+
builder.setMode(Mode.normal());
|
|
158
159
|
builder.setDictionary("/path/to/ipadic");
|
|
159
160
|
|
|
160
161
|
// Add token filters
|
|
@@ -172,11 +173,11 @@ const tokens = tokenizer.tokenize("テキストの解析");
|
|
|
172
173
|
### Integrated Pipeline
|
|
173
174
|
|
|
174
175
|
```javascript
|
|
175
|
-
const { TokenizerBuilder } = require("lindera");
|
|
176
|
+
const { Mode, TokenizerBuilder } = require("lindera");
|
|
176
177
|
|
|
177
178
|
// Build tokenizer with integrated filters
|
|
178
179
|
const builder = new TokenizerBuilder();
|
|
179
|
-
builder.setMode(
|
|
180
|
+
builder.setMode(Mode.normal());
|
|
180
181
|
builder.setDictionary("/path/to/ipadic");
|
|
181
182
|
|
|
182
183
|
// Add character filters
|
|
@@ -295,7 +296,7 @@ train({
|
|
|
295
296
|
featureDef: "path/to/feature.def",
|
|
296
297
|
rewriteDef: "path/to/rewrite.def",
|
|
297
298
|
output: "model.dat",
|
|
298
|
-
lambda: 0
|
|
299
|
+
lambda: 1.0,
|
|
299
300
|
maxIter: 100,
|
|
300
301
|
});
|
|
301
302
|
```
|
|
@@ -329,6 +330,7 @@ See `examples/train_and_export.js` for a complete example.
|
|
|
329
330
|
|
|
330
331
|
- `TokenizerBuilder`: Fluent builder for tokenizer configuration
|
|
331
332
|
- `Tokenizer`: Main tokenization engine
|
|
333
|
+
- `Mode`: Tokenization mode, normal or decompose with a `Penalty`
|
|
332
334
|
- `Dictionary`: A loaded system dictionary
|
|
333
335
|
- `UserDictionary`: A loaded user dictionary
|
|
334
336
|
- `Metadata`: Dictionary metadata and configuration
|
package/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type JsDictionary = Dictionary
|
|
|
27
27
|
/**
|
|
28
28
|
* Dictionary metadata configuration.
|
|
29
29
|
*
|
|
30
|
-
* A thin napi wrapper over [`
|
|
30
|
+
* A thin napi wrapper over [`lindera_binding::CoreMetadata`], which owns
|
|
31
31
|
* the default values and the schema wiring.
|
|
32
32
|
*/
|
|
33
33
|
export declare class Metadata {
|
|
@@ -37,6 +37,11 @@ export declare class Metadata {
|
|
|
37
37
|
* # Arguments
|
|
38
38
|
*
|
|
39
39
|
* * `options` - Optional configuration object. When omitted, all defaults are used.
|
|
40
|
+
*
|
|
41
|
+
* # Returns
|
|
42
|
+
*
|
|
43
|
+
* The metadata, or an `InvalidArg` error for a cost or context ID that
|
|
44
|
+
* is not an integer in its range.
|
|
40
45
|
*/
|
|
41
46
|
constructor(options?: MetadataOptions | undefined | null)
|
|
42
47
|
/**
|
|
@@ -69,15 +74,48 @@ export declare class Metadata {
|
|
|
69
74
|
set encoding(encoding: string)
|
|
70
75
|
/** Default word cost. */
|
|
71
76
|
get defaultWordCost(): number
|
|
72
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Sets the default word cost.
|
|
79
|
+
*
|
|
80
|
+
* # Arguments
|
|
81
|
+
*
|
|
82
|
+
* * `cost` - An integer from -32768 to 32767.
|
|
83
|
+
*
|
|
84
|
+
* # Returns
|
|
85
|
+
*
|
|
86
|
+
* Nothing, or an `InvalidArg` error for any other number, which leaves
|
|
87
|
+
* the cost unchanged.
|
|
88
|
+
*/
|
|
73
89
|
set defaultWordCost(cost: number)
|
|
74
90
|
/** Default left context ID. */
|
|
75
91
|
get defaultLeftContextId(): number
|
|
76
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Sets the default left context ID.
|
|
94
|
+
*
|
|
95
|
+
* # Arguments
|
|
96
|
+
*
|
|
97
|
+
* * `id` - An integer from 0 to 65535.
|
|
98
|
+
*
|
|
99
|
+
* # Returns
|
|
100
|
+
*
|
|
101
|
+
* Nothing, or an `InvalidArg` error for any other number, which leaves
|
|
102
|
+
* the ID unchanged.
|
|
103
|
+
*/
|
|
77
104
|
set defaultLeftContextId(id: number)
|
|
78
105
|
/** Default right context ID. */
|
|
79
106
|
get defaultRightContextId(): number
|
|
80
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Sets the default right context ID.
|
|
109
|
+
*
|
|
110
|
+
* # Arguments
|
|
111
|
+
*
|
|
112
|
+
* * `id` - An integer from 0 to 65535.
|
|
113
|
+
*
|
|
114
|
+
* # Returns
|
|
115
|
+
*
|
|
116
|
+
* Nothing, or an `InvalidArg` error for any other number, which leaves
|
|
117
|
+
* the ID unchanged.
|
|
118
|
+
*/
|
|
81
119
|
set defaultRightContextId(id: number)
|
|
82
120
|
/** Default field value for missing fields. */
|
|
83
121
|
get defaultFieldValue(): string
|
|
@@ -91,10 +129,6 @@ export declare class Metadata {
|
|
|
91
129
|
get skipInvalidCostOrId(): boolean
|
|
92
130
|
/** Sets whether to skip invalid entries. */
|
|
93
131
|
set skipInvalidCostOrId(value: boolean)
|
|
94
|
-
/** Whether to normalize morphological details. */
|
|
95
|
-
get normalizeDetails(): boolean
|
|
96
|
-
/** Sets whether to normalize details. */
|
|
97
|
-
set normalizeDetails(value: boolean)
|
|
98
132
|
/**
|
|
99
133
|
* Returns a plain object representation of the metadata.
|
|
100
134
|
*
|
|
@@ -109,10 +143,78 @@ export declare class Metadata {
|
|
|
109
143
|
}
|
|
110
144
|
export type JsMetadata = Metadata
|
|
111
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Tokenization mode: normal, or decompose with a `Penalty`.
|
|
148
|
+
*
|
|
149
|
+
* The JS counterpart of the Rust `lindera::mode::Mode`. It has no
|
|
150
|
+
* constructor; `Mode.normal()`, `Mode.decompose()` and `Mode.fromStr()`
|
|
151
|
+
* create one. A mode cannot be changed, and `equals` compares its name and
|
|
152
|
+
* penalty.
|
|
153
|
+
*/
|
|
154
|
+
export declare class Mode {
|
|
155
|
+
/**
|
|
156
|
+
* Creates normal mode.
|
|
157
|
+
*
|
|
158
|
+
* # Returns
|
|
159
|
+
*
|
|
160
|
+
* Normal mode.
|
|
161
|
+
*/
|
|
162
|
+
static normal(): Mode
|
|
163
|
+
/**
|
|
164
|
+
* Creates decompose mode.
|
|
165
|
+
*
|
|
166
|
+
* # Arguments
|
|
167
|
+
*
|
|
168
|
+
* * `penalty` - The `Penalty`. `null` or `undefined` (the default) uses
|
|
169
|
+
* the default penalty; a field left out keeps its default.
|
|
170
|
+
*
|
|
171
|
+
* # Returns
|
|
172
|
+
*
|
|
173
|
+
* Decompose mode with the penalty. Throws, with code `InvalidArg`, for
|
|
174
|
+
* a penalty that is not an object or a field that is not an integer in
|
|
175
|
+
* its range.
|
|
176
|
+
*/
|
|
177
|
+
static decompose(penalty?: Penalty | undefined | null): Mode
|
|
178
|
+
/**
|
|
179
|
+
* Creates a mode from its name, as the Rust `Mode` parses one.
|
|
180
|
+
*
|
|
181
|
+
* # Arguments
|
|
182
|
+
*
|
|
183
|
+
* * `name` - `"normal"` or `"decompose"`, case sensitive.
|
|
184
|
+
*
|
|
185
|
+
* # Returns
|
|
186
|
+
*
|
|
187
|
+
* The mode, with the default penalty for `"decompose"`. Throws for any
|
|
188
|
+
* other name, as `setMode` did for it in v6.
|
|
189
|
+
*/
|
|
190
|
+
static fromStr(name: string): Mode
|
|
191
|
+
/** The name of the mode: `"normal"` or `"decompose"`. */
|
|
192
|
+
get name(): string
|
|
193
|
+
/**
|
|
194
|
+
* The penalty of decompose mode, as a copy with every field set, or
|
|
195
|
+
* `null` for normal mode.
|
|
196
|
+
*/
|
|
197
|
+
get penalty(): Penalty | null
|
|
198
|
+
/** Returns whether this is normal mode. */
|
|
199
|
+
isNormal(): boolean
|
|
200
|
+
/** Returns whether this is decompose mode. */
|
|
201
|
+
isDecompose(): boolean
|
|
202
|
+
/**
|
|
203
|
+
* Returns whether `other` has the same name and penalty.
|
|
204
|
+
*
|
|
205
|
+
* # Arguments
|
|
206
|
+
*
|
|
207
|
+
* * `other` - Another `Mode`. A value that is not a `Mode` throws.
|
|
208
|
+
*/
|
|
209
|
+
equals(other: Mode): boolean
|
|
210
|
+
/** Returns the name of the mode, as `name` does. */
|
|
211
|
+
toString(): string
|
|
212
|
+
}
|
|
213
|
+
|
|
112
214
|
/**
|
|
113
215
|
* Dictionary schema definition.
|
|
114
216
|
*
|
|
115
|
-
* A thin napi wrapper over [`
|
|
217
|
+
* A thin napi wrapper over [`lindera_binding::CoreSchema`], which owns the
|
|
116
218
|
* field storage, the name-to-index map, and the field lookups.
|
|
117
219
|
*/
|
|
118
220
|
export declare class Schema {
|
|
@@ -153,11 +255,12 @@ export declare class Schema {
|
|
|
153
255
|
*
|
|
154
256
|
* # Arguments
|
|
155
257
|
*
|
|
156
|
-
* * `index` - Zero-based index.
|
|
258
|
+
* * `index` - Zero-based index, an integer of 0 or more.
|
|
157
259
|
*
|
|
158
260
|
* # Returns
|
|
159
261
|
*
|
|
160
|
-
* The field name,
|
|
262
|
+
* The field name, `undefined` if the schema has no field at `index`, or
|
|
263
|
+
* an `InvalidArg` error when `index` is negative or not an integer.
|
|
161
264
|
*/
|
|
162
265
|
getFieldName(index: number): string | null
|
|
163
266
|
/**
|
|
@@ -211,10 +314,19 @@ export declare class Tokenizer {
|
|
|
211
314
|
* # Arguments
|
|
212
315
|
*
|
|
213
316
|
* * `dictionary` - Dictionary to use for tokenization.
|
|
214
|
-
* * `mode` -
|
|
317
|
+
* * `mode` - The `Mode`, as `TokenizerBuilder.setMode` takes it. `null`
|
|
318
|
+
* or `undefined` (the default) is normal mode.
|
|
215
319
|
* * `user_dictionary` - Optional user dictionary for custom words.
|
|
320
|
+
* * `space_penalty` - The left-space penalty, in the forms
|
|
321
|
+
* `TokenizerBuilder.setSpacePenalty` accepts. `null` or `undefined`
|
|
322
|
+
* (the default) keeps the rules the dictionary ships.
|
|
323
|
+
*
|
|
324
|
+
* Throws for a `mode` that is not a `Mode`, for an invalid space-penalty
|
|
325
|
+
* setting, as `setSpacePenalty` and `build()` do, and for a user
|
|
326
|
+
* dictionary with a context ID outside the dictionary's connection
|
|
327
|
+
* matrix.
|
|
216
328
|
*/
|
|
217
|
-
constructor(dictionary: Dictionary, mode?:
|
|
329
|
+
constructor(dictionary: Dictionary, mode?: Mode | undefined | null, userDictionary?: UserDictionary | undefined | null, spacePenalty?: boolean | { rules: Array<{ pos: Array<string>; cost: number }> } | null | undefined)
|
|
218
330
|
/**
|
|
219
331
|
* Tokenizes the given text.
|
|
220
332
|
*
|
|
@@ -255,15 +367,139 @@ export declare class Tokenizer {
|
|
|
255
367
|
* # Arguments
|
|
256
368
|
*
|
|
257
369
|
* * `text` - Text to tokenize.
|
|
258
|
-
* * `n` - Number of N-best results to return.
|
|
370
|
+
* * `n` - Number of N-best results to return, an integer of 0 or more.
|
|
259
371
|
* * `unique` - If true, deduplicate results (default: false).
|
|
260
|
-
* * `cost_threshold` - Maximum cost difference from the best path
|
|
372
|
+
* * `cost_threshold` - Maximum cost difference from the best path, an
|
|
373
|
+
* integer that fits in 64 bits (default: undefined).
|
|
261
374
|
*
|
|
262
375
|
* # Returns
|
|
263
376
|
*
|
|
264
|
-
* An array of NbestResult objects, each containing tokens and their cost
|
|
377
|
+
* An array of NbestResult objects, each containing tokens and their cost,
|
|
378
|
+
* or an `InvalidArg` error when `n` or `cost_threshold` is not an integer
|
|
379
|
+
* in its range.
|
|
265
380
|
*/
|
|
266
381
|
tokenizeNbest(text: string, n: number, unique?: boolean | undefined | null, costThreshold?: number | undefined | null): Array<NbestResult>
|
|
382
|
+
/**
|
|
383
|
+
* Tokenizes every text of `texts`, each as `tokenize` does, on up to
|
|
384
|
+
* `maxThreads` threads, and returns their tokens in the order of
|
|
385
|
+
* `texts`.
|
|
386
|
+
*
|
|
387
|
+
* The call is synchronous: the JavaScript thread waits until every
|
|
388
|
+
* text is tokenized, while the tokenization runs on several threads.
|
|
389
|
+
* The results are the same for every number of threads.
|
|
390
|
+
*
|
|
391
|
+
* # Arguments
|
|
392
|
+
*
|
|
393
|
+
* * `texts` - An array of texts.
|
|
394
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
395
|
+
* the parallelism the system reports).
|
|
396
|
+
*
|
|
397
|
+
* # Returns
|
|
398
|
+
*
|
|
399
|
+
* An array with the token objects of each text, or an `InvalidArg`
|
|
400
|
+
* error when `maxThreads` is not an integer of 1 or more.
|
|
401
|
+
*/
|
|
402
|
+
tokenizeBatch(texts: Array<string>, maxThreads?: number | undefined | null): Array<Array<Token>>
|
|
403
|
+
/**
|
|
404
|
+
* Tokenizes every text of `texts` as `tokenizeSurfaces` does, on up to
|
|
405
|
+
* `maxThreads` threads, as `tokenizeBatch` does.
|
|
406
|
+
*
|
|
407
|
+
* # Arguments
|
|
408
|
+
*
|
|
409
|
+
* * `texts` - An array of texts.
|
|
410
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
411
|
+
* the parallelism the system reports).
|
|
412
|
+
*
|
|
413
|
+
* # Returns
|
|
414
|
+
*
|
|
415
|
+
* An array with the surface strings of each text, or an `InvalidArg`
|
|
416
|
+
* error when `maxThreads` is not an integer of 1 or more.
|
|
417
|
+
*/
|
|
418
|
+
tokenizeSurfacesBatch(texts: Array<string>, maxThreads?: number | undefined | null): Array<Array<string>>
|
|
419
|
+
/**
|
|
420
|
+
* Tokenizes every text of `texts` as `tokenizeNbest` does, on up to
|
|
421
|
+
* `maxThreads` threads, as `tokenizeBatch` does.
|
|
422
|
+
*
|
|
423
|
+
* # Arguments
|
|
424
|
+
*
|
|
425
|
+
* * `texts` - An array of texts.
|
|
426
|
+
* * `n` - Number of N-best results per text, an integer of 0 or more.
|
|
427
|
+
* * `unique` - If true, deduplicate results (default: false).
|
|
428
|
+
* * `cost_threshold` - Maximum cost difference from the best path of
|
|
429
|
+
* each text, an integer that fits in 64 bits (default: undefined).
|
|
430
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
431
|
+
* the parallelism the system reports).
|
|
432
|
+
*
|
|
433
|
+
* # Returns
|
|
434
|
+
*
|
|
435
|
+
* An array with the NbestResult objects of each text, or an
|
|
436
|
+
* `InvalidArg` error when `n`, `costThreshold` or `maxThreads` is not
|
|
437
|
+
* an integer in its range.
|
|
438
|
+
*/
|
|
439
|
+
tokenizeNbestBatch(texts: Array<string>, n: number, unique?: boolean | undefined | null, costThreshold?: number | undefined | null, maxThreads?: number | undefined | null): Array<Array<NbestResult>>
|
|
440
|
+
/**
|
|
441
|
+
* Tokenizes every text of `texts` as `tokenizeBatch` does, and returns
|
|
442
|
+
* a `Promise` of the same results.
|
|
443
|
+
*
|
|
444
|
+
* The texts are tokenized on a thread of libuv's pool, on up to
|
|
445
|
+
* `maxThreads` threads of the batch, while the event loop runs; the
|
|
446
|
+
* token objects are then made on the JavaScript thread, at once when
|
|
447
|
+
* they are few, or else in parts with a turn of the event loop between
|
|
448
|
+
* two parts. Batches on the same tokenizer run one after the other; a
|
|
449
|
+
* single-text call does not wait for them.
|
|
450
|
+
*
|
|
451
|
+
* # Arguments
|
|
452
|
+
*
|
|
453
|
+
* * `texts` - An array of texts.
|
|
454
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
455
|
+
* the parallelism the system reports).
|
|
456
|
+
*
|
|
457
|
+
* # Returns
|
|
458
|
+
*
|
|
459
|
+
* A `Promise` of an array with the token objects of each text. It
|
|
460
|
+
* rejects with an `InvalidArg` error when `maxThreads` is not an integer
|
|
461
|
+
* of 1 or more, and with the error of the first text in input order
|
|
462
|
+
* that fails.
|
|
463
|
+
*/
|
|
464
|
+
tokenizeBatchAsync(texts: Array<string>, maxThreads?: number | undefined | null): Promise<Array<Array<Token>>>
|
|
465
|
+
/**
|
|
466
|
+
* Tokenizes every text of `texts` as `tokenizeSurfacesBatch` does, and
|
|
467
|
+
* returns a `Promise` of the same results, as `tokenizeBatchAsync` does.
|
|
468
|
+
*
|
|
469
|
+
* # Arguments
|
|
470
|
+
*
|
|
471
|
+
* * `texts` - An array of texts.
|
|
472
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
473
|
+
* the parallelism the system reports).
|
|
474
|
+
*
|
|
475
|
+
* # Returns
|
|
476
|
+
*
|
|
477
|
+
* A `Promise` of an array with the surface strings of each text. It
|
|
478
|
+
* rejects as `tokenizeBatchAsync`'s does.
|
|
479
|
+
*/
|
|
480
|
+
tokenizeSurfacesBatchAsync(texts: Array<string>, maxThreads?: number | undefined | null): Promise<Array<Array<string>>>
|
|
481
|
+
/**
|
|
482
|
+
* Tokenizes every text of `texts` as `tokenizeNbestBatch` does, and
|
|
483
|
+
* returns a `Promise` of the same results, as `tokenizeBatchAsync` does.
|
|
484
|
+
*
|
|
485
|
+
* # Arguments
|
|
486
|
+
*
|
|
487
|
+
* * `texts` - An array of texts.
|
|
488
|
+
* * `n` - Number of N-best results per text, an integer of 0 or more.
|
|
489
|
+
* * `unique` - If true, deduplicate results (default: false).
|
|
490
|
+
* * `cost_threshold` - Maximum cost difference from the best path of
|
|
491
|
+
* each text, an integer that fits in 64 bits (default: undefined).
|
|
492
|
+
* * `max_threads` - The most threads, an integer of 1 or more (default:
|
|
493
|
+
* the parallelism the system reports).
|
|
494
|
+
*
|
|
495
|
+
* # Returns
|
|
496
|
+
*
|
|
497
|
+
* A `Promise` of an array with the NbestResult objects of each text. It
|
|
498
|
+
* rejects with an `InvalidArg` error when `n`, `costThreshold` or
|
|
499
|
+
* `maxThreads` is not an integer in its range, and with the error of
|
|
500
|
+
* the first text in input order that fails.
|
|
501
|
+
*/
|
|
502
|
+
tokenizeNbestBatchAsync(texts: Array<string>, n: number, unique?: boolean | undefined | null, costThreshold?: number | undefined | null, maxThreads?: number | undefined | null): Promise<Array<Array<NbestResult>>>
|
|
267
503
|
}
|
|
268
504
|
export type JsTokenizer = Tokenizer
|
|
269
505
|
|
|
@@ -293,13 +529,14 @@ export declare class TokenizerBuilder {
|
|
|
293
529
|
*
|
|
294
530
|
* # Arguments
|
|
295
531
|
*
|
|
296
|
-
* * `mode` - Mode
|
|
532
|
+
* * `mode` - The `Mode`, with its penalty for decompose mode.
|
|
297
533
|
*
|
|
298
534
|
* # Returns
|
|
299
535
|
*
|
|
300
|
-
* The builder itself (`this`), enabling method chaining.
|
|
536
|
+
* The builder itself (`this`), enabling method chaining. Throws, with
|
|
537
|
+
* code `InvalidArg`, for a value that is not a `Mode`.
|
|
301
538
|
*/
|
|
302
|
-
setMode(mode:
|
|
539
|
+
setMode(mode: Mode): this
|
|
303
540
|
/**
|
|
304
541
|
* Sets the dictionary path or URI.
|
|
305
542
|
*
|
|
@@ -327,6 +564,10 @@ export declare class TokenizerBuilder {
|
|
|
327
564
|
/**
|
|
328
565
|
* Sets whether to keep whitespace in tokenization results.
|
|
329
566
|
*
|
|
567
|
+
* Kept whitespace also stays in the lattice, so the other tokens can
|
|
568
|
+
* differ from those of the default output, which skips whitespace as
|
|
569
|
+
* MeCab does.
|
|
570
|
+
*
|
|
330
571
|
* # Arguments
|
|
331
572
|
*
|
|
332
573
|
* * `keep_whitespace` - If true, whitespace tokens will be included in results.
|
|
@@ -336,6 +577,47 @@ export declare class TokenizerBuilder {
|
|
|
336
577
|
* The builder itself (`this`), enabling method chaining.
|
|
337
578
|
*/
|
|
338
579
|
setKeepWhitespace(keepWhitespace: boolean): this
|
|
580
|
+
/**
|
|
581
|
+
* Sets whether whitespace is skipped in the lattice, with the same
|
|
582
|
+
* meaning as `segmenter.skip_whitespace` in a YAML config.
|
|
583
|
+
*
|
|
584
|
+
* `true` skips whitespace, so the words on either side connect directly,
|
|
585
|
+
* as MeCab does; `false` keeps whitespace in the lattice as a node of
|
|
586
|
+
* its own, as before v7 (it is still dropped from the output); `null`
|
|
587
|
+
* or `undefined` goes back to the default of the dictionary's
|
|
588
|
+
* `metadata.json` (skipping, except with SudachiDict). No effect while
|
|
589
|
+
* whitespace tokens are kept (`setKeepWhitespace(true)`).
|
|
590
|
+
*
|
|
591
|
+
* # Arguments
|
|
592
|
+
*
|
|
593
|
+
* * `skip_whitespace` - The setting, or `null` / `undefined` for the
|
|
594
|
+
* dictionary's default.
|
|
595
|
+
*
|
|
596
|
+
* # Returns
|
|
597
|
+
*
|
|
598
|
+
* The builder itself (`this`), enabling method chaining.
|
|
599
|
+
*/
|
|
600
|
+
setSkipWhitespace(skipWhitespace: boolean | null | undefined): this
|
|
601
|
+
/**
|
|
602
|
+
* Sets the break characters, with the same meaning as
|
|
603
|
+
* `segmenter.break_characters` in a YAML config.
|
|
604
|
+
*
|
|
605
|
+
* Each character of the string is a break character: no unknown word,
|
|
606
|
+
* nor, in decompose mode, any system-dictionary word, crosses a
|
|
607
|
+
* boundary between a break character and another character. An empty
|
|
608
|
+
* string turns the rule off, which gives MeCab's segmentation; `null`
|
|
609
|
+
* or `undefined` goes back to the default, `・`.
|
|
610
|
+
*
|
|
611
|
+
* # Arguments
|
|
612
|
+
*
|
|
613
|
+
* * `break_characters` - The break characters, or `null` / `undefined`
|
|
614
|
+
* for the default.
|
|
615
|
+
*
|
|
616
|
+
* # Returns
|
|
617
|
+
*
|
|
618
|
+
* The builder itself (`this`), enabling method chaining.
|
|
619
|
+
*/
|
|
620
|
+
setBreakCharacters(breakCharacters: string | null | undefined): this
|
|
339
621
|
/**
|
|
340
622
|
* Sets the left-space penalty (Korean), with the same meaning as
|
|
341
623
|
* `segmenter.space_penalty` in a configuration file.
|
|
@@ -356,7 +638,8 @@ export declare class TokenizerBuilder {
|
|
|
356
638
|
* # Returns
|
|
357
639
|
*
|
|
358
640
|
* The builder itself (`this`), enabling method chaining. Throws when
|
|
359
|
-
* `value` is none of the forms above
|
|
641
|
+
* `value` is none of the forms above, or when it nests more than 128
|
|
642
|
+
* levels deep (a value that contains itself always does).
|
|
360
643
|
*/
|
|
361
644
|
setSpacePenalty(value: boolean | { rules: Array<{ pos: Array<string>; cost: number }> } | null | undefined): this
|
|
362
645
|
/**
|
|
@@ -369,7 +652,9 @@ export declare class TokenizerBuilder {
|
|
|
369
652
|
*
|
|
370
653
|
* # Returns
|
|
371
654
|
*
|
|
372
|
-
* The builder itself (`this`), enabling method chaining.
|
|
655
|
+
* The builder itself (`this`), enabling method chaining. Throws when
|
|
656
|
+
* `args` nests more than 128 levels deep (a value that contains itself
|
|
657
|
+
* always does).
|
|
373
658
|
*/
|
|
374
659
|
appendCharacterFilter(kind: string, args?: any | undefined | null): this
|
|
375
660
|
/**
|
|
@@ -382,7 +667,9 @@ export declare class TokenizerBuilder {
|
|
|
382
667
|
*
|
|
383
668
|
* # Returns
|
|
384
669
|
*
|
|
385
|
-
* The builder itself (`this`), enabling method chaining.
|
|
670
|
+
* The builder itself (`this`), enabling method chaining. Throws when
|
|
671
|
+
* `args` nests more than 128 levels deep (a value that contains itself
|
|
672
|
+
* always does).
|
|
386
673
|
*/
|
|
387
674
|
appendTokenFilter(kind: string, args?: any | undefined | null): this
|
|
388
675
|
/**
|
|
@@ -408,29 +695,68 @@ export type JsUserDictionary = UserDictionary
|
|
|
408
695
|
/**
|
|
409
696
|
* Builds a dictionary from source files.
|
|
410
697
|
*
|
|
698
|
+
* When the metadata enables `connection_id_mapping`, as the `metadata.json`
|
|
699
|
+
* of ko-dic and UniDic does, the build relabels the connection matrix's
|
|
700
|
+
* context IDs by access frequency: by the counts of `context_id_freq`, or,
|
|
701
|
+
* without it, by the count of dictionary entries. The relabelling changes
|
|
702
|
+
* the speed of tokenization, never its result.
|
|
703
|
+
*
|
|
411
704
|
* # Arguments
|
|
412
705
|
*
|
|
413
706
|
* * `input_dir` - Directory containing dictionary source files.
|
|
414
707
|
* * `output_dir` - Directory where the built dictionary will be saved.
|
|
415
708
|
* * `metadata` - Metadata configuration for the dictionary.
|
|
709
|
+
* * `context_id_freq` - Optional path of a context-ID frequency histogram,
|
|
710
|
+
* such as the `context_id_freq.txt` of a dictionary crate, as `lindera
|
|
711
|
+
* build --context-id-freq` takes it. Read only with
|
|
712
|
+
* `connection_id_mapping`.
|
|
416
713
|
*/
|
|
417
|
-
export declare function buildDictionary(inputDir: string, outputDir: string, metadata: JsMetadata): void
|
|
714
|
+
export declare function buildDictionary(inputDir: string, outputDir: string, metadata: JsMetadata, contextIdFreq?: string | undefined | null): void
|
|
418
715
|
|
|
419
716
|
/**
|
|
420
717
|
* Builds a user dictionary from a CSV file.
|
|
421
718
|
*
|
|
719
|
+
* The rows' context IDs are not checked here; they are checked when the
|
|
720
|
+
* user dictionary is combined with a system dictionary. To check them as
|
|
721
|
+
* the CSV is built, use `buildUserDictionaryFor` with the system dictionary.
|
|
722
|
+
*
|
|
422
723
|
* # Arguments
|
|
423
724
|
*
|
|
424
725
|
* * `kind` - Dictionary kind (reserved for future use).
|
|
425
726
|
* * `input_file` - Path to the CSV file containing user dictionary entries.
|
|
426
|
-
* * `output_dir` -
|
|
727
|
+
* * `output_dir` - Path of the file to write the built user dictionary to,
|
|
728
|
+
* not a directory despite its name. The user dictionary loaders choose
|
|
729
|
+
* how to load a file by its extension, so end it with `.bin`.
|
|
427
730
|
* * `metadata` - Optional metadata configuration. If omitted, default values are used.
|
|
428
731
|
*/
|
|
429
732
|
export declare function buildUserDictionary(kind: string, inputFile: string, outputDir: string, metadata?: JsMetadata | undefined | null): void
|
|
430
733
|
|
|
734
|
+
/**
|
|
735
|
+
* Builds a user dictionary from a CSV file for a loaded system dictionary.
|
|
736
|
+
*
|
|
737
|
+
* The CSV is built with the system dictionary's metadata, and every row's
|
|
738
|
+
* context IDs are checked against its connection matrix, so a row outside
|
|
739
|
+
* the matrix fails with an error that names its CSV line and surface, and
|
|
740
|
+
* no file is written.
|
|
741
|
+
*
|
|
742
|
+
* # Arguments
|
|
743
|
+
*
|
|
744
|
+
* * `input_file` - Path to the CSV file containing user dictionary entries.
|
|
745
|
+
* * `output_file` - Path of the file to write the built user dictionary to.
|
|
746
|
+
* The user dictionary loaders choose how to load a file by its extension,
|
|
747
|
+
* so end it with `.bin`.
|
|
748
|
+
* * `dictionary` - The system dictionary the user dictionary is built for.
|
|
749
|
+
*/
|
|
750
|
+
export declare function buildUserDictionaryFor(inputFile: string, outputFile: string, dictionary: Dictionary): void
|
|
751
|
+
|
|
431
752
|
/**
|
|
432
753
|
* Exports dictionary files from a trained model.
|
|
433
754
|
*
|
|
755
|
+
* Writes the files `lindera export` writes, with the same method
|
|
756
|
+
* (`SerializableModel::export`): `lex.csv`, `matrix.def`, `unk.def`,
|
|
757
|
+
* `char.def`, `feature.def`, `rewrite.def`, `left-id.def` and
|
|
758
|
+
* `right-id.def`, and `metadata.json` when `options.metadata` is given.
|
|
759
|
+
*
|
|
434
760
|
* # Arguments
|
|
435
761
|
*
|
|
436
762
|
* * `options` - Export options containing file paths.
|
|
@@ -481,38 +807,6 @@ export declare const enum JsFieldType {
|
|
|
481
807
|
Custom = 'Custom',
|
|
482
808
|
}
|
|
483
809
|
|
|
484
|
-
/**
|
|
485
|
-
* Tokenization mode.
|
|
486
|
-
*
|
|
487
|
-
* Determines how text is segmented into tokens.
|
|
488
|
-
*
|
|
489
|
-
* - `Normal`: Standard tokenization based on dictionary cost.
|
|
490
|
-
* - `Decompose`: Decomposes compound words using penalty-based segmentation.
|
|
491
|
-
*/
|
|
492
|
-
export declare const enum JsMode {
|
|
493
|
-
/** Standard tokenization based on dictionary cost */
|
|
494
|
-
Normal = 'Normal',
|
|
495
|
-
/** Decompose compound words using penalty-based segmentation */
|
|
496
|
-
Decompose = 'Decompose',
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Penalty configuration for decompose mode.
|
|
501
|
-
*
|
|
502
|
-
* Controls how aggressively compound words are decomposed based on
|
|
503
|
-
* character type and length thresholds.
|
|
504
|
-
*/
|
|
505
|
-
export interface JsPenalty {
|
|
506
|
-
/** Length threshold for kanji sequences before applying penalty (default: 2). */
|
|
507
|
-
kanjiPenaltyLengthThreshold: number
|
|
508
|
-
/** Penalty value for long kanji sequences (default: 3000). */
|
|
509
|
-
kanjiPenaltyLengthPenalty: number
|
|
510
|
-
/** Length threshold for other character sequences before applying penalty (default: 7). */
|
|
511
|
-
otherPenaltyLengthThreshold: number
|
|
512
|
-
/** Penalty value for long other-character sequences (default: 1700). */
|
|
513
|
-
otherPenaltyLengthPenalty: number
|
|
514
|
-
}
|
|
515
|
-
|
|
516
810
|
/**
|
|
517
811
|
* Loads a dictionary from the specified URI.
|
|
518
812
|
*
|
|
@@ -541,6 +835,26 @@ export declare function loadDictionary(uri: string): Dictionary
|
|
|
541
835
|
*/
|
|
542
836
|
export declare function loadUserDictionary(uri: string, metadata: JsMetadata): UserDictionary
|
|
543
837
|
|
|
838
|
+
/**
|
|
839
|
+
* Loads a user dictionary for a loaded system dictionary.
|
|
840
|
+
*
|
|
841
|
+
* A `.csv` is built with the system dictionary's metadata and checked
|
|
842
|
+
* against its connection matrix as it is built, so a row whose context ID
|
|
843
|
+
* lies outside the matrix fails with an error that names its CSV line and
|
|
844
|
+
* surface. A `.bin` is loaded as it was built; the `Tokenizer` checks it
|
|
845
|
+
* when it is built with the system dictionary.
|
|
846
|
+
*
|
|
847
|
+
* # Arguments
|
|
848
|
+
*
|
|
849
|
+
* * `uri` - URI or path of the `.csv` or `.bin` user dictionary.
|
|
850
|
+
* * `dictionary` - The system dictionary the user dictionary is used with.
|
|
851
|
+
*
|
|
852
|
+
* # Returns
|
|
853
|
+
*
|
|
854
|
+
* A loaded UserDictionary object.
|
|
855
|
+
*/
|
|
856
|
+
export declare function loadUserDictionaryFor(uri: string, dictionary: Dictionary): UserDictionary
|
|
857
|
+
|
|
544
858
|
/**
|
|
545
859
|
* Options for creating a Metadata instance.
|
|
546
860
|
*
|
|
@@ -551,11 +865,14 @@ export interface MetadataOptions {
|
|
|
551
865
|
name?: string
|
|
552
866
|
/** Character encoding (default: "UTF-8"). */
|
|
553
867
|
encoding?: string
|
|
554
|
-
/**
|
|
868
|
+
/**
|
|
869
|
+
* Default cost for unknown words, an integer from -32768 to 32767
|
|
870
|
+
* (default: -10000).
|
|
871
|
+
*/
|
|
555
872
|
defaultWordCost?: number
|
|
556
|
-
/** Default left context ID (default: 1288). */
|
|
873
|
+
/** Default left context ID, an integer from 0 to 65535 (default: 1288). */
|
|
557
874
|
defaultLeftContextId?: number
|
|
558
|
-
/** Default right context ID (default: 1288). */
|
|
875
|
+
/** Default right context ID, an integer from 0 to 65535 (default: 1288). */
|
|
559
876
|
defaultRightContextId?: number
|
|
560
877
|
/** Default value for missing fields (default: "*"). */
|
|
561
878
|
defaultFieldValue?: string
|
|
@@ -563,8 +880,6 @@ export interface MetadataOptions {
|
|
|
563
880
|
flexibleCsv?: boolean
|
|
564
881
|
/** Skip entries with invalid cost or ID (default: false). */
|
|
565
882
|
skipInvalidCostOrId?: boolean
|
|
566
|
-
/** Normalize morphological details (default: false). */
|
|
567
|
-
normalizeDetails?: boolean
|
|
568
883
|
}
|
|
569
884
|
|
|
570
885
|
/**
|
|
@@ -579,6 +894,36 @@ export interface NbestResult {
|
|
|
579
894
|
cost: number
|
|
580
895
|
}
|
|
581
896
|
|
|
897
|
+
/**
|
|
898
|
+
* Penalty configuration for decompose mode.
|
|
899
|
+
*
|
|
900
|
+
* Controls how aggressively compound words are decomposed based on
|
|
901
|
+
* character type and length thresholds. Pass it to `Mode.decompose`. A
|
|
902
|
+
* field left out keeps its default.
|
|
903
|
+
*/
|
|
904
|
+
export interface Penalty {
|
|
905
|
+
/**
|
|
906
|
+
* Length threshold for kanji sequences before applying the penalty, an
|
|
907
|
+
* integer 0 or more (default: 2).
|
|
908
|
+
*/
|
|
909
|
+
kanjiPenaltyLengthThreshold?: number
|
|
910
|
+
/**
|
|
911
|
+
* Penalty value for long kanji sequences, a 32-bit signed integer
|
|
912
|
+
* (default: 3000).
|
|
913
|
+
*/
|
|
914
|
+
kanjiPenaltyLengthPenalty?: number
|
|
915
|
+
/**
|
|
916
|
+
* Length threshold for other character sequences before applying the
|
|
917
|
+
* penalty, an integer 0 or more (default: 7).
|
|
918
|
+
*/
|
|
919
|
+
otherPenaltyLengthThreshold?: number
|
|
920
|
+
/**
|
|
921
|
+
* Penalty value for long other-character sequences, a 32-bit signed
|
|
922
|
+
* integer (default: 1700).
|
|
923
|
+
*/
|
|
924
|
+
otherPenaltyLengthPenalty?: number
|
|
925
|
+
}
|
|
926
|
+
|
|
582
927
|
/**
|
|
583
928
|
* A morphological token.
|
|
584
929
|
*
|
|
@@ -608,6 +953,13 @@ export interface Token {
|
|
|
608
953
|
* # Arguments
|
|
609
954
|
*
|
|
610
955
|
* * `options` - Training options containing file paths and parameters.
|
|
956
|
+
*
|
|
957
|
+
* # Returns
|
|
958
|
+
*
|
|
959
|
+
* Nothing, or an error. A `maxIter` or `maxThreads` that is not an integer
|
|
960
|
+
* of 1 or more, and a `regularization`, `lambda`, `elasticNetL1Ratio` or
|
|
961
|
+
* `eta` that is not accepted, are an `InvalidArg` error, raised before any
|
|
962
|
+
* file is read.
|
|
611
963
|
*/
|
|
612
964
|
export declare function train(options: TrainOptions): void
|
|
613
965
|
|
|
@@ -627,12 +979,40 @@ export interface TrainOptions {
|
|
|
627
979
|
rewriteDef: string
|
|
628
980
|
/** Output path for the trained model file. */
|
|
629
981
|
output: string
|
|
630
|
-
/**
|
|
982
|
+
/**
|
|
983
|
+
* Regularization coefficient, finite and >= 0 (default: 1.0); with L2,
|
|
984
|
+
* MeCab's `-c C` is `1 / C`, so 1.0 is MeCab's `-c 1.0`.
|
|
985
|
+
* Zero disables regularization for every type.
|
|
986
|
+
*/
|
|
631
987
|
lambda?: number
|
|
632
|
-
/**
|
|
988
|
+
/**
|
|
989
|
+
* Maximum number of training iterations, an integer of 1 or more
|
|
990
|
+
* (default: 100).
|
|
991
|
+
*/
|
|
633
992
|
maxIter?: number
|
|
634
|
-
/**
|
|
993
|
+
/**
|
|
994
|
+
* Number of threads, an integer of 1 or more (undefined = auto-detect
|
|
995
|
+
* CPU cores).
|
|
996
|
+
*/
|
|
635
997
|
maxThreads?: number
|
|
998
|
+
/**
|
|
999
|
+
* Regularization type: `"l1"`, `"l2"` or `"elasticnet"` (in any case;
|
|
1000
|
+
* also `"elastic_net"` or `"elastic-net"`) (default: `"l2"`).
|
|
1001
|
+
*/
|
|
1002
|
+
regularization?: string
|
|
1003
|
+
/**
|
|
1004
|
+
* L1 ratio of Elastic Net regularization, between 0 and 1 (default:
|
|
1005
|
+
* 0.5); used only with `"elasticnet"`.
|
|
1006
|
+
* Zero uses only L2; one uses only L1.
|
|
1007
|
+
*/
|
|
1008
|
+
elasticNetL1Ratio?: number
|
|
1009
|
+
/**
|
|
1010
|
+
* Tolerance of the convergence test, finite and >= 0 (default: 5e-5):
|
|
1011
|
+
* training stops before `maxIter` once the relative change of the
|
|
1012
|
+
* objective stays below it for 3 iterations in a row; 0 disables the
|
|
1013
|
+
* test.
|
|
1014
|
+
*/
|
|
1015
|
+
eta?: number
|
|
636
1016
|
}
|
|
637
1017
|
|
|
638
1018
|
/** Returns the version of the lindera-nodejs package. */
|
package/index.js
CHANGED
|
@@ -6,8 +6,13 @@ const { readFileSync } = require('fs')
|
|
|
6
6
|
let nativeBinding = null
|
|
7
7
|
// Which artifact actually loaded. The WASI fallback chain overwrites it with
|
|
8
8
|
// the flavor it resolved; the late native retry below leaves it alone because
|
|
9
|
-
// it only runs while no WASI candidate has been loaded.
|
|
9
|
+
// it only runs while no WASI candidate has been loaded. The take-over check
|
|
10
|
+
// after the load-failure block can also set it.
|
|
10
11
|
let __napiLoadedBindingTarget = 'native'
|
|
12
|
+
// What this loader's own `requireNative()` calls returned. The check after
|
|
13
|
+
// the load-failure block compares it with `nativeBinding` to tell a binding
|
|
14
|
+
// this loader loaded from one that code outside it put in its place.
|
|
15
|
+
let __napiRequiredNativeBinding = null
|
|
11
16
|
const loadErrors = []
|
|
12
17
|
|
|
13
18
|
const isMusl = () => {
|
|
@@ -89,8 +94,8 @@ function requireNative() {
|
|
|
89
94
|
try {
|
|
90
95
|
const binding = require('lindera-android-arm64')
|
|
91
96
|
const bindingPackageVersion = require('lindera-android-arm64/package.json').version
|
|
92
|
-
if (bindingPackageVersion !== '
|
|
93
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
97
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
98
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
94
99
|
}
|
|
95
100
|
return binding
|
|
96
101
|
} catch (e) {
|
|
@@ -105,8 +110,8 @@ function requireNative() {
|
|
|
105
110
|
try {
|
|
106
111
|
const binding = require('lindera-android-arm-eabi')
|
|
107
112
|
const bindingPackageVersion = require('lindera-android-arm-eabi/package.json').version
|
|
108
|
-
if (bindingPackageVersion !== '
|
|
109
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
113
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
114
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
110
115
|
}
|
|
111
116
|
return binding
|
|
112
117
|
} catch (e) {
|
|
@@ -126,8 +131,8 @@ function requireNative() {
|
|
|
126
131
|
try {
|
|
127
132
|
const binding = require('lindera-win32-x64-gnu')
|
|
128
133
|
const bindingPackageVersion = require('lindera-win32-x64-gnu/package.json').version
|
|
129
|
-
if (bindingPackageVersion !== '
|
|
130
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
134
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
135
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
131
136
|
}
|
|
132
137
|
return binding
|
|
133
138
|
} catch (e) {
|
|
@@ -142,8 +147,8 @@ function requireNative() {
|
|
|
142
147
|
try {
|
|
143
148
|
const binding = require('lindera-win32-x64-msvc')
|
|
144
149
|
const bindingPackageVersion = require('lindera-win32-x64-msvc/package.json').version
|
|
145
|
-
if (bindingPackageVersion !== '
|
|
146
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
150
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
147
152
|
}
|
|
148
153
|
return binding
|
|
149
154
|
} catch (e) {
|
|
@@ -159,8 +164,8 @@ function requireNative() {
|
|
|
159
164
|
try {
|
|
160
165
|
const binding = require('lindera-win32-ia32-msvc')
|
|
161
166
|
const bindingPackageVersion = require('lindera-win32-ia32-msvc/package.json').version
|
|
162
|
-
if (bindingPackageVersion !== '
|
|
163
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
167
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
168
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
164
169
|
}
|
|
165
170
|
return binding
|
|
166
171
|
} catch (e) {
|
|
@@ -175,8 +180,8 @@ function requireNative() {
|
|
|
175
180
|
try {
|
|
176
181
|
const binding = require('lindera-win32-arm64-msvc')
|
|
177
182
|
const bindingPackageVersion = require('lindera-win32-arm64-msvc/package.json').version
|
|
178
|
-
if (bindingPackageVersion !== '
|
|
179
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
183
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
184
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
180
185
|
}
|
|
181
186
|
return binding
|
|
182
187
|
} catch (e) {
|
|
@@ -194,8 +199,8 @@ function requireNative() {
|
|
|
194
199
|
try {
|
|
195
200
|
const binding = require('lindera-darwin-universal')
|
|
196
201
|
const bindingPackageVersion = require('lindera-darwin-universal/package.json').version
|
|
197
|
-
if (bindingPackageVersion !== '
|
|
198
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
202
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
199
204
|
}
|
|
200
205
|
return binding
|
|
201
206
|
} catch (e) {
|
|
@@ -210,8 +215,8 @@ function requireNative() {
|
|
|
210
215
|
try {
|
|
211
216
|
const binding = require('lindera-darwin-x64')
|
|
212
217
|
const bindingPackageVersion = require('lindera-darwin-x64/package.json').version
|
|
213
|
-
if (bindingPackageVersion !== '
|
|
214
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
218
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
219
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
215
220
|
}
|
|
216
221
|
return binding
|
|
217
222
|
} catch (e) {
|
|
@@ -226,8 +231,8 @@ function requireNative() {
|
|
|
226
231
|
try {
|
|
227
232
|
const binding = require('lindera-darwin-arm64')
|
|
228
233
|
const bindingPackageVersion = require('lindera-darwin-arm64/package.json').version
|
|
229
|
-
if (bindingPackageVersion !== '
|
|
230
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
234
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
235
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
231
236
|
}
|
|
232
237
|
return binding
|
|
233
238
|
} catch (e) {
|
|
@@ -246,8 +251,8 @@ function requireNative() {
|
|
|
246
251
|
try {
|
|
247
252
|
const binding = require('lindera-freebsd-x64')
|
|
248
253
|
const bindingPackageVersion = require('lindera-freebsd-x64/package.json').version
|
|
249
|
-
if (bindingPackageVersion !== '
|
|
250
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
254
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
255
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
251
256
|
}
|
|
252
257
|
return binding
|
|
253
258
|
} catch (e) {
|
|
@@ -262,8 +267,24 @@ function requireNative() {
|
|
|
262
267
|
try {
|
|
263
268
|
const binding = require('lindera-freebsd-arm64')
|
|
264
269
|
const bindingPackageVersion = require('lindera-freebsd-arm64/package.json').version
|
|
265
|
-
if (bindingPackageVersion !== '
|
|
266
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
270
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
271
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
272
|
+
}
|
|
273
|
+
return binding
|
|
274
|
+
} catch (e) {
|
|
275
|
+
loadErrors.push(e)
|
|
276
|
+
}
|
|
277
|
+
} else if (process.arch === 'ppc64') {
|
|
278
|
+
try {
|
|
279
|
+
return require('./lindera.freebsd-ppc64.node')
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e)
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const binding = require('lindera-freebsd-ppc64')
|
|
285
|
+
const bindingPackageVersion = require('lindera-freebsd-ppc64/package.json').version
|
|
286
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
287
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
267
288
|
}
|
|
268
289
|
return binding
|
|
269
290
|
} catch (e) {
|
|
@@ -283,8 +304,8 @@ function requireNative() {
|
|
|
283
304
|
try {
|
|
284
305
|
const binding = require('lindera-linux-x64-musl')
|
|
285
306
|
const bindingPackageVersion = require('lindera-linux-x64-musl/package.json').version
|
|
286
|
-
if (bindingPackageVersion !== '
|
|
287
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
307
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
308
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
288
309
|
}
|
|
289
310
|
return binding
|
|
290
311
|
} catch (e) {
|
|
@@ -299,8 +320,8 @@ function requireNative() {
|
|
|
299
320
|
try {
|
|
300
321
|
const binding = require('lindera-linux-x64-gnu')
|
|
301
322
|
const bindingPackageVersion = require('lindera-linux-x64-gnu/package.json').version
|
|
302
|
-
if (bindingPackageVersion !== '
|
|
303
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
323
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
324
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
304
325
|
}
|
|
305
326
|
return binding
|
|
306
327
|
} catch (e) {
|
|
@@ -317,8 +338,8 @@ function requireNative() {
|
|
|
317
338
|
try {
|
|
318
339
|
const binding = require('lindera-linux-arm64-musl')
|
|
319
340
|
const bindingPackageVersion = require('lindera-linux-arm64-musl/package.json').version
|
|
320
|
-
if (bindingPackageVersion !== '
|
|
321
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
341
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
342
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
322
343
|
}
|
|
323
344
|
return binding
|
|
324
345
|
} catch (e) {
|
|
@@ -333,8 +354,8 @@ function requireNative() {
|
|
|
333
354
|
try {
|
|
334
355
|
const binding = require('lindera-linux-arm64-gnu')
|
|
335
356
|
const bindingPackageVersion = require('lindera-linux-arm64-gnu/package.json').version
|
|
336
|
-
if (bindingPackageVersion !== '
|
|
337
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
357
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
358
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
338
359
|
}
|
|
339
360
|
return binding
|
|
340
361
|
} catch (e) {
|
|
@@ -351,8 +372,8 @@ function requireNative() {
|
|
|
351
372
|
try {
|
|
352
373
|
const binding = require('lindera-linux-arm-musleabihf')
|
|
353
374
|
const bindingPackageVersion = require('lindera-linux-arm-musleabihf/package.json').version
|
|
354
|
-
if (bindingPackageVersion !== '
|
|
355
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
375
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
376
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
356
377
|
}
|
|
357
378
|
return binding
|
|
358
379
|
} catch (e) {
|
|
@@ -367,8 +388,8 @@ function requireNative() {
|
|
|
367
388
|
try {
|
|
368
389
|
const binding = require('lindera-linux-arm-gnueabihf')
|
|
369
390
|
const bindingPackageVersion = require('lindera-linux-arm-gnueabihf/package.json').version
|
|
370
|
-
if (bindingPackageVersion !== '
|
|
371
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
391
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
392
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
372
393
|
}
|
|
373
394
|
return binding
|
|
374
395
|
} catch (e) {
|
|
@@ -385,8 +406,8 @@ function requireNative() {
|
|
|
385
406
|
try {
|
|
386
407
|
const binding = require('lindera-linux-loong64-musl')
|
|
387
408
|
const bindingPackageVersion = require('lindera-linux-loong64-musl/package.json').version
|
|
388
|
-
if (bindingPackageVersion !== '
|
|
389
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
409
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
410
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
390
411
|
}
|
|
391
412
|
return binding
|
|
392
413
|
} catch (e) {
|
|
@@ -401,8 +422,8 @@ function requireNative() {
|
|
|
401
422
|
try {
|
|
402
423
|
const binding = require('lindera-linux-loong64-gnu')
|
|
403
424
|
const bindingPackageVersion = require('lindera-linux-loong64-gnu/package.json').version
|
|
404
|
-
if (bindingPackageVersion !== '
|
|
405
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
425
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
426
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
406
427
|
}
|
|
407
428
|
return binding
|
|
408
429
|
} catch (e) {
|
|
@@ -419,8 +440,8 @@ function requireNative() {
|
|
|
419
440
|
try {
|
|
420
441
|
const binding = require('lindera-linux-riscv64-musl')
|
|
421
442
|
const bindingPackageVersion = require('lindera-linux-riscv64-musl/package.json').version
|
|
422
|
-
if (bindingPackageVersion !== '
|
|
423
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
443
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
424
445
|
}
|
|
425
446
|
return binding
|
|
426
447
|
} catch (e) {
|
|
@@ -435,8 +456,8 @@ function requireNative() {
|
|
|
435
456
|
try {
|
|
436
457
|
const binding = require('lindera-linux-riscv64-gnu')
|
|
437
458
|
const bindingPackageVersion = require('lindera-linux-riscv64-gnu/package.json').version
|
|
438
|
-
if (bindingPackageVersion !== '
|
|
439
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
459
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
440
461
|
}
|
|
441
462
|
return binding
|
|
442
463
|
} catch (e) {
|
|
@@ -452,8 +473,8 @@ function requireNative() {
|
|
|
452
473
|
try {
|
|
453
474
|
const binding = require('lindera-linux-ppc64-gnu')
|
|
454
475
|
const bindingPackageVersion = require('lindera-linux-ppc64-gnu/package.json').version
|
|
455
|
-
if (bindingPackageVersion !== '
|
|
456
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
476
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
477
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
457
478
|
}
|
|
458
479
|
return binding
|
|
459
480
|
} catch (e) {
|
|
@@ -468,8 +489,8 @@ function requireNative() {
|
|
|
468
489
|
try {
|
|
469
490
|
const binding = require('lindera-linux-s390x-gnu')
|
|
470
491
|
const bindingPackageVersion = require('lindera-linux-s390x-gnu/package.json').version
|
|
471
|
-
if (bindingPackageVersion !== '
|
|
472
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
492
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
493
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
473
494
|
}
|
|
474
495
|
return binding
|
|
475
496
|
} catch (e) {
|
|
@@ -488,8 +509,8 @@ function requireNative() {
|
|
|
488
509
|
try {
|
|
489
510
|
const binding = require('lindera-openharmony-arm64')
|
|
490
511
|
const bindingPackageVersion = require('lindera-openharmony-arm64/package.json').version
|
|
491
|
-
if (bindingPackageVersion !== '
|
|
492
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
512
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
513
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
493
514
|
}
|
|
494
515
|
return binding
|
|
495
516
|
} catch (e) {
|
|
@@ -504,8 +525,8 @@ function requireNative() {
|
|
|
504
525
|
try {
|
|
505
526
|
const binding = require('lindera-openharmony-x64')
|
|
506
527
|
const bindingPackageVersion = require('lindera-openharmony-x64/package.json').version
|
|
507
|
-
if (bindingPackageVersion !== '
|
|
508
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
528
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
529
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
509
530
|
}
|
|
510
531
|
return binding
|
|
511
532
|
} catch (e) {
|
|
@@ -520,8 +541,8 @@ function requireNative() {
|
|
|
520
541
|
try {
|
|
521
542
|
const binding = require('lindera-openharmony-arm')
|
|
522
543
|
const bindingPackageVersion = require('lindera-openharmony-arm/package.json').version
|
|
523
|
-
if (bindingPackageVersion !== '
|
|
524
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
544
|
+
if (bindingPackageVersion !== '7.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
545
|
+
throw new Error(`Native binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
525
546
|
}
|
|
526
547
|
return binding
|
|
527
548
|
} catch (e) {
|
|
@@ -585,6 +606,7 @@ const forceWasi =
|
|
|
585
606
|
|
|
586
607
|
if (!forceWasi) {
|
|
587
608
|
nativeBinding = requireNative()
|
|
609
|
+
__napiRequiredNativeBinding = nativeBinding
|
|
588
610
|
}
|
|
589
611
|
|
|
590
612
|
if (!nativeBinding || forceWasi) {
|
|
@@ -661,8 +683,8 @@ if (!nativeBinding || forceWasi) {
|
|
|
661
683
|
if (!candidateFailed) {
|
|
662
684
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
663
685
|
const bindingPackageVersion = require('lindera-wasm32-wasi/package.json').version
|
|
664
|
-
if (bindingPackageVersion !== '
|
|
665
|
-
throw new Error(`WASI binding package version mismatch, expected
|
|
686
|
+
if (bindingPackageVersion !== '7.0.0') {
|
|
687
|
+
throw new Error(`WASI binding package version mismatch, expected 7.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
666
688
|
}
|
|
667
689
|
}
|
|
668
690
|
wasiBinding = require('lindera-wasm32-wasi')
|
|
@@ -686,6 +708,7 @@ if (!nativeBinding || forceWasi) {
|
|
|
686
708
|
!__napiWasiFlavorRequested
|
|
687
709
|
) {
|
|
688
710
|
nativeBinding = requireNative()
|
|
711
|
+
__napiRequiredNativeBinding = nativeBinding
|
|
689
712
|
}
|
|
690
713
|
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
691
714
|
const error = new Error(
|
|
@@ -713,6 +736,40 @@ if (!nativeBinding) {
|
|
|
713
736
|
throw new Error(`Failed to load native binding`)
|
|
714
737
|
}
|
|
715
738
|
|
|
739
|
+
// A package can patch its own fallback in front of the load-failure check
|
|
740
|
+
// above, e.g. a WebContainer download through `napi-postinstall/fallback`.
|
|
741
|
+
// That fallback swaps `nativeBinding` for a generated WASI loader, which has
|
|
742
|
+
// already stamped its own flavor, while the target above still says 'native'.
|
|
743
|
+
// Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
|
|
744
|
+
// export reports the wrong artifact. Three limits keep the conflict check:
|
|
745
|
+
// - only a binding this loader did not load itself, so a native addon whose
|
|
746
|
+
// `#[napi(module_exports)]` hook claims the name is still rejected;
|
|
747
|
+
// - only an own data property, read through its descriptor, so no addon
|
|
748
|
+
// getter runs here, and it must read back the same, as the stamp reads it;
|
|
749
|
+
// - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
|
|
750
|
+
// chain can report ('wasm32-wasi' for a package without a WASI target).
|
|
751
|
+
// This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
|
|
752
|
+
if (
|
|
753
|
+
__napiLoadedBindingTarget === 'native' &&
|
|
754
|
+
nativeBinding !== __napiRequiredNativeBinding
|
|
755
|
+
) {
|
|
756
|
+
try {
|
|
757
|
+
const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
|
|
758
|
+
nativeBinding,
|
|
759
|
+
'__napiBindingTarget',
|
|
760
|
+
)
|
|
761
|
+
if (
|
|
762
|
+
__napiBindingTargetDescriptor &&
|
|
763
|
+
__napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
|
|
764
|
+
nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
|
|
765
|
+
) {
|
|
766
|
+
__napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
|
|
767
|
+
}
|
|
768
|
+
} catch {
|
|
769
|
+
// keep 'native'
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
716
773
|
function __napiStampBindingTarget(exportsObject, target) {
|
|
717
774
|
if (
|
|
718
775
|
Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
|
|
@@ -782,6 +839,7 @@ module.exports.Dictionary = nativeBinding.Dictionary
|
|
|
782
839
|
module.exports.JsDictionary = nativeBinding.JsDictionary
|
|
783
840
|
module.exports.Metadata = nativeBinding.Metadata
|
|
784
841
|
module.exports.JsMetadata = nativeBinding.JsMetadata
|
|
842
|
+
module.exports.Mode = nativeBinding.Mode
|
|
785
843
|
module.exports.Schema = nativeBinding.Schema
|
|
786
844
|
module.exports.JsSchema = nativeBinding.JsSchema
|
|
787
845
|
module.exports.Tokenizer = nativeBinding.Tokenizer
|
|
@@ -792,10 +850,11 @@ module.exports.UserDictionary = nativeBinding.UserDictionary
|
|
|
792
850
|
module.exports.JsUserDictionary = nativeBinding.JsUserDictionary
|
|
793
851
|
module.exports.buildDictionary = nativeBinding.buildDictionary
|
|
794
852
|
module.exports.buildUserDictionary = nativeBinding.buildUserDictionary
|
|
853
|
+
module.exports.buildUserDictionaryFor = nativeBinding.buildUserDictionaryFor
|
|
795
854
|
module.exports.exportModel = nativeBinding.exportModel
|
|
796
855
|
module.exports.JsFieldType = nativeBinding.JsFieldType
|
|
797
|
-
module.exports.JsMode = nativeBinding.JsMode
|
|
798
856
|
module.exports.loadDictionary = nativeBinding.loadDictionary
|
|
799
857
|
module.exports.loadUserDictionary = nativeBinding.loadUserDictionary
|
|
858
|
+
module.exports.loadUserDictionaryFor = nativeBinding.loadUserDictionaryFor
|
|
800
859
|
module.exports.train = nativeBinding.train
|
|
801
860
|
module.exports.version = nativeBinding.version
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lindera",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Node.js bindings for Lindera morphological analysis engine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"index.d.ts"
|
|
43
43
|
],
|
|
44
44
|
"optionalDependencies": {
|
|
45
|
-
"lindera-darwin-arm64": "
|
|
46
|
-
"lindera-darwin-x64": "
|
|
47
|
-
"lindera-linux-arm64-gnu": "
|
|
48
|
-
"lindera-linux-x64-gnu": "
|
|
49
|
-
"lindera-win32-arm64-msvc": "
|
|
50
|
-
"lindera-win32-x64-msvc": "
|
|
45
|
+
"lindera-darwin-arm64": "7.0.0",
|
|
46
|
+
"lindera-darwin-x64": "7.0.0",
|
|
47
|
+
"lindera-linux-arm64-gnu": "7.0.0",
|
|
48
|
+
"lindera-linux-x64-gnu": "7.0.0",
|
|
49
|
+
"lindera-win32-arm64-msvc": "7.0.0",
|
|
50
|
+
"lindera-win32-x64-msvc": "7.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
|
53
53
|
"type": "git",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"napi"
|
|
65
65
|
],
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@napi-rs/cli": "3.10.
|
|
67
|
+
"@napi-rs/cli": "3.10.12",
|
|
68
68
|
"typescript": "^7.0.2"
|
|
69
69
|
}
|
|
70
70
|
}
|