garu-ko 0.2.2 → 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
@@ -87,13 +87,16 @@ interface Token {
87
87
 
88
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;
@@ -51,8 +54,9 @@ export declare class Garu {
51
54
  tokenize(text: string): string[];
52
55
  /**
53
56
  * Extract nouns (NNG, NNP) from text.
57
+ * Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
54
58
  */
55
- nouns(text: string): string[];
59
+ nouns(text: string, options?: NounsOptions): string[];
56
60
  /**
57
61
  * Whether the WASM analyzer is loaded and ready.
58
62
  */
package/dist/index.js CHANGED
@@ -104,8 +104,9 @@ export class Garu {
104
104
  }
105
105
  /**
106
106
  * Extract nouns (NNG, NNP) from text.
107
+ * Set `options.includeSL` to also include foreign tokens (SL) like "AI", "BM25".
107
108
  */
108
- nouns(text) {
109
+ nouns(text, options) {
109
110
  if (!this._loaded) {
110
111
  throw new Error('Garu instance has been destroyed');
111
112
  }
@@ -113,8 +114,9 @@ export class Garu {
113
114
  return [];
114
115
  }
115
116
  const result = this._wasm.analyze(text);
117
+ const includeSL = options?.includeSL ?? false;
116
118
  return result.tokens
117
- .filter((t) => t.pos === 'NNG' || t.pos === 'NNP')
119
+ .filter((t) => t.pos === 'NNG' || t.pos === 'NNP' || (includeSL && t.pos === 'SL'))
118
120
  .map((t) => t.text);
119
121
  }
120
122
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.2.2",
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",
Binary file