garu-ko 0.12.0 → 0.13.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/node.js CHANGED
@@ -15,7 +15,7 @@ export class Garu extends GaruBase {
15
15
  const { join, dirname } = await import('path');
16
16
  const dir = dirname(fileURLToPath(import.meta.url));
17
17
  const wasmBytes = await readFile(join(dir, '..', 'pkg', 'garu_wasm_bg.wasm'));
18
- await wasmModule.default(wasmBytes);
18
+ await wasmModule.default({ module_or_path: wasmBytes });
19
19
  let modelBytes;
20
20
  if (options?.modelData) {
21
21
  modelBytes = new Uint8Array(options.modelData);
@@ -304,5 +304,34 @@ export function splitVerified(text, model, analyzer) {
304
304
  ? extractSentenceFeatures(text, candidates, analyzer)
305
305
  : extractContextFeatures(text, candidates);
306
306
  const retained = verifySentenceCandidates(text, candidates, features, model);
307
- return splitAtBoundaries(text, retained.map(candidate => candidate.offset));
307
+ return splitAtBoundaries(text, snapBoundaries(text, retained.map(candidate => candidate.offset)));
308
+ }
309
+ // Trailing laughter, emoticons, tildes and repeated marks belong to the preceding sentence.
310
+ const TRAILING = /[\s~!?.…^;*♡♥★☆♪♬”’)\]」』\u1100-\u11FF\u3131-\u318E\u2600-\u27BF\uFE0F\u200D\u{1F000}-\u{1FAFF}]/u;
311
+ const HANGUL_SYLLABLE = /[가-힣]/u;
312
+ // Spaced input: at least one word gap per ten Hangul syllables.
313
+ const SPACED_RATIO = 10;
314
+ /** Move boundaries past trailing ornaments; in spaced input, drop word-internal boundaries. */
315
+ function snapBoundaries(text, offsets) {
316
+ const chars = [...text];
317
+ let hangul = 0;
318
+ let gaps = 0;
319
+ for (let i = 0; i < chars.length; i++) {
320
+ if (HANGUL_SYLLABLE.test(chars[i]))
321
+ hangul++;
322
+ else if (SPACE.test(chars[i]) && i > 0 && !SPACE.test(chars[i - 1]))
323
+ gaps++;
324
+ }
325
+ const spaced = gaps * SPACED_RATIO >= hangul;
326
+ const out = [];
327
+ for (let offset of offsets) {
328
+ while (offset < chars.length && TRAILING.test(chars[offset]))
329
+ offset++;
330
+ if (offset >= chars.length || out[out.length - 1] === offset)
331
+ continue;
332
+ if (spaced && offset > 0 && !TRAILING.test(chars[offset - 1]))
333
+ continue;
334
+ out.push(offset);
335
+ }
336
+ return out;
308
337
  }
@@ -1,5 +1,8 @@
1
1
  import type { SentenceAnalyzer } from './sentence-verifier.js';
2
2
  import type { Segment } from './normalize.js';
3
3
  export type { SentenceAnalyzer } from './sentence-verifier.js';
4
- /** Fast offline splitting; supplying an analyzer opts into the slower morphology verifier. */
4
+ /**
5
+ * Fast offline splitting; supplying an analyzer opts into the slower morphology verifier.
6
+ * Every line break ends a sentence; join hard-wrapped lines before calling.
7
+ */
5
8
  export declare function splitSentences(text: string, analyzer?: SentenceAnalyzer): Segment[];
package/dist/sentences.js CHANGED
@@ -2,10 +2,28 @@
2
2
  import { SENTENCE_MODEL } from './sentence-data.js';
3
3
  import { SENTENCE_MODEL as FAST_MODEL } from './sentence-fast-data.js';
4
4
  import { loadSentenceVerifier, splitVerified } from './sentence-verifier.js';
5
+ const LINE_BREAK = /\r\n|[\n\r\u2028\u2029]/gu;
5
6
  let model;
6
7
  let fastModel;
7
- /** Fast offline splitting; supplying an analyzer opts into the slower morphology verifier. */
8
+ /**
9
+ * Fast offline splitting; supplying an analyzer opts into the slower morphology verifier.
10
+ * Every line break ends a sentence; join hard-wrapped lines before calling.
11
+ */
8
12
  export function splitSentences(text, analyzer) {
13
+ const lines = splitLines(text);
14
+ if (lines.length === 1)
15
+ return splitLine(text, analyzer);
16
+ const segments = [];
17
+ for (const line of lines) {
18
+ if (!line.text.trim())
19
+ continue;
20
+ for (const segment of splitLine(line.text, analyzer)) {
21
+ segments.push({ text: segment.text, offset: line.offset + segment.offset });
22
+ }
23
+ }
24
+ return segments.length ? segments : [{ text: text.trim(), offset: 0 }];
25
+ }
26
+ function splitLine(text, analyzer) {
9
27
  if (!analyzer) {
10
28
  fastModel ?? (fastModel = loadSentenceVerifier(FAST_MODEL));
11
29
  return splitVerified(text, fastModel);
@@ -13,3 +31,17 @@ export function splitSentences(text, analyzer) {
13
31
  model ?? (model = loadSentenceVerifier(SENTENCE_MODEL));
14
32
  return splitVerified(text, model, analyzer);
15
33
  }
34
+ /** Lines with Unicode codepoint offsets into the original text. */
35
+ function splitLines(text) {
36
+ const lines = [];
37
+ let start = 0;
38
+ let offset = 0;
39
+ for (const match of text.matchAll(LINE_BREAK)) {
40
+ const line = text.slice(start, match.index);
41
+ lines.push({ text: line, offset });
42
+ offset += [...line].length + match[0].length;
43
+ start = match.index + match[0].length;
44
+ }
45
+ lines.push({ text: text.slice(start), offset });
46
+ return lines;
47
+ }
package/models/NOTICE.md CHANGED
@@ -14,4 +14,4 @@ The changes comprise Unicode normalization, POS mapping, deduplication, selectio
14
14
 
15
15
  Retain the applicable attribution and modification notices when redistributing this data. Include a copy of the Apache-2.0 license for the MeCab-derived portions, and the CC license text or its URI for the CC-licensed portions. The ShareAlike condition applies to adaptations of the CC-licensed data. This notice does not relicense the independent engine code or grant new rights to the original training corpora. The full license texts govern their respective source material.
16
16
 
17
- The context-POS parameters in Section 16, the optional `garu-ko/text` boundary weights and the Q4 context-verifier weights in `garu-ko/sentences` were trained from the National Institute of Korean Language (국립국어원) NIKL morphological corpus, 2021 edition. Training and evaluation lineage is recorded in `training/ambiguity/` and `training/boundaries/` in the repository; `sentence-provenance.json` identifies both the fast and morphology-assisted Q4 artifacts. Original corpus paragraphs and annotations are not included in the package.
17
+ The context-POS parameters in Section 16, the optional `garu-ko/text` boundary weights and the Q4 context-verifier weights in `garu-ko/sentences` were trained from the National Institute of Korean Language (국립국어원) NIKL morphological corpus, 2021 edition. Since research history #83 the sentence half of the `garu-ko/text` boundary weights also uses Instagram sentence records from the NIKL online posting materials corpus 2025 (국립국어원 온라인 게시 자료 말뭉치 2025, version 1.0), and the Section 17 spoken `그` rule uses the 2021 spoken corpus with tildes removed. Training and evaluation lineage is recorded in `training/ambiguity/` and `training/boundaries/` in the repository; `sentence-provenance.json` identifies both the fast and morphology-assisted Q4 artifacts. Original corpus paragraphs and annotations are not included in the package.
package/models/base.gmdl CHANGED
Binary file
@@ -66,5 +66,7 @@
66
66
  }
67
67
  },
68
68
  "evaluation_wasm_sha256": "1a3ac3a324fcfce72a1388fa1b84e12512cbfe41ac19de1bb8ebaf84f75935fd",
69
- "runtime_version": "0.10.0"
69
+ "runtime_version": "0.10.0",
70
+ "runtime_boundary_weights_sha256": "c8a4aa2bc5a85130e01204bfd09d4612340eadd1f3b4dfd811bcaf991eb380c9",
71
+ "runtime_changes": "2026-11-11 research history #83: the first-stage sentence head was retrained with Instagram punctuation positions (NIKL online posting corpus 2025); splitSentences ends sentences at line breaks, moves boundaries past trailing ornaments and drops word-internal boundaries in spaced input. Both verifiers are unchanged and were trained against base_boundary_weights_sha256."
70
72
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.12.0",
4
- "description": "Ultra-lightweight Korean morphological analyzer for the web (1.26MB model, WASM, F1 96.05% gold testset)",
3
+ "version": "0.13.0",
4
+ "description": "Ultra-lightweight Korean morphological analyzer for the web (1.34MB model, WASM, F1 96.18% gold testset)",
5
5
  "type": "module",
6
6
  "main": "dist/node.js",
7
7
  "browser": "dist/browser.js",
package/pkg/garu_wasm.js CHANGED
@@ -156,7 +156,7 @@ export class GaruWasm {
156
156
  }
157
157
  }
158
158
  if (Symbol.dispose) GaruWasm.prototype[Symbol.dispose] = GaruWasm.prototype.free;
159
- import * as import1 from "./snippets/garu-core-da182886218044e8/inline0.js"
159
+ import * as import1 from "./snippets/garu-core-c2e3720a73bec734/inline0.js"
160
160
 
161
161
  function __wbg_get_imports() {
162
162
  const import0 = {
@@ -215,7 +215,7 @@ function __wbg_get_imports() {
215
215
  return {
216
216
  __proto__: null,
217
217
  "./garu_wasm_bg.js": import0,
218
- "./snippets/garu-core-da182886218044e8/inline0.js": import1,
218
+ "./snippets/garu-core-c2e3720a73bec734/inline0.js": import1,
219
219
  };
220
220
  }
221
221
 
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.12.0",
4
+ "version": "0.13.0",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "garu_wasm_bg.wasm",