garu-ko 0.5.0 → 0.5.2
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/dist/index.js +18 -25
- package/models/cnn2.bin +0 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63,34 +63,27 @@ export class Garu {
|
|
|
63
63
|
}
|
|
64
64
|
modelBytes = new Uint8Array(await response.arrayBuffer());
|
|
65
65
|
}
|
|
66
|
-
// Construct the WASM analyzer
|
|
67
|
-
const wasmInstance = new wasmModule.GaruWasm(modelBytes);
|
|
68
66
|
// Load CNN reranker
|
|
69
|
-
let cnnBytes
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
cnnBytes = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const cnnUrl = new URL('../models/cnn2.bin', import.meta.url).href;
|
|
81
|
-
const cnnResp = await fetch(cnnUrl);
|
|
82
|
-
if (cnnResp.ok) {
|
|
83
|
-
cnnBytes = new Uint8Array(await cnnResp.arrayBuffer());
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
// CNN loading is best-effort
|
|
67
|
+
let cnnBytes;
|
|
68
|
+
if (isNode) {
|
|
69
|
+
const { readFile } = await import('fs/promises');
|
|
70
|
+
const { fileURLToPath } = await import('url');
|
|
71
|
+
const { join, dirname } = await import('path');
|
|
72
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
73
|
+
const buf = await readFile(join(dir, '..', 'models', 'cnn2.bin'));
|
|
74
|
+
cnnBytes = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
89
75
|
}
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
else {
|
|
77
|
+
const cnnUrl = new URL('../models/cnn2.bin', import.meta.url).href;
|
|
78
|
+
const cnnResp = await fetch(cnnUrl);
|
|
79
|
+
if (!cnnResp.ok) {
|
|
80
|
+
throw new Error(`Failed to fetch CNN model from ${cnnUrl}: ${cnnResp.status}`);
|
|
81
|
+
}
|
|
82
|
+
cnnBytes = new Uint8Array(await cnnResp.arrayBuffer());
|
|
92
83
|
}
|
|
93
|
-
|
|
84
|
+
// Construct the WASM analyzer with both models
|
|
85
|
+
const wasmInstance = new wasmModule.GaruWasm(modelBytes, cnnBytes);
|
|
86
|
+
return new Garu(wasmInstance, modelBytes.byteLength + cnnBytes.byteLength);
|
|
94
87
|
}
|
|
95
88
|
/**
|
|
96
89
|
* Analyze Korean text, returning morphological tokens with scores.
|
package/models/cnn2.bin
CHANGED
|
Binary file
|