@ryaningli/rwer 0.2.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/package.json +21 -0
- package/rwer.d.ts +155 -0
- package/rwer.js +538 -0
- package/rwer_bg.wasm +0 -0
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ryaningli/rwer",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Fast Rust WebAssembly bindings for rwer — WER, CER, and ASR evaluation metrics",
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ryaningli/rwer"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"rwer_bg.wasm",
|
|
13
|
+
"rwer.js",
|
|
14
|
+
"rwer.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "rwer.js",
|
|
17
|
+
"types": "rwer.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/rwer.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A single chunk in the alignment visualization.
|
|
6
|
+
*/
|
|
7
|
+
export class AlignmentChunk {
|
|
8
|
+
private constructor();
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* The hypothesis text (for substitute/insert chunks).
|
|
13
|
+
*/
|
|
14
|
+
readonly hypothesis: string;
|
|
15
|
+
/**
|
|
16
|
+
* The type of this chunk: "equal", "substitute", "insert", or "delete".
|
|
17
|
+
*/
|
|
18
|
+
readonly kind: string;
|
|
19
|
+
/**
|
|
20
|
+
* The reference text (for equal/substitute/delete chunks).
|
|
21
|
+
*/
|
|
22
|
+
readonly text: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Detailed alignment output with all metrics and chunks.
|
|
27
|
+
*/
|
|
28
|
+
export class AlignmentOutput {
|
|
29
|
+
private constructor();
|
|
30
|
+
free(): void;
|
|
31
|
+
[Symbol.dispose](): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get all alignment chunks as a JS array.
|
|
34
|
+
*/
|
|
35
|
+
chunks(): AlignmentChunk[];
|
|
36
|
+
/**
|
|
37
|
+
* Get a human-readable alignment visualization.
|
|
38
|
+
*/
|
|
39
|
+
visualize(): string;
|
|
40
|
+
readonly cer: number;
|
|
41
|
+
readonly deletions: number;
|
|
42
|
+
readonly hits: number;
|
|
43
|
+
readonly hyp_len: number;
|
|
44
|
+
readonly insertions: number;
|
|
45
|
+
readonly mer: number;
|
|
46
|
+
readonly ref_len: number;
|
|
47
|
+
readonly substitutions: number;
|
|
48
|
+
readonly wer: number;
|
|
49
|
+
readonly wil: number;
|
|
50
|
+
readonly wip: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Compute Character Error Rate at the Unicode grapheme cluster level.
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* import { cer } from "rwer-wasm";
|
|
58
|
+
* console.log(cer("hello", "hallo")); // 0.2
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function cer(reference: string, hypothesis: string): number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Compute Match Error Rate.
|
|
65
|
+
*/
|
|
66
|
+
export function mer(reference: string, hypothesis: string): number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Compute all character-level metrics and return detailed alignment output.
|
|
70
|
+
*/
|
|
71
|
+
export function process_chars(reference: string, hypothesis: string): AlignmentOutput;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Compute all word-level metrics and return detailed alignment output.
|
|
75
|
+
*/
|
|
76
|
+
export function process_words(reference: string, hypothesis: string): AlignmentOutput;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Compute Word Error Rate between reference and hypothesis strings.
|
|
80
|
+
*
|
|
81
|
+
* ```js
|
|
82
|
+
* import { wer } from "rwer-wasm";
|
|
83
|
+
* console.log(wer("the cat sat", "the cat sat on")); // 0.3333...
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function wer(reference: string, hypothesis: string): number;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Compute Word Information Lost.
|
|
90
|
+
*/
|
|
91
|
+
export function wil(reference: string, hypothesis: string): number;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Compute Word Information Preserved.
|
|
95
|
+
*/
|
|
96
|
+
export function wip(reference: string, hypothesis: string): number;
|
|
97
|
+
|
|
98
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
99
|
+
|
|
100
|
+
export interface InitOutput {
|
|
101
|
+
readonly memory: WebAssembly.Memory;
|
|
102
|
+
readonly __wbg_alignmentchunk_free: (a: number, b: number) => void;
|
|
103
|
+
readonly __wbg_alignmentoutput_free: (a: number, b: number) => void;
|
|
104
|
+
readonly alignmentchunk_hypothesis: (a: number) => [number, number];
|
|
105
|
+
readonly alignmentchunk_kind: (a: number) => [number, number];
|
|
106
|
+
readonly alignmentchunk_text: (a: number) => [number, number];
|
|
107
|
+
readonly alignmentoutput_cer: (a: number) => number;
|
|
108
|
+
readonly alignmentoutput_chunks: (a: number) => [number, number];
|
|
109
|
+
readonly alignmentoutput_deletions: (a: number) => number;
|
|
110
|
+
readonly alignmentoutput_hits: (a: number) => number;
|
|
111
|
+
readonly alignmentoutput_hyp_len: (a: number) => number;
|
|
112
|
+
readonly alignmentoutput_insertions: (a: number) => number;
|
|
113
|
+
readonly alignmentoutput_mer: (a: number) => number;
|
|
114
|
+
readonly alignmentoutput_ref_len: (a: number) => number;
|
|
115
|
+
readonly alignmentoutput_substitutions: (a: number) => number;
|
|
116
|
+
readonly alignmentoutput_visualize: (a: number) => [number, number];
|
|
117
|
+
readonly alignmentoutput_wer: (a: number) => number;
|
|
118
|
+
readonly alignmentoutput_wil: (a: number) => number;
|
|
119
|
+
readonly alignmentoutput_wip: (a: number) => number;
|
|
120
|
+
readonly cer: (a: number, b: number, c: number, d: number) => number;
|
|
121
|
+
readonly mer: (a: number, b: number, c: number, d: number) => number;
|
|
122
|
+
readonly process_chars: (a: number, b: number, c: number, d: number) => number;
|
|
123
|
+
readonly process_words: (a: number, b: number, c: number, d: number) => number;
|
|
124
|
+
readonly wer: (a: number, b: number, c: number, d: number) => number;
|
|
125
|
+
readonly wil: (a: number, b: number, c: number, d: number) => number;
|
|
126
|
+
readonly wip: (a: number, b: number, c: number, d: number) => number;
|
|
127
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
128
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
129
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
130
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
131
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
132
|
+
readonly __wbindgen_start: () => void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
139
|
+
* a precompiled `WebAssembly.Module`.
|
|
140
|
+
*
|
|
141
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
142
|
+
*
|
|
143
|
+
* @returns {InitOutput}
|
|
144
|
+
*/
|
|
145
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
149
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
150
|
+
*
|
|
151
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
152
|
+
*
|
|
153
|
+
* @returns {Promise<InitOutput>}
|
|
154
|
+
*/
|
|
155
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/rwer.js
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
/* @ts-self-types="./rwer.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A single chunk in the alignment visualization.
|
|
5
|
+
*/
|
|
6
|
+
export class AlignmentChunk {
|
|
7
|
+
static __wrap(ptr) {
|
|
8
|
+
ptr = ptr >>> 0;
|
|
9
|
+
const obj = Object.create(AlignmentChunk.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
AlignmentChunkFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
AlignmentChunkFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_alignmentchunk_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The hypothesis text (for substitute/insert chunks).
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
get hypothesis() {
|
|
29
|
+
let deferred1_0;
|
|
30
|
+
let deferred1_1;
|
|
31
|
+
try {
|
|
32
|
+
const ret = wasm.alignmentchunk_hypothesis(this.__wbg_ptr);
|
|
33
|
+
deferred1_0 = ret[0];
|
|
34
|
+
deferred1_1 = ret[1];
|
|
35
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
36
|
+
} finally {
|
|
37
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The type of this chunk: "equal", "substitute", "insert", or "delete".
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
get kind() {
|
|
45
|
+
let deferred1_0;
|
|
46
|
+
let deferred1_1;
|
|
47
|
+
try {
|
|
48
|
+
const ret = wasm.alignmentchunk_kind(this.__wbg_ptr);
|
|
49
|
+
deferred1_0 = ret[0];
|
|
50
|
+
deferred1_1 = ret[1];
|
|
51
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
52
|
+
} finally {
|
|
53
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The reference text (for equal/substitute/delete chunks).
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
get text() {
|
|
61
|
+
let deferred1_0;
|
|
62
|
+
let deferred1_1;
|
|
63
|
+
try {
|
|
64
|
+
const ret = wasm.alignmentchunk_text(this.__wbg_ptr);
|
|
65
|
+
deferred1_0 = ret[0];
|
|
66
|
+
deferred1_1 = ret[1];
|
|
67
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
68
|
+
} finally {
|
|
69
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (Symbol.dispose) AlignmentChunk.prototype[Symbol.dispose] = AlignmentChunk.prototype.free;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Detailed alignment output with all metrics and chunks.
|
|
77
|
+
*/
|
|
78
|
+
export class AlignmentOutput {
|
|
79
|
+
static __wrap(ptr) {
|
|
80
|
+
ptr = ptr >>> 0;
|
|
81
|
+
const obj = Object.create(AlignmentOutput.prototype);
|
|
82
|
+
obj.__wbg_ptr = ptr;
|
|
83
|
+
AlignmentOutputFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
__destroy_into_raw() {
|
|
87
|
+
const ptr = this.__wbg_ptr;
|
|
88
|
+
this.__wbg_ptr = 0;
|
|
89
|
+
AlignmentOutputFinalization.unregister(this);
|
|
90
|
+
return ptr;
|
|
91
|
+
}
|
|
92
|
+
free() {
|
|
93
|
+
const ptr = this.__destroy_into_raw();
|
|
94
|
+
wasm.__wbg_alignmentoutput_free(ptr, 0);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @returns {number}
|
|
98
|
+
*/
|
|
99
|
+
get cer() {
|
|
100
|
+
const ret = wasm.alignmentoutput_cer(this.__wbg_ptr);
|
|
101
|
+
return ret;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get all alignment chunks as a JS array.
|
|
105
|
+
* @returns {AlignmentChunk[]}
|
|
106
|
+
*/
|
|
107
|
+
chunks() {
|
|
108
|
+
const ret = wasm.alignmentoutput_chunks(this.__wbg_ptr);
|
|
109
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
110
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
111
|
+
return v1;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @returns {number}
|
|
115
|
+
*/
|
|
116
|
+
get deletions() {
|
|
117
|
+
const ret = wasm.alignmentoutput_deletions(this.__wbg_ptr);
|
|
118
|
+
return ret >>> 0;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @returns {number}
|
|
122
|
+
*/
|
|
123
|
+
get hits() {
|
|
124
|
+
const ret = wasm.alignmentoutput_hits(this.__wbg_ptr);
|
|
125
|
+
return ret >>> 0;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @returns {number}
|
|
129
|
+
*/
|
|
130
|
+
get hyp_len() {
|
|
131
|
+
const ret = wasm.alignmentoutput_hyp_len(this.__wbg_ptr);
|
|
132
|
+
return ret >>> 0;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @returns {number}
|
|
136
|
+
*/
|
|
137
|
+
get insertions() {
|
|
138
|
+
const ret = wasm.alignmentoutput_insertions(this.__wbg_ptr);
|
|
139
|
+
return ret >>> 0;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @returns {number}
|
|
143
|
+
*/
|
|
144
|
+
get mer() {
|
|
145
|
+
const ret = wasm.alignmentoutput_mer(this.__wbg_ptr);
|
|
146
|
+
return ret;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @returns {number}
|
|
150
|
+
*/
|
|
151
|
+
get ref_len() {
|
|
152
|
+
const ret = wasm.alignmentoutput_ref_len(this.__wbg_ptr);
|
|
153
|
+
return ret >>> 0;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @returns {number}
|
|
157
|
+
*/
|
|
158
|
+
get substitutions() {
|
|
159
|
+
const ret = wasm.alignmentoutput_substitutions(this.__wbg_ptr);
|
|
160
|
+
return ret >>> 0;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get a human-readable alignment visualization.
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
visualize() {
|
|
167
|
+
let deferred1_0;
|
|
168
|
+
let deferred1_1;
|
|
169
|
+
try {
|
|
170
|
+
const ret = wasm.alignmentoutput_visualize(this.__wbg_ptr);
|
|
171
|
+
deferred1_0 = ret[0];
|
|
172
|
+
deferred1_1 = ret[1];
|
|
173
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
174
|
+
} finally {
|
|
175
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @returns {number}
|
|
180
|
+
*/
|
|
181
|
+
get wer() {
|
|
182
|
+
const ret = wasm.alignmentoutput_wer(this.__wbg_ptr);
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @returns {number}
|
|
187
|
+
*/
|
|
188
|
+
get wil() {
|
|
189
|
+
const ret = wasm.alignmentoutput_wil(this.__wbg_ptr);
|
|
190
|
+
return ret;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @returns {number}
|
|
194
|
+
*/
|
|
195
|
+
get wip() {
|
|
196
|
+
const ret = wasm.alignmentoutput_wip(this.__wbg_ptr);
|
|
197
|
+
return ret;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (Symbol.dispose) AlignmentOutput.prototype[Symbol.dispose] = AlignmentOutput.prototype.free;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Compute Character Error Rate at the Unicode grapheme cluster level.
|
|
204
|
+
*
|
|
205
|
+
* ```js
|
|
206
|
+
* import { cer } from "rwer-wasm";
|
|
207
|
+
* console.log(cer("hello", "hallo")); // 0.2
|
|
208
|
+
* ```
|
|
209
|
+
* @param {string} reference
|
|
210
|
+
* @param {string} hypothesis
|
|
211
|
+
* @returns {number}
|
|
212
|
+
*/
|
|
213
|
+
export function cer(reference, hypothesis) {
|
|
214
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
215
|
+
const len0 = WASM_VECTOR_LEN;
|
|
216
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
217
|
+
const len1 = WASM_VECTOR_LEN;
|
|
218
|
+
const ret = wasm.cer(ptr0, len0, ptr1, len1);
|
|
219
|
+
return ret;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Compute Match Error Rate.
|
|
224
|
+
* @param {string} reference
|
|
225
|
+
* @param {string} hypothesis
|
|
226
|
+
* @returns {number}
|
|
227
|
+
*/
|
|
228
|
+
export function mer(reference, hypothesis) {
|
|
229
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
230
|
+
const len0 = WASM_VECTOR_LEN;
|
|
231
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
232
|
+
const len1 = WASM_VECTOR_LEN;
|
|
233
|
+
const ret = wasm.mer(ptr0, len0, ptr1, len1);
|
|
234
|
+
return ret;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Compute all character-level metrics and return detailed alignment output.
|
|
239
|
+
* @param {string} reference
|
|
240
|
+
* @param {string} hypothesis
|
|
241
|
+
* @returns {AlignmentOutput}
|
|
242
|
+
*/
|
|
243
|
+
export function process_chars(reference, hypothesis) {
|
|
244
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
245
|
+
const len0 = WASM_VECTOR_LEN;
|
|
246
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
247
|
+
const len1 = WASM_VECTOR_LEN;
|
|
248
|
+
const ret = wasm.process_chars(ptr0, len0, ptr1, len1);
|
|
249
|
+
return AlignmentOutput.__wrap(ret);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Compute all word-level metrics and return detailed alignment output.
|
|
254
|
+
* @param {string} reference
|
|
255
|
+
* @param {string} hypothesis
|
|
256
|
+
* @returns {AlignmentOutput}
|
|
257
|
+
*/
|
|
258
|
+
export function process_words(reference, hypothesis) {
|
|
259
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
260
|
+
const len0 = WASM_VECTOR_LEN;
|
|
261
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
262
|
+
const len1 = WASM_VECTOR_LEN;
|
|
263
|
+
const ret = wasm.process_words(ptr0, len0, ptr1, len1);
|
|
264
|
+
return AlignmentOutput.__wrap(ret);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Compute Word Error Rate between reference and hypothesis strings.
|
|
269
|
+
*
|
|
270
|
+
* ```js
|
|
271
|
+
* import { wer } from "rwer-wasm";
|
|
272
|
+
* console.log(wer("the cat sat", "the cat sat on")); // 0.3333...
|
|
273
|
+
* ```
|
|
274
|
+
* @param {string} reference
|
|
275
|
+
* @param {string} hypothesis
|
|
276
|
+
* @returns {number}
|
|
277
|
+
*/
|
|
278
|
+
export function wer(reference, hypothesis) {
|
|
279
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
280
|
+
const len0 = WASM_VECTOR_LEN;
|
|
281
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
282
|
+
const len1 = WASM_VECTOR_LEN;
|
|
283
|
+
const ret = wasm.wer(ptr0, len0, ptr1, len1);
|
|
284
|
+
return ret;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Compute Word Information Lost.
|
|
289
|
+
* @param {string} reference
|
|
290
|
+
* @param {string} hypothesis
|
|
291
|
+
* @returns {number}
|
|
292
|
+
*/
|
|
293
|
+
export function wil(reference, hypothesis) {
|
|
294
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
295
|
+
const len0 = WASM_VECTOR_LEN;
|
|
296
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
297
|
+
const len1 = WASM_VECTOR_LEN;
|
|
298
|
+
const ret = wasm.wil(ptr0, len0, ptr1, len1);
|
|
299
|
+
return ret;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Compute Word Information Preserved.
|
|
304
|
+
* @param {string} reference
|
|
305
|
+
* @param {string} hypothesis
|
|
306
|
+
* @returns {number}
|
|
307
|
+
*/
|
|
308
|
+
export function wip(reference, hypothesis) {
|
|
309
|
+
const ptr0 = passStringToWasm0(reference, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
310
|
+
const len0 = WASM_VECTOR_LEN;
|
|
311
|
+
const ptr1 = passStringToWasm0(hypothesis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
312
|
+
const len1 = WASM_VECTOR_LEN;
|
|
313
|
+
const ret = wasm.wip(ptr0, len0, ptr1, len1);
|
|
314
|
+
return ret;
|
|
315
|
+
}
|
|
316
|
+
function __wbg_get_imports() {
|
|
317
|
+
const import0 = {
|
|
318
|
+
__proto__: null,
|
|
319
|
+
__wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
|
|
320
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
321
|
+
},
|
|
322
|
+
__wbg_alignmentchunk_new: function(arg0) {
|
|
323
|
+
const ret = AlignmentChunk.__wrap(arg0);
|
|
324
|
+
return ret;
|
|
325
|
+
},
|
|
326
|
+
__wbindgen_init_externref_table: function() {
|
|
327
|
+
const table = wasm.__wbindgen_externrefs;
|
|
328
|
+
const offset = table.grow(4);
|
|
329
|
+
table.set(0, undefined);
|
|
330
|
+
table.set(offset + 0, undefined);
|
|
331
|
+
table.set(offset + 1, null);
|
|
332
|
+
table.set(offset + 2, true);
|
|
333
|
+
table.set(offset + 3, false);
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
__proto__: null,
|
|
338
|
+
"./rwer_bg.js": import0,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const AlignmentChunkFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
343
|
+
? { register: () => {}, unregister: () => {} }
|
|
344
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_alignmentchunk_free(ptr >>> 0, 1));
|
|
345
|
+
const AlignmentOutputFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
346
|
+
? { register: () => {}, unregister: () => {} }
|
|
347
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_alignmentoutput_free(ptr >>> 0, 1));
|
|
348
|
+
|
|
349
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
350
|
+
ptr = ptr >>> 0;
|
|
351
|
+
const mem = getDataViewMemory0();
|
|
352
|
+
const result = [];
|
|
353
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
354
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
355
|
+
}
|
|
356
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let cachedDataViewMemory0 = null;
|
|
361
|
+
function getDataViewMemory0() {
|
|
362
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
363
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
364
|
+
}
|
|
365
|
+
return cachedDataViewMemory0;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function getStringFromWasm0(ptr, len) {
|
|
369
|
+
ptr = ptr >>> 0;
|
|
370
|
+
return decodeText(ptr, len);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let cachedUint8ArrayMemory0 = null;
|
|
374
|
+
function getUint8ArrayMemory0() {
|
|
375
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
376
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
377
|
+
}
|
|
378
|
+
return cachedUint8ArrayMemory0;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
382
|
+
if (realloc === undefined) {
|
|
383
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
384
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
385
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
386
|
+
WASM_VECTOR_LEN = buf.length;
|
|
387
|
+
return ptr;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let len = arg.length;
|
|
391
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
392
|
+
|
|
393
|
+
const mem = getUint8ArrayMemory0();
|
|
394
|
+
|
|
395
|
+
let offset = 0;
|
|
396
|
+
|
|
397
|
+
for (; offset < len; offset++) {
|
|
398
|
+
const code = arg.charCodeAt(offset);
|
|
399
|
+
if (code > 0x7F) break;
|
|
400
|
+
mem[ptr + offset] = code;
|
|
401
|
+
}
|
|
402
|
+
if (offset !== len) {
|
|
403
|
+
if (offset !== 0) {
|
|
404
|
+
arg = arg.slice(offset);
|
|
405
|
+
}
|
|
406
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
407
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
408
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
409
|
+
|
|
410
|
+
offset += ret.written;
|
|
411
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
WASM_VECTOR_LEN = offset;
|
|
415
|
+
return ptr;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
419
|
+
cachedTextDecoder.decode();
|
|
420
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
421
|
+
let numBytesDecoded = 0;
|
|
422
|
+
function decodeText(ptr, len) {
|
|
423
|
+
numBytesDecoded += len;
|
|
424
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
425
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
426
|
+
cachedTextDecoder.decode();
|
|
427
|
+
numBytesDecoded = len;
|
|
428
|
+
}
|
|
429
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const cachedTextEncoder = new TextEncoder();
|
|
433
|
+
|
|
434
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
435
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
436
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
437
|
+
view.set(buf);
|
|
438
|
+
return {
|
|
439
|
+
read: arg.length,
|
|
440
|
+
written: buf.length
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
let WASM_VECTOR_LEN = 0;
|
|
446
|
+
|
|
447
|
+
let wasmModule, wasm;
|
|
448
|
+
function __wbg_finalize_init(instance, module) {
|
|
449
|
+
wasm = instance.exports;
|
|
450
|
+
wasmModule = module;
|
|
451
|
+
cachedDataViewMemory0 = null;
|
|
452
|
+
cachedUint8ArrayMemory0 = null;
|
|
453
|
+
wasm.__wbindgen_start();
|
|
454
|
+
return wasm;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async function __wbg_load(module, imports) {
|
|
458
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
459
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
460
|
+
try {
|
|
461
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
462
|
+
} catch (e) {
|
|
463
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
464
|
+
|
|
465
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
466
|
+
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);
|
|
467
|
+
|
|
468
|
+
} else { throw e; }
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const bytes = await module.arrayBuffer();
|
|
473
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
474
|
+
} else {
|
|
475
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
476
|
+
|
|
477
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
478
|
+
return { instance, module };
|
|
479
|
+
} else {
|
|
480
|
+
return instance;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function expectedResponseType(type) {
|
|
485
|
+
switch (type) {
|
|
486
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
487
|
+
}
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function initSync(module) {
|
|
493
|
+
if (wasm !== undefined) return wasm;
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
if (module !== undefined) {
|
|
497
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
498
|
+
({module} = module)
|
|
499
|
+
} else {
|
|
500
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const imports = __wbg_get_imports();
|
|
505
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
506
|
+
module = new WebAssembly.Module(module);
|
|
507
|
+
}
|
|
508
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
509
|
+
return __wbg_finalize_init(instance, module);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
async function __wbg_init(module_or_path) {
|
|
513
|
+
if (wasm !== undefined) return wasm;
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
if (module_or_path !== undefined) {
|
|
517
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
518
|
+
({module_or_path} = module_or_path)
|
|
519
|
+
} else {
|
|
520
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (module_or_path === undefined) {
|
|
525
|
+
module_or_path = new URL('rwer_bg.wasm', import.meta.url);
|
|
526
|
+
}
|
|
527
|
+
const imports = __wbg_get_imports();
|
|
528
|
+
|
|
529
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
530
|
+
module_or_path = fetch(module_or_path);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
534
|
+
|
|
535
|
+
return __wbg_finalize_init(instance, module);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export { initSync, __wbg_init as default };
|
package/rwer_bg.wasm
ADDED
|
Binary file
|