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 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 = null;
70
- try {
71
- if (isNode) {
72
- const { readFile } = await import('fs/promises');
73
- const { fileURLToPath } = await import('url');
74
- const { join, dirname } = await import('path');
75
- const dir = dirname(fileURLToPath(import.meta.url));
76
- const buf = await readFile(join(dir, '..', 'models', 'cnn2.bin'));
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
- if (cnnBytes) {
91
- wasmInstance.load_cnn(cnnBytes);
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
- return new Garu(wasmInstance, modelBytes.byteLength + (cnnBytes?.byteLength ?? 0));
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Ultra-lightweight Korean morphological analyzer for the web (1.7MB model, WASM, F1 93.7%)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",