garu-ko 0.9.11 → 0.9.13

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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  **Browser-native Korean morphological analyzer.** No server required.
4
4
 
5
- - **1.4MB model** bundled in npm package (no CDN needed)
6
- - **401KB WASM** engine (172KB gzipped) -- runs in any modern browser
7
- - **F1 95.8%** on 9k human-verified gold testset (ep_norm), **F1 91.0%** on a held-out 2025 spoken-language set
5
+ - **1.2MB model** bundled in npm package (no CDN needed)
6
+ - **412KB WASM** engine (176KB gzipped) -- runs in any modern browser
7
+ - **F1 95.8%** on 9k human-verified gold testset (ep_norm), **F1 91.1%** on a held-out 2025 spoken-language set
8
8
  - **~1ms** inference per sentence
9
9
  - **Offline-ready** -- works without network
10
10
  - **[Live Demo](https://garu.zerry.co.kr)** -- try it in your browser
@@ -104,6 +104,38 @@ garu.nouns('AI 기술이 발전했다', { includeSL: true });
104
104
 
105
105
  Returns surface-form strings only. Lightweight alternative to `analyze()`.
106
106
 
107
+ ### `garu.addUserWord(surface, pos, freq?): void`
108
+
109
+ Register a domain word at runtime — **no model rebuild required**. The word is injected into the lattice and competes with the built-in dictionary on the same cost scale.
110
+
111
+ ```js
112
+ garu.nouns('인공지능 기술이 발전했다');
113
+ // ["인공", "지능", "기술", "발전"]
114
+
115
+ garu.addUserWord('인공지능', 'NNG');
116
+ garu.nouns('인공지능 기술이 발전했다');
117
+ // ["인공지능", "기술", "발전"]
118
+ ```
119
+
120
+ `freq` uses the same scale as the built-in dictionary — higher values are more likely to beat a split analysis (default 5000). A user word cannot span whitespace.
121
+
122
+ Useful for product names, organisations and neologisms that a general corpus does not cover, especially when indexing them as single search terms.
123
+
124
+ ### `garu.addUserWords(words): void`
125
+
126
+ Register several words at once.
127
+
128
+ ```js
129
+ garu.addUserWords([
130
+ { surface: '전세사기', pos: 'NNG' },
131
+ { surface: '탄소중립', pos: 'NNG', freq: 20000 },
132
+ ]);
133
+ ```
134
+
135
+ ### `garu.clearUserWords(): void` / `garu.userWordCount(): number`
136
+
137
+ Remove every registered user word, or count them. With none registered, analysis is identical to using the built-in dictionary alone.
138
+
107
139
  ### `garu.destroy(): void`
108
140
 
109
141
  Free WASM memory. Instance is unusable after this call.
@@ -133,19 +165,19 @@ await search(db, { term: '먹다' }) // ← matches
133
165
  ## FAQ
134
166
 
135
167
  **What is garu-ko?**
136
- garu-ko (가루/Garu) is a browser-native Korean morphological analyzer. A 1.4MB model and a 401KB WASM engine run entirely in the browser, so it segments Korean text, tags parts of speech, extracts nouns, and tokenizes with no server and no network.
168
+ garu-ko (가루/Garu) is a browser-native Korean morphological analyzer. A 1.2MB model and a 412KB WASM engine run entirely in the browser, so it segments Korean text, tags parts of speech, extracts nouns, and tokenizes with no server and no network.
137
169
 
138
170
  **Does it need a server or API?**
139
171
  No. It runs 100% client-side via WebAssembly. After the initial load there is no backend call, so it works offline and inside browser extensions, service-worker PWAs, and intranet apps.
140
172
 
141
173
  **How accurate is it?**
142
- F1 95.8% on a 9,000-sentence human-verified gold testset (ep_norm), and F1 91.0% on a held-out 2025 spoken-language evaluation set.
174
+ F1 95.8% on a 9,000-sentence human-verified gold testset (ep_norm), and F1 91.1% on a held-out 2025 spoken-language evaluation set.
143
175
 
144
176
  **Which POS tagset does it use?**
145
177
  The Sejong tagset (42 tags) from the National Institute of Korean Language — NNG/NNP for nouns, VV/VA for verbs/adjectives, particles, endings, and symbols.
146
178
 
147
179
  **Does it use a neural network?**
148
- No. It combines a codebook, an eojeol cache, sentence-level N-best trigram Viterbi, and deterministic post-processing rules, so output is deterministic and reproducible.
180
+ No. It combines a codebook, an eojeol cache, sentence-level N-best trigram Viterbi, deterministic post-processing rules, and a linear reranking perceptron — not a neural network — so output is deterministic and reproducible.
149
181
 
150
182
  **Where does it run besides the browser?**
151
183
  The same `npm install garu-ko` works in browser ESM, Node.js 18+, Bun, and Deno with one API.
package/dist/core.d.ts CHANGED
@@ -19,6 +19,13 @@ export interface AnalyzeOptions {
19
19
  export interface NounsOptions {
20
20
  includeSL?: boolean;
21
21
  }
22
+ /** A domain word registered at runtime via `addUserWord` / `addUserWords`. */
23
+ export interface UserWord {
24
+ surface: string;
25
+ pos: POS;
26
+ /** Dictionary-scale frequency; higher wins over a split analysis. Default 5000. */
27
+ freq?: number;
28
+ }
22
29
  export interface LoadOptions {
23
30
  modelData?: ArrayBuffer;
24
31
  modelUrl?: string;
@@ -60,6 +67,27 @@ export declare class GaruBase {
60
67
  * Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
61
68
  */
62
69
  nouns(text: string, options?: NounsOptions): string[];
70
+ /**
71
+ * Register a domain word so it is recognised as a single token.
72
+ *
73
+ * No model rebuild is needed — the word is injected into the lattice and
74
+ * competes with the built-in dictionary on the same cost scale. A higher
75
+ * `freq` makes it more likely to win over a split analysis (default 5000).
76
+ * A word cannot span whitespace.
77
+ */
78
+ addUserWord(surface: string, pos: POS, freq?: number): void;
79
+ /**
80
+ * Register several domain words at once.
81
+ */
82
+ addUserWords(words: UserWord[]): void;
83
+ /**
84
+ * Remove every registered user word, restoring the built-in behaviour.
85
+ */
86
+ clearUserWords(): void;
87
+ /**
88
+ * Number of registered user words.
89
+ */
90
+ userWordCount(): number;
63
91
  /**
64
92
  * Whether the WASM analyzer is loaded and ready.
65
93
  */
package/dist/core.js CHANGED
@@ -68,6 +68,46 @@ export class GaruBase {
68
68
  .filter((t) => t.pos === 'NNG' || t.pos === 'NNP' || (includeSL && t.pos === 'SL'))
69
69
  .map((t) => t.text);
70
70
  }
71
+ /**
72
+ * Register a domain word so it is recognised as a single token.
73
+ *
74
+ * No model rebuild is needed — the word is injected into the lattice and
75
+ * competes with the built-in dictionary on the same cost scale. A higher
76
+ * `freq` makes it more likely to win over a split analysis (default 5000).
77
+ * A word cannot span whitespace.
78
+ */
79
+ addUserWord(surface, pos, freq) {
80
+ if (!this._loaded) {
81
+ throw new Error('Garu instance has been destroyed');
82
+ }
83
+ this._wasm.add_user_word(surface, pos, freq);
84
+ }
85
+ /**
86
+ * Register several domain words at once.
87
+ */
88
+ addUserWords(words) {
89
+ for (const w of words) {
90
+ this.addUserWord(w.surface, w.pos, w.freq);
91
+ }
92
+ }
93
+ /**
94
+ * Remove every registered user word, restoring the built-in behaviour.
95
+ */
96
+ clearUserWords() {
97
+ if (!this._loaded) {
98
+ throw new Error('Garu instance has been destroyed');
99
+ }
100
+ this._wasm.clear_user_words();
101
+ }
102
+ /**
103
+ * Number of registered user words.
104
+ */
105
+ userWordCount() {
106
+ if (!this._loaded) {
107
+ throw new Error('Garu instance has been destroyed');
108
+ }
109
+ return this._wasm.user_word_count();
110
+ }
71
111
  /**
72
112
  * Whether the WASM analyzer is loaded and ready.
73
113
  */
package/models/base.gmdl CHANGED
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.9.11",
4
- "description": "Ultra-lightweight Korean morphological analyzer for the web (1MB model, WASM, F1 93.7% NIKL MP)",
3
+ "version": "0.9.13",
4
+ "description": "Ultra-lightweight Korean morphological analyzer for the web (1.2MB model, WASM, F1 95.8% gold testset)",
5
5
  "type": "module",
6
6
  "main": "dist/node.js",
7
7
  "browser": "dist/browser.js",
@@ -4,10 +4,22 @@
4
4
  export class GaruWasm {
5
5
  free(): void;
6
6
  [Symbol.dispose](): void;
7
+ /**
8
+ * 사용자 단어 등록 — 모델 리빌드 없이 도메인 어휘를 인식시킨다.
9
+ */
10
+ add_user_word(surface: string, pos: string, freq?: number | null): void;
7
11
  analyze(text: string): any;
8
12
  analyze_topn(text: string, n: number): any;
13
+ /**
14
+ * 등록된 사용자 단어를 모두 제거.
15
+ */
16
+ clear_user_words(): void;
9
17
  constructor(model_data: Uint8Array, normalize_jamo?: boolean | null);
10
18
  tokenize(text: string): any;
19
+ /**
20
+ * 등록된 사용자 단어 수.
21
+ */
22
+ user_word_count(): number;
11
23
  static version(): string;
12
24
  }
13
25
 
@@ -16,10 +28,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
16
28
  export interface InitOutput {
17
29
  readonly memory: WebAssembly.Memory;
18
30
  readonly __wbg_garuwasm_free: (a: number, b: number) => void;
31
+ readonly garuwasm_add_user_word: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
19
32
  readonly garuwasm_analyze: (a: number, b: number, c: number, d: number) => void;
20
33
  readonly garuwasm_analyze_topn: (a: number, b: number, c: number, d: number, e: number) => void;
34
+ readonly garuwasm_clear_user_words: (a: number) => void;
21
35
  readonly garuwasm_new: (a: number, b: number, c: number, d: number) => void;
22
36
  readonly garuwasm_tokenize: (a: number, b: number, c: number, d: number) => void;
37
+ readonly garuwasm_user_word_count: (a: number) => number;
23
38
  readonly garuwasm_version: (a: number) => void;
24
39
  readonly __wbindgen_export: (a: number, b: number) => number;
25
40
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
package/pkg/garu_wasm.js CHANGED
@@ -11,6 +11,29 @@ export class GaruWasm {
11
11
  const ptr = this.__destroy_into_raw();
12
12
  wasm.__wbg_garuwasm_free(ptr, 0);
13
13
  }
14
+ /**
15
+ * 사용자 단어 등록 — 모델 리빌드 없이 도메인 어휘를 인식시킨다.
16
+ * @param {string} surface
17
+ * @param {string} pos
18
+ * @param {number | null} [freq]
19
+ */
20
+ add_user_word(surface, pos, freq) {
21
+ try {
22
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
23
+ const ptr0 = passStringToWasm0(surface, wasm.__wbindgen_export, wasm.__wbindgen_export2);
24
+ const len0 = WASM_VECTOR_LEN;
25
+ const ptr1 = passStringToWasm0(pos, wasm.__wbindgen_export, wasm.__wbindgen_export2);
26
+ const len1 = WASM_VECTOR_LEN;
27
+ wasm.garuwasm_add_user_word(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(freq) ? 0x100000001 : (freq) >>> 0);
28
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
29
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
30
+ if (r1) {
31
+ throw takeObject(r0);
32
+ }
33
+ } finally {
34
+ wasm.__wbindgen_add_to_stack_pointer(16);
35
+ }
36
+ }
14
37
  /**
15
38
  * @param {string} text
16
39
  * @returns {any}
@@ -54,6 +77,12 @@ export class GaruWasm {
54
77
  wasm.__wbindgen_add_to_stack_pointer(16);
55
78
  }
56
79
  }
80
+ /**
81
+ * 등록된 사용자 단어를 모두 제거.
82
+ */
83
+ clear_user_words() {
84
+ wasm.garuwasm_clear_user_words(this.__wbg_ptr);
85
+ }
57
86
  /**
58
87
  * @param {Uint8Array} model_data
59
88
  * @param {boolean | null} [normalize_jamo]
@@ -98,6 +127,14 @@ export class GaruWasm {
98
127
  wasm.__wbindgen_add_to_stack_pointer(16);
99
128
  }
100
129
  }
130
+ /**
131
+ * 등록된 사용자 단어 수.
132
+ * @returns {number}
133
+ */
134
+ user_word_count() {
135
+ const ret = wasm.garuwasm_user_word_count(this.__wbg_ptr);
136
+ return ret >>> 0;
137
+ }
101
138
  /**
102
139
  * @returns {string}
103
140
  */
@@ -119,7 +156,7 @@ export class GaruWasm {
119
156
  }
120
157
  }
121
158
  if (Symbol.dispose) GaruWasm.prototype[Symbol.dispose] = GaruWasm.prototype.free;
122
- import * as import1 from "./snippets/garu-core-625a28070cd87abb/inline0.js"
159
+ import * as import1 from "./snippets/garu-core-311e0dace2b123c4/inline0.js"
123
160
 
124
161
  function __wbg_get_imports() {
125
162
  const import0 = {
@@ -178,7 +215,7 @@ function __wbg_get_imports() {
178
215
  return {
179
216
  __proto__: null,
180
217
  "./garu_wasm_bg.js": import0,
181
- "./snippets/garu-core-625a28070cd87abb/inline0.js": import1,
218
+ "./snippets/garu-core-311e0dace2b123c4/inline0.js": import1,
182
219
  };
183
220
  }
184
221
 
Binary file
@@ -2,10 +2,13 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_garuwasm_free: (a: number, b: number) => void;
5
+ export const garuwasm_add_user_word: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
5
6
  export const garuwasm_analyze: (a: number, b: number, c: number, d: number) => void;
6
7
  export const garuwasm_analyze_topn: (a: number, b: number, c: number, d: number, e: number) => void;
8
+ export const garuwasm_clear_user_words: (a: number) => void;
7
9
  export const garuwasm_new: (a: number, b: number, c: number, d: number) => void;
8
10
  export const garuwasm_tokenize: (a: number, b: number, c: number, d: number) => void;
11
+ export const garuwasm_user_word_count: (a: number) => number;
9
12
  export const garuwasm_version: (a: number) => void;
10
13
  export const __wbindgen_export: (a: number, b: number) => number;
11
14
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
package/pkg/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-wasm",
3
3
  "type": "module",
4
- "version": "0.9.11",
4
+ "version": "0.9.13",
5
5
  "files": [
6
6
  "garu_wasm_bg.wasm",
7
7
  "garu_wasm.js",
@@ -0,0 +1 @@
1
+ export function performance_now() { return performance.now(); }
@@ -0,0 +1 @@
1
+ export function performance_now() { return performance.now(); }