garu-ko 0.1.0
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.d.ts +62 -0
- package/dist/index.js +97 -0
- package/models/base.gmdl +0 -0
- package/package.json +26 -0
- package/pkg/garu_wasm.d.ts +52 -0
- package/pkg/garu_wasm.js +343 -0
- package/pkg/garu_wasm_bg.wasm +0 -0
- package/pkg/garu_wasm_bg.wasm.d.ts +15 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type POS = 'NNG' | 'NNP' | 'NNB' | 'NR' | 'NP' | 'VV' | 'VA' | 'VX' | 'VCP' | 'VCN' | 'MAG' | 'MAJ' | 'MM' | 'IC' | 'JKS' | 'JKC' | 'JKG' | 'JKO' | 'JKB' | 'JKV' | 'JKQ' | 'JX' | 'JC' | 'EP' | 'EF' | 'EC' | 'ETN' | 'ETM' | 'XPN' | 'XSN' | 'XSV' | 'XSA' | 'XR' | 'SF' | 'SP' | 'SS' | 'SE' | 'SO' | 'SW' | 'SH' | 'SL' | 'SN';
|
|
2
|
+
export interface Token {
|
|
3
|
+
text: string;
|
|
4
|
+
pos: POS;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
score?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface AnalyzeResult {
|
|
10
|
+
tokens: Token[];
|
|
11
|
+
score: number;
|
|
12
|
+
elapsed: number;
|
|
13
|
+
}
|
|
14
|
+
export interface AnalyzeOptions {
|
|
15
|
+
topN?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface LoadOptions {
|
|
18
|
+
modelData?: ArrayBuffer;
|
|
19
|
+
modelUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ModelInfo {
|
|
22
|
+
version: string;
|
|
23
|
+
size: number;
|
|
24
|
+
accuracy: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class Garu {
|
|
27
|
+
private _wasm;
|
|
28
|
+
private _loaded;
|
|
29
|
+
private _modelSize;
|
|
30
|
+
private constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Load the WASM module and model data, returning a ready-to-use Garu instance.
|
|
33
|
+
*
|
|
34
|
+
* @param options.modelData - Provide model bytes directly as an ArrayBuffer
|
|
35
|
+
* @param options.modelUrl - Fetch model from this URL
|
|
36
|
+
* If neither is provided, the model is fetched from the default CDN URL.
|
|
37
|
+
*/
|
|
38
|
+
static load(options?: LoadOptions): Promise<Garu>;
|
|
39
|
+
/**
|
|
40
|
+
* Analyze Korean text, returning morphological tokens with scores.
|
|
41
|
+
*
|
|
42
|
+
* When `options.topN` is greater than 1, returns an array of N-best results.
|
|
43
|
+
* Otherwise returns a single AnalyzeResult.
|
|
44
|
+
*/
|
|
45
|
+
analyze(text: string, options?: AnalyzeOptions): AnalyzeResult | AnalyzeResult[];
|
|
46
|
+
/**
|
|
47
|
+
* Quick tokenisation — returns an array of surface-form strings.
|
|
48
|
+
*/
|
|
49
|
+
tokenize(text: string): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Whether the WASM analyzer is loaded and ready.
|
|
52
|
+
*/
|
|
53
|
+
isLoaded(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Return metadata about the loaded model.
|
|
56
|
+
*/
|
|
57
|
+
modelInfo(): ModelInfo;
|
|
58
|
+
/**
|
|
59
|
+
* Free the WASM instance and mark this Garu as unloaded.
|
|
60
|
+
*/
|
|
61
|
+
destroy(): void;
|
|
62
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const DEFAULT_MODEL_URL = 'https://cdn.jsdelivr.net/npm/garu@latest/models/base.gmdl';
|
|
2
|
+
const EMPTY_RESULT = Object.freeze({
|
|
3
|
+
tokens: [],
|
|
4
|
+
score: 0,
|
|
5
|
+
elapsed: 0,
|
|
6
|
+
});
|
|
7
|
+
export class Garu {
|
|
8
|
+
constructor(wasmInstance, modelSize) {
|
|
9
|
+
this._wasm = wasmInstance;
|
|
10
|
+
this._loaded = true;
|
|
11
|
+
this._modelSize = modelSize;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Load the WASM module and model data, returning a ready-to-use Garu instance.
|
|
15
|
+
*
|
|
16
|
+
* @param options.modelData - Provide model bytes directly as an ArrayBuffer
|
|
17
|
+
* @param options.modelUrl - Fetch model from this URL
|
|
18
|
+
* If neither is provided, the model is fetched from the default CDN URL.
|
|
19
|
+
*/
|
|
20
|
+
static async load(options) {
|
|
21
|
+
// Dynamic import of the WASM glue module and initialise it
|
|
22
|
+
// @ts-ignore dynamic WASM import
|
|
23
|
+
const wasmModule = await import('../pkg/garu_wasm.js');
|
|
24
|
+
await wasmModule.default();
|
|
25
|
+
// Resolve model bytes
|
|
26
|
+
let modelBytes;
|
|
27
|
+
if (options?.modelData) {
|
|
28
|
+
modelBytes = new Uint8Array(options.modelData);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const url = options?.modelUrl ?? DEFAULT_MODEL_URL;
|
|
32
|
+
const response = await fetch(url);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`Failed to fetch model from ${url}: ${response.status} ${response.statusText}`);
|
|
35
|
+
}
|
|
36
|
+
const buffer = await response.arrayBuffer();
|
|
37
|
+
modelBytes = new Uint8Array(buffer);
|
|
38
|
+
}
|
|
39
|
+
// Construct the WASM analyzer
|
|
40
|
+
const wasmInstance = new wasmModule.GaruWasm(modelBytes);
|
|
41
|
+
return new Garu(wasmInstance, modelBytes.byteLength);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Analyze Korean text, returning morphological tokens with scores.
|
|
45
|
+
*
|
|
46
|
+
* When `options.topN` is greater than 1, returns an array of N-best results.
|
|
47
|
+
* Otherwise returns a single AnalyzeResult.
|
|
48
|
+
*/
|
|
49
|
+
analyze(text, options) {
|
|
50
|
+
const topN = options?.topN ?? 1;
|
|
51
|
+
if (topN > 1) {
|
|
52
|
+
if (text === '') {
|
|
53
|
+
return [{ ...EMPTY_RESULT, tokens: [] }];
|
|
54
|
+
}
|
|
55
|
+
return this._wasm.analyze_topn(text, topN);
|
|
56
|
+
}
|
|
57
|
+
if (text === '') {
|
|
58
|
+
return { ...EMPTY_RESULT, tokens: [] };
|
|
59
|
+
}
|
|
60
|
+
return this._wasm.analyze(text);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Quick tokenisation — returns an array of surface-form strings.
|
|
64
|
+
*/
|
|
65
|
+
tokenize(text) {
|
|
66
|
+
if (text === '') {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return this._wasm.tokenize(text);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether the WASM analyzer is loaded and ready.
|
|
73
|
+
*/
|
|
74
|
+
isLoaded() {
|
|
75
|
+
return this._loaded;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Return metadata about the loaded model.
|
|
79
|
+
*/
|
|
80
|
+
modelInfo() {
|
|
81
|
+
return {
|
|
82
|
+
version: this._wasm.constructor.version(),
|
|
83
|
+
size: this._modelSize,
|
|
84
|
+
accuracy: 0.8,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Free the WASM instance and mark this Garu as unloaded.
|
|
89
|
+
*/
|
|
90
|
+
destroy() {
|
|
91
|
+
if (this._wasm) {
|
|
92
|
+
this._wasm.free();
|
|
93
|
+
this._wasm = null;
|
|
94
|
+
}
|
|
95
|
+
this._loaded = false;
|
|
96
|
+
}
|
|
97
|
+
}
|
package/models/base.gmdl
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "garu-ko",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ultra-lightweight Korean morphological analyzer for the web (2.2MB model, WASM 93KB, F1 95.3%)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["dist", "pkg", "models"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build:wasm": "wasm-pack build ../crates/garu-wasm --target web --out-dir ../../js/pkg",
|
|
11
|
+
"build:js": "tsc",
|
|
12
|
+
"build": "npm run build:wasm && npm run build:js",
|
|
13
|
+
"test": "vitest run"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["korean", "morphological-analysis", "nlp", "wasm", "lightweight", "browser"],
|
|
16
|
+
"author": "cyj <dydwls140@naver.com>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/ongjin/garu.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.4",
|
|
24
|
+
"vitest": "^2.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class GaruWasm {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
analyze(text: string): any;
|
|
8
|
+
analyze_topn(text: string, n: number): any;
|
|
9
|
+
constructor(model_data: Uint8Array);
|
|
10
|
+
tokenize(text: string): any;
|
|
11
|
+
static version(): string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
15
|
+
|
|
16
|
+
export interface InitOutput {
|
|
17
|
+
readonly memory: WebAssembly.Memory;
|
|
18
|
+
readonly __wbg_garuwasm_free: (a: number, b: number) => void;
|
|
19
|
+
readonly garuwasm_analyze: (a: number, b: number, c: number) => [number, number, number];
|
|
20
|
+
readonly garuwasm_analyze_topn: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
21
|
+
readonly garuwasm_new: (a: number, b: number) => [number, number, number];
|
|
22
|
+
readonly garuwasm_tokenize: (a: number, b: number, c: number) => [number, number, number];
|
|
23
|
+
readonly garuwasm_version: () => [number, number];
|
|
24
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
25
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
26
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
27
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
28
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
29
|
+
readonly __wbindgen_start: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
36
|
+
* a precompiled `WebAssembly.Module`.
|
|
37
|
+
*
|
|
38
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
39
|
+
*
|
|
40
|
+
* @returns {InitOutput}
|
|
41
|
+
*/
|
|
42
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
46
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
47
|
+
*
|
|
48
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<InitOutput>}
|
|
51
|
+
*/
|
|
52
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/pkg/garu_wasm.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/* @ts-self-types="./garu_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class GaruWasm {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
GaruWasmFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_garuwasm_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} text
|
|
16
|
+
* @returns {any}
|
|
17
|
+
*/
|
|
18
|
+
analyze(text) {
|
|
19
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
20
|
+
const len0 = WASM_VECTOR_LEN;
|
|
21
|
+
const ret = wasm.garuwasm_analyze(this.__wbg_ptr, ptr0, len0);
|
|
22
|
+
if (ret[2]) {
|
|
23
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
24
|
+
}
|
|
25
|
+
return takeFromExternrefTable0(ret[0]);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} text
|
|
29
|
+
* @param {number} n
|
|
30
|
+
* @returns {any}
|
|
31
|
+
*/
|
|
32
|
+
analyze_topn(text, n) {
|
|
33
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
34
|
+
const len0 = WASM_VECTOR_LEN;
|
|
35
|
+
const ret = wasm.garuwasm_analyze_topn(this.__wbg_ptr, ptr0, len0, n);
|
|
36
|
+
if (ret[2]) {
|
|
37
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
38
|
+
}
|
|
39
|
+
return takeFromExternrefTable0(ret[0]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param {Uint8Array} model_data
|
|
43
|
+
*/
|
|
44
|
+
constructor(model_data) {
|
|
45
|
+
const ptr0 = passArray8ToWasm0(model_data, wasm.__wbindgen_malloc);
|
|
46
|
+
const len0 = WASM_VECTOR_LEN;
|
|
47
|
+
const ret = wasm.garuwasm_new(ptr0, len0);
|
|
48
|
+
if (ret[2]) {
|
|
49
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
50
|
+
}
|
|
51
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
52
|
+
GaruWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} text
|
|
57
|
+
* @returns {any}
|
|
58
|
+
*/
|
|
59
|
+
tokenize(text) {
|
|
60
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
61
|
+
const len0 = WASM_VECTOR_LEN;
|
|
62
|
+
const ret = wasm.garuwasm_tokenize(this.__wbg_ptr, ptr0, len0);
|
|
63
|
+
if (ret[2]) {
|
|
64
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
65
|
+
}
|
|
66
|
+
return takeFromExternrefTable0(ret[0]);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
static version() {
|
|
72
|
+
let deferred1_0;
|
|
73
|
+
let deferred1_1;
|
|
74
|
+
try {
|
|
75
|
+
const ret = wasm.garuwasm_version();
|
|
76
|
+
deferred1_0 = ret[0];
|
|
77
|
+
deferred1_1 = ret[1];
|
|
78
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
79
|
+
} finally {
|
|
80
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Symbol.dispose) GaruWasm.prototype[Symbol.dispose] = GaruWasm.prototype.free;
|
|
85
|
+
|
|
86
|
+
function __wbg_get_imports() {
|
|
87
|
+
const import0 = {
|
|
88
|
+
__proto__: null,
|
|
89
|
+
__wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
|
|
90
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
91
|
+
return ret;
|
|
92
|
+
},
|
|
93
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
94
|
+
const ret = String(arg1);
|
|
95
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
96
|
+
const len1 = WASM_VECTOR_LEN;
|
|
97
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
98
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
99
|
+
},
|
|
100
|
+
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
101
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
102
|
+
},
|
|
103
|
+
__wbg_new_a70fbab9066b301f: function() {
|
|
104
|
+
const ret = new Array();
|
|
105
|
+
return ret;
|
|
106
|
+
},
|
|
107
|
+
__wbg_new_ab79df5bd7c26067: function() {
|
|
108
|
+
const ret = new Object();
|
|
109
|
+
return ret;
|
|
110
|
+
},
|
|
111
|
+
__wbg_set_282384002438957f: function(arg0, arg1, arg2) {
|
|
112
|
+
arg0[arg1 >>> 0] = arg2;
|
|
113
|
+
},
|
|
114
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
115
|
+
arg0[arg1] = arg2;
|
|
116
|
+
},
|
|
117
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
118
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
119
|
+
const ret = arg0;
|
|
120
|
+
return ret;
|
|
121
|
+
},
|
|
122
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
123
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
124
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
125
|
+
return ret;
|
|
126
|
+
},
|
|
127
|
+
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
128
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
129
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
130
|
+
return ret;
|
|
131
|
+
},
|
|
132
|
+
__wbindgen_init_externref_table: function() {
|
|
133
|
+
const table = wasm.__wbindgen_externrefs;
|
|
134
|
+
const offset = table.grow(4);
|
|
135
|
+
table.set(0, undefined);
|
|
136
|
+
table.set(offset + 0, undefined);
|
|
137
|
+
table.set(offset + 1, null);
|
|
138
|
+
table.set(offset + 2, true);
|
|
139
|
+
table.set(offset + 3, false);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
__proto__: null,
|
|
144
|
+
"./garu_wasm_bg.js": import0,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const GaruWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
149
|
+
? { register: () => {}, unregister: () => {} }
|
|
150
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_garuwasm_free(ptr >>> 0, 1));
|
|
151
|
+
|
|
152
|
+
let cachedDataViewMemory0 = null;
|
|
153
|
+
function getDataViewMemory0() {
|
|
154
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
155
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
156
|
+
}
|
|
157
|
+
return cachedDataViewMemory0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getStringFromWasm0(ptr, len) {
|
|
161
|
+
ptr = ptr >>> 0;
|
|
162
|
+
return decodeText(ptr, len);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let cachedUint8ArrayMemory0 = null;
|
|
166
|
+
function getUint8ArrayMemory0() {
|
|
167
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
168
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
169
|
+
}
|
|
170
|
+
return cachedUint8ArrayMemory0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
174
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
175
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
176
|
+
WASM_VECTOR_LEN = arg.length;
|
|
177
|
+
return ptr;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
181
|
+
if (realloc === undefined) {
|
|
182
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
183
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
184
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
185
|
+
WASM_VECTOR_LEN = buf.length;
|
|
186
|
+
return ptr;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let len = arg.length;
|
|
190
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
191
|
+
|
|
192
|
+
const mem = getUint8ArrayMemory0();
|
|
193
|
+
|
|
194
|
+
let offset = 0;
|
|
195
|
+
|
|
196
|
+
for (; offset < len; offset++) {
|
|
197
|
+
const code = arg.charCodeAt(offset);
|
|
198
|
+
if (code > 0x7F) break;
|
|
199
|
+
mem[ptr + offset] = code;
|
|
200
|
+
}
|
|
201
|
+
if (offset !== len) {
|
|
202
|
+
if (offset !== 0) {
|
|
203
|
+
arg = arg.slice(offset);
|
|
204
|
+
}
|
|
205
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
206
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
207
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
208
|
+
|
|
209
|
+
offset += ret.written;
|
|
210
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
WASM_VECTOR_LEN = offset;
|
|
214
|
+
return ptr;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function takeFromExternrefTable0(idx) {
|
|
218
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
219
|
+
wasm.__externref_table_dealloc(idx);
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
224
|
+
cachedTextDecoder.decode();
|
|
225
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
226
|
+
let numBytesDecoded = 0;
|
|
227
|
+
function decodeText(ptr, len) {
|
|
228
|
+
numBytesDecoded += len;
|
|
229
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
230
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
231
|
+
cachedTextDecoder.decode();
|
|
232
|
+
numBytesDecoded = len;
|
|
233
|
+
}
|
|
234
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const cachedTextEncoder = new TextEncoder();
|
|
238
|
+
|
|
239
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
240
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
241
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
242
|
+
view.set(buf);
|
|
243
|
+
return {
|
|
244
|
+
read: arg.length,
|
|
245
|
+
written: buf.length
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let WASM_VECTOR_LEN = 0;
|
|
251
|
+
|
|
252
|
+
let wasmModule, wasm;
|
|
253
|
+
function __wbg_finalize_init(instance, module) {
|
|
254
|
+
wasm = instance.exports;
|
|
255
|
+
wasmModule = module;
|
|
256
|
+
cachedDataViewMemory0 = null;
|
|
257
|
+
cachedUint8ArrayMemory0 = null;
|
|
258
|
+
wasm.__wbindgen_start();
|
|
259
|
+
return wasm;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function __wbg_load(module, imports) {
|
|
263
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
264
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
265
|
+
try {
|
|
266
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
267
|
+
} catch (e) {
|
|
268
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
269
|
+
|
|
270
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
271
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
272
|
+
|
|
273
|
+
} else { throw e; }
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const bytes = await module.arrayBuffer();
|
|
278
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
279
|
+
} else {
|
|
280
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
281
|
+
|
|
282
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
283
|
+
return { instance, module };
|
|
284
|
+
} else {
|
|
285
|
+
return instance;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function expectedResponseType(type) {
|
|
290
|
+
switch (type) {
|
|
291
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function initSync(module) {
|
|
298
|
+
if (wasm !== undefined) return wasm;
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
if (module !== undefined) {
|
|
302
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
303
|
+
({module} = module)
|
|
304
|
+
} else {
|
|
305
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const imports = __wbg_get_imports();
|
|
310
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
311
|
+
module = new WebAssembly.Module(module);
|
|
312
|
+
}
|
|
313
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
314
|
+
return __wbg_finalize_init(instance, module);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function __wbg_init(module_or_path) {
|
|
318
|
+
if (wasm !== undefined) return wasm;
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
if (module_or_path !== undefined) {
|
|
322
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
323
|
+
({module_or_path} = module_or_path)
|
|
324
|
+
} else {
|
|
325
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (module_or_path === undefined) {
|
|
330
|
+
module_or_path = new URL('garu_wasm_bg.wasm', import.meta.url);
|
|
331
|
+
}
|
|
332
|
+
const imports = __wbg_get_imports();
|
|
333
|
+
|
|
334
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
335
|
+
module_or_path = fetch(module_or_path);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
339
|
+
|
|
340
|
+
return __wbg_finalize_init(instance, module);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_garuwasm_free: (a: number, b: number) => void;
|
|
5
|
+
export const garuwasm_analyze: (a: number, b: number, c: number) => [number, number, number];
|
|
6
|
+
export const garuwasm_analyze_topn: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
7
|
+
export const garuwasm_new: (a: number, b: number) => [number, number, number];
|
|
8
|
+
export const garuwasm_tokenize: (a: number, b: number, c: number) => [number, number, number];
|
|
9
|
+
export const garuwasm_version: () => [number, number];
|
|
10
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
11
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
12
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
13
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
14
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const __wbindgen_start: () => void;
|