garu-ko 0.2.1 → 0.2.3

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
@@ -85,15 +85,18 @@ interface Token {
85
85
  }
86
86
  ```
87
87
 
88
- Set `options.topN > 1` to get N-best results as an array.
88
+ Set `options.topN > 1` to get N-best results as an array. Note: topN > 1 is not yet fully supported and may return fewer results.
89
89
 
90
- ### `garu.nouns(text): string[]`
90
+ ### `garu.nouns(text, options?): string[]`
91
91
 
92
- Extract nouns (NNG, NNP) from text.
92
+ Extract nouns (NNG, NNP) from text. Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
93
93
 
94
94
  ```js
95
95
  garu.nouns('인공지능 기술이 발전했다');
96
96
  // ["인공", "지능", "기술", "발전"]
97
+
98
+ garu.nouns('AI 기술이 발전했다', { includeSL: true });
99
+ // ["AI", "기술", "발전"]
97
100
  ```
98
101
 
99
102
  ### `garu.tokenize(text): string[]`
package/dist/index.d.ts CHANGED
@@ -14,6 +14,9 @@ export interface AnalyzeResult {
14
14
  export interface AnalyzeOptions {
15
15
  topN?: number;
16
16
  }
17
+ export interface NounsOptions {
18
+ includeSL?: boolean;
19
+ }
17
20
  export interface LoadOptions {
18
21
  modelData?: ArrayBuffer;
19
22
  modelUrl?: string;
@@ -41,6 +44,8 @@ export declare class Garu {
41
44
  *
42
45
  * When `options.topN` is greater than 1, returns an array of N-best results.
43
46
  * Otherwise returns a single AnalyzeResult.
47
+ *
48
+ * Note: topN > 1 is not yet fully supported and may return fewer results.
44
49
  */
45
50
  analyze(text: string, options?: AnalyzeOptions): AnalyzeResult | AnalyzeResult[];
46
51
  /**
@@ -49,8 +54,9 @@ export declare class Garu {
49
54
  tokenize(text: string): string[];
50
55
  /**
51
56
  * Extract nouns (NNG, NNP) from text.
57
+ * Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
52
58
  */
53
- nouns(text: string): string[];
59
+ nouns(text: string, options?: NounsOptions): string[];
54
60
  /**
55
61
  * Whether the WASM analyzer is loaded and ready.
56
62
  */
package/dist/index.js CHANGED
@@ -71,8 +71,13 @@ export class Garu {
71
71
  *
72
72
  * When `options.topN` is greater than 1, returns an array of N-best results.
73
73
  * Otherwise returns a single AnalyzeResult.
74
+ *
75
+ * Note: topN > 1 is not yet fully supported and may return fewer results.
74
76
  */
75
77
  analyze(text, options) {
78
+ if (!this._loaded) {
79
+ throw new Error('Garu instance has been destroyed');
80
+ }
76
81
  const topN = options?.topN ?? 1;
77
82
  if (topN > 1) {
78
83
  if (text === '') {
@@ -89,6 +94,9 @@ export class Garu {
89
94
  * Quick tokenisation — returns an array of surface-form strings.
90
95
  */
91
96
  tokenize(text) {
97
+ if (!this._loaded) {
98
+ throw new Error('Garu instance has been destroyed');
99
+ }
92
100
  if (text === '') {
93
101
  return [];
94
102
  }
@@ -96,14 +104,19 @@ export class Garu {
96
104
  }
97
105
  /**
98
106
  * Extract nouns (NNG, NNP) from text.
107
+ * Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
99
108
  */
100
- nouns(text) {
109
+ nouns(text, options) {
110
+ if (!this._loaded) {
111
+ throw new Error('Garu instance has been destroyed');
112
+ }
101
113
  if (text === '') {
102
114
  return [];
103
115
  }
104
116
  const result = this._wasm.analyze(text);
117
+ const includeSL = options?.includeSL ?? false;
105
118
  return result.tokens
106
- .filter((t) => t.pos === 'NNG' || t.pos === 'NNP')
119
+ .filter((t) => t.pos === 'NNG' || t.pos === 'NNP' || (includeSL && t.pos === 'SL'))
107
120
  .map((t) => t.text);
108
121
  }
109
122
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Ultra-lightweight Korean morphological analyzer for the web (1.7MB model, WASM 93KB, F1 95.3%)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/pkg/garu_wasm.js CHANGED
@@ -82,6 +82,7 @@ export class GaruWasm {
82
82
  }
83
83
  }
84
84
  if (Symbol.dispose) GaruWasm.prototype[Symbol.dispose] = GaruWasm.prototype.free;
85
+ import * as import1 from "./snippets/garu-core-ea50edba4dc5fdae/inline0.js"
85
86
 
86
87
  function __wbg_get_imports() {
87
88
  const import0 = {
@@ -108,10 +109,6 @@ function __wbg_get_imports() {
108
109
  const ret = new Object();
109
110
  return ret;
110
111
  },
111
- __wbg_now_16f0c993d5dd6c27: function() {
112
- const ret = Date.now();
113
- return ret;
114
- },
115
112
  __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
116
113
  arg0[arg1 >>> 0] = arg2;
117
114
  },
@@ -146,6 +143,7 @@ function __wbg_get_imports() {
146
143
  return {
147
144
  __proto__: null,
148
145
  "./garu_wasm_bg.js": import0,
146
+ "./snippets/garu-core-ea50edba4dc5fdae/inline0.js": import1,
149
147
  };
150
148
  }
151
149
 
Binary file
package/pkg/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-wasm",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
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(); }