@kensio/pinyinjs 1.7.5 → 1.7.6

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.
Files changed (89) hide show
  1. package/README.md +128 -123
  2. package/data/full.entries +2595 -2595
  3. package/data/manifest.json +5 -5
  4. package/data/script.map +66 -3
  5. package/dist/decode/chang-context.d.ts +27 -0
  6. package/dist/decode/chang-context.d.ts.map +1 -0
  7. package/dist/decode/chang-context.js +66 -0
  8. package/dist/decode/chang-context.js.map +1 -0
  9. package/dist/decode/chang-rule.d.ts +37 -0
  10. package/dist/decode/chang-rule.d.ts.map +1 -0
  11. package/dist/decode/chang-rule.js +169 -0
  12. package/dist/decode/chang-rule.js.map +1 -0
  13. package/dist/decode/confidence.d.ts +11 -3
  14. package/dist/decode/confidence.d.ts.map +1 -1
  15. package/dist/decode/confidence.js +11 -3
  16. package/dist/decode/confidence.js.map +1 -1
  17. package/dist/decode/convert-pipeline.d.ts.map +1 -1
  18. package/dist/decode/convert-pipeline.js +2 -1
  19. package/dist/decode/convert-pipeline.js.map +1 -1
  20. package/dist/decode/de-rule.d.ts +54 -0
  21. package/dist/decode/de-rule.d.ts.map +1 -0
  22. package/dist/decode/de-rule.js +113 -0
  23. package/dist/decode/de-rule.js.map +1 -0
  24. package/dist/decode/hint-lattice.d.ts.map +1 -1
  25. package/dist/decode/hint-lattice.js +17 -3
  26. package/dist/decode/hint-lattice.js.map +1 -1
  27. package/dist/decode/jiao-rule.d.ts +9 -3
  28. package/dist/decode/jiao-rule.d.ts.map +1 -1
  29. package/dist/decode/jiao-rule.js +44 -5
  30. package/dist/decode/jiao-rule.js.map +1 -1
  31. package/dist/decode/lattice-types.d.ts +27 -8
  32. package/dist/decode/lattice-types.d.ts.map +1 -1
  33. package/dist/decode/lattice-types.js +27 -8
  34. package/dist/decode/lattice-types.js.map +1 -1
  35. package/dist/decode/polyphone-rules.d.ts +7 -27
  36. package/dist/decode/polyphone-rules.d.ts.map +1 -1
  37. package/dist/decode/polyphone-rules.js +7 -155
  38. package/dist/decode/polyphone-rules.js.map +1 -1
  39. package/dist/decode/reading-rules.d.ts +1 -29
  40. package/dist/decode/reading-rules.d.ts.map +1 -1
  41. package/dist/decode/reading-rules.js +4 -69
  42. package/dist/decode/reading-rules.js.map +1 -1
  43. package/dist/decode/run-words.d.ts +17 -0
  44. package/dist/decode/run-words.d.ts.map +1 -0
  45. package/dist/decode/run-words.js +29 -0
  46. package/dist/decode/run-words.js.map +1 -0
  47. package/dist/decode/sandhi-input.d.ts +30 -0
  48. package/dist/decode/sandhi-input.d.ts.map +1 -0
  49. package/dist/decode/sandhi-input.js +35 -0
  50. package/dist/decode/sandhi-input.js.map +1 -0
  51. package/dist/decode/sandhi-tones.d.ts +33 -5
  52. package/dist/decode/sandhi-tones.d.ts.map +1 -1
  53. package/dist/decode/sandhi-tones.js +59 -8
  54. package/dist/decode/sandhi-tones.js.map +1 -1
  55. package/dist/decode/sandhi.d.ts +9 -6
  56. package/dist/decode/sandhi.d.ts.map +1 -1
  57. package/dist/decode/sandhi.js +10 -7
  58. package/dist/decode/sandhi.js.map +1 -1
  59. package/dist/decode/write-run.d.ts +0 -7
  60. package/dist/decode/write-run.d.ts.map +1 -1
  61. package/dist/decode/write-run.js +4 -39
  62. package/dist/decode/write-run.js.map +1 -1
  63. package/dist/dictionary/cedict-senses.d.ts +7 -0
  64. package/dist/dictionary/cedict-senses.d.ts.map +1 -1
  65. package/dist/dictionary/cedict-senses.js +12 -0
  66. package/dist/dictionary/cedict-senses.js.map +1 -1
  67. package/dist/dictionary/constituent-repair.d.ts +36 -0
  68. package/dist/dictionary/constituent-repair.d.ts.map +1 -0
  69. package/dist/dictionary/constituent-repair.js +117 -0
  70. package/dist/dictionary/constituent-repair.js.map +1 -0
  71. package/dist/dictionary/merge-types.d.ts +8 -2
  72. package/dist/dictionary/merge-types.d.ts.map +1 -1
  73. package/dist/dictionary/merge-types.js.map +1 -1
  74. package/dist/dictionary/merge-walk.d.ts +27 -0
  75. package/dist/dictionary/merge-walk.d.ts.map +1 -0
  76. package/dist/dictionary/merge-walk.js +49 -0
  77. package/dist/dictionary/merge-walk.js.map +1 -0
  78. package/dist/dictionary/merge.d.ts +3 -3
  79. package/dist/dictionary/merge.d.ts.map +1 -1
  80. package/dist/dictionary/merge.js +18 -28
  81. package/dist/dictionary/merge.js.map +1 -1
  82. package/dist/dictionary/word-readings.d.ts.map +1 -1
  83. package/dist/dictionary/word-readings.js +3 -0
  84. package/dist/dictionary/word-readings.js.map +1 -1
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +1 -1
  88. package/dist/index.js.map +1 -1
  89. package/package.json +2 -2
@@ -39,14 +39,17 @@ export type SandhiGrouping = readonly (number | readonly number[])[];
39
39
  * contextual tone is put back, over the whole syllable array rather than within
40
40
  * a word, which is what lets 不 in one word assimilate to a tone in the next.
41
41
  *
42
- * 一 and 不 assimilate to whatever follows them and need nothing but the
43
- * syllables. Third-tone sandhi is not like that — its domain is the foot rather
44
- * than the syllable string — so `grouping` says where the words and their parts
45
- * are. Without one the whole array is taken for a single word, which is what a
46
- * caller holding nothing but a reading has.
42
+ * 不 assimilates to whatever follows it and needs nothing but the syllables.
43
+ * Third-tone sandhi is not like that — its domain is the foot rather than the
44
+ * syllable string — so `grouping` says where the words and their parts are.
45
+ * Without one the whole array is taken for a single word, which is what a
46
+ * caller holding nothing but a reading has. 一 sits between the two: the tone it
47
+ * takes is settled by the syllables, and whether it takes one at all is a
48
+ * question about the 汉字, so `characters` carries them where the caller has
49
+ * them. See {@link isCounting}.
47
50
  *
48
51
  * Never operates on a string. The old project patched output text with regexes,
49
52
  * which is what made its rules order-dependent and untestable.
50
53
  */
51
- export declare function applySandhi(syllables: readonly Syllable[], options?: SandhiOptions, grouping?: SandhiGrouping): readonly Syllable[];
54
+ export declare function applySandhi(syllables: readonly Syllable[], options?: SandhiOptions, grouping?: SandhiGrouping, characters?: readonly (string | undefined)[]): readonly Syllable[];
52
55
  //# sourceMappingURL=sandhi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sandhi.d.ts","sourceRoot":"","sources":["../../src/decode/sandhi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;AA6HrE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,OAAO,GAAE,aAAkB,EAC3B,QAAQ,CAAC,EAAE,cAAc,GACxB,SAAS,QAAQ,EAAE,CA6BrB"}
1
+ {"version":3,"file":"sandhi.d.ts","sourceRoot":"","sources":["../../src/decode/sandhi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;AA6HrE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,OAAO,GAAE,aAAkB,EAC3B,QAAQ,CAAC,EAAE,cAAc,EACzB,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAC3C,SAAS,QAAQ,EAAE,CA6BrB"}
@@ -103,16 +103,19 @@ function applyThirdTone(syllables, grouping) {
103
103
  * contextual tone is put back, over the whole syllable array rather than within
104
104
  * a word, which is what lets 不 in one word assimilate to a tone in the next.
105
105
  *
106
- * 一 and 不 assimilate to whatever follows them and need nothing but the
107
- * syllables. Third-tone sandhi is not like that — its domain is the foot rather
108
- * than the syllable string — so `grouping` says where the words and their parts
109
- * are. Without one the whole array is taken for a single word, which is what a
110
- * caller holding nothing but a reading has.
106
+ * 不 assimilates to whatever follows it and needs nothing but the syllables.
107
+ * Third-tone sandhi is not like that — its domain is the foot rather than the
108
+ * syllable string — so `grouping` says where the words and their parts are.
109
+ * Without one the whole array is taken for a single word, which is what a
110
+ * caller holding nothing but a reading has. 一 sits between the two: the tone it
111
+ * takes is settled by the syllables, and whether it takes one at all is a
112
+ * question about the 汉字, so `characters` carries them where the caller has
113
+ * them. See {@link isCounting}.
111
114
  *
112
115
  * Never operates on a string. The old project patched output text with regexes,
113
116
  * which is what made its rules order-dependent and untestable.
114
117
  */
115
- export function applySandhi(syllables, options = {}, grouping) {
118
+ export function applySandhi(syllables, options = {}, grouping, characters) {
116
119
  const { yiBu = true, thirdTone = false } = options;
117
120
  const applied = thirdTone
118
121
  ? applyThirdTone(syllables, grouping)
@@ -122,7 +125,7 @@ export function applySandhi(syllables, options = {}, grouping) {
122
125
  if (yiBu && isYi(syllable) && syllable.tone === 1) {
123
126
  // A 一 that is not counting keeps its citation tone, so it is left
124
127
  // exactly as the dictionary stored it.
125
- if (isCounting(applied, at)) {
128
+ if (isCounting(applied, at, characters)) {
126
129
  applied[at] = { ...syllable, tone: yiToneBefore(following?.tone) };
127
130
  }
128
131
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"sandhi.js","sourceRoot":"","sources":["../../src/decode/sandhi.ts"],"names":[],"mappings":"AACA,O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IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -18,11 +18,4 @@ export declare function writeRun(dictionary: Dictionary, words: readonly ScoredW
18
18
  * Rewrite every piece's text with a pass that reads across all of them.
19
19
  */
20
20
  export declare function rewrite(pieces: readonly ConvertedPiece[], pass: (parts: readonly string[]) => readonly string[]): readonly ConvertedPiece[];
21
- /**
22
- * The words a Han run decodes to, with 分词连写 applied.
23
- *
24
- * Grouping rewrites word boundaries and never the readings behind them, so the
25
- * syllables — and the confidence beside them — survive it in order.
26
- */
27
- export declare function wordsOf(decoded: readonly ScoredWord[], dictionary: Dictionary, isGrouped: boolean): readonly ScoredWord[];
28
21
  //# sourceMappingURL=write-run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write-run.d.ts","sourceRoot":"","sources":["../../src/decode/write-run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,KAAK,cAAc,EAInB,KAAK,OAAO,EACb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,GAAG,SAAS,GAChC,SAAS,cAAc,EAAE,CA0C3B;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,EAAE,GACpD,SAAS,cAAc,EAAE,CAO3B;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,OAAO,GACjB,SAAS,UAAU,EAAE,CAUvB"}
1
+ {"version":3,"file":"write-run.d.ts","sourceRoot":"","sources":["../../src/decode/write-run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,KAAK,cAAc,EAInB,KAAK,OAAO,EACb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,GAAG,SAAS,GAChC,SAAS,cAAc,EAAE,CAqC3B;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,EAAE,GACpD,SAAS,cAAc,EAAE,CAO3B"}
@@ -1,5 +1,4 @@
1
- import { applyGrouping } from "../orthography/grouping.js";
2
- import { divisionOf } from "./constituents.js";
1
+ import { charactersPerSyllable, groupingOf } from "./sandhi-input.js";
3
2
  import { applySandhi } from "./sandhi.js";
4
3
  import { plainPiece, readingFor, writeWord, } from "./pieces.js";
5
4
  /**
@@ -7,17 +6,10 @@ import { plainPiece, readingFor, writeWord, } from "./pieces.js";
7
6
  */
8
7
  export function writeRun(dictionary, words, locale, written, sandhi) {
9
8
  // Sandhi runs across the whole run rather than within a word, since 不 in one
10
- // word assimilates to the tone starting the next. Third-tone sandhi needs to
11
- // know where the words are all the same, so the grouping goes with it — and
12
- // only when it is asked for, since dividing a word costs lookups.
9
+ // word assimilates to the tone starting the next, and what it needs beyond
10
+ // the syllables is in `sandhi-input.ts`.
13
11
  const readings = words.map((scored) => readingFor(dictionary, scored.word, locale));
14
- const grouping = sandhi?.thirdTone === true
15
- ? words.map((scored, index) => {
16
- const reading = readings[index] ?? [];
17
- return (divisionOf(dictionary, scored.word.text, reading) ?? reading.length);
18
- })
19
- : undefined;
20
- const flattened = applySandhi(readings.flat(), sandhi, grouping);
12
+ const flattened = applySandhi(readings.flat(), sandhi, groupingOf(dictionary, words, readings, sandhi?.thirdTone === true), charactersPerSyllable(words, readings));
21
13
  let at = 0;
22
14
  const pieces = [];
23
15
  for (const [index, scored] of words.entries()) {
@@ -47,31 +39,4 @@ export function rewrite(pieces, pass) {
47
39
  return text === piece.text ? piece : { ...piece, text };
48
40
  });
49
41
  }
50
- /**
51
- * The words a Han run decodes to, with 分词连写 applied.
52
- *
53
- * Grouping rewrites word boundaries and never the readings behind them, so the
54
- * syllables — and the confidence beside them — survive it in order.
55
- */
56
- export function wordsOf(decoded, dictionary, isGrouped) {
57
- return isGrouped
58
- ? regroup(decoded, applyGrouping(decoded.map((scored) => scored.word), dictionary))
59
- : decoded;
60
- }
61
- /**
62
- * Redistribute the decode's per-syllable confidence over regrouped words.
63
- *
64
- * 分词连写 moves word boundaries — 看 and 了 become 看了 — without touching a
65
- * reading, so the run's syllables are the same syllables in the same order and
66
- * are simply cut in different places.
67
- */
68
- function regroup(decoded, grouped) {
69
- const confidence = decoded.flatMap((scored) => [...scored.confidence]);
70
- let at = 0;
71
- return grouped.map((word) => {
72
- const held = confidence.slice(at, at + word.reading.length);
73
- at += word.reading.length;
74
- return { word, confidence: held };
75
- });
76
- }
77
42
  //# sourceMappingURL=write-run.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write-run.js","source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AG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QAC9B,qEAAqE;QACrE,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC;QACzC,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -32,6 +32,13 @@ export declare function indexCedict(cedict: readonly CedictEntry[], formOf: (ent
32
32
  * A word's readings as CC-CEDICT gives them, one per sense.
33
33
  */
34
34
  export declare function cedictReadingsOf(word: string, entries: readonly CedictEntry[]): readonly (readonly Syllable[])[];
35
+ /**
36
+ * Ask either index for every reading CC-CEDICT gives a spelling.
37
+ *
38
+ * Both scripts, because a word can be listed under one and not the other, and
39
+ * an empty answer means CC-CEDICT does not hold the spelling at all.
40
+ */
41
+ export declare function senseLookup(byWord: ReadonlyMap<string, readonly CedictEntry[]>, byHant: ReadonlyMap<string, readonly CedictEntry[]>): (word: string) => readonly (readonly Syllable[])[];
35
42
  /**
36
43
  * Whether a proposed 國語 reading is really another 普通话 sense of the word.
37
44
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cedict-senses.d.ts","sourceRoot":"","sources":["../../src/dictionary/cedict-senses.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIxD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,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W,EAAE,EAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,GACrC,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAY7C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,WAAW,EAAE,GAC9B,SAAS,CAAC,SAAS,QAAQ,EAAE,CAAC,EAAE,CAIlC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,EACnD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,GAClD,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,SAAS,QAAQ,EAAE,CAAC,EAAE,CAKpD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,aAAa,EAAE,SAAS,CAAC,SAAS,QAAQ,EAAE,CAAC,EAAE,GAC9C,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,GAAG,SAAS,GAC7B,OAAO,CAET"}
@@ -62,6 +62,18 @@ export function cedictReadingsOf(word, entries) {
62
62
  .map((entry) => readDictionaryReading(word, entry.readings))
63
63
  .filter((reading) => reading !== undefined);
64
64
  }
65
+ /**
66
+ * Ask either index for every reading CC-CEDICT gives a spelling.
67
+ *
68
+ * Both scripts, because a word can be listed under one and not the other, and
69
+ * an empty answer means CC-CEDICT does not hold the spelling at all.
70
+ */
71
+ export function senseLookup(byWord, byHant) {
72
+ return (word) => [
73
+ ...cedictReadingsOf(word, byWord.get(word) ?? []),
74
+ ...cedictReadingsOf(word, byHant.get(word) ?? []),
75
+ ];
76
+ }
65
77
  /**
66
78
  * Whether a proposed 國語 reading is really another 普通话 sense of the word.
67
79
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cedict-senses.js","sourceRoot":"","sources":["../../src/dictionary/cedict-senses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,MAAmD,EACnD,MAAmD;IAEnD,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAClC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,WAAW,CAClD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,MAA8B,EAC9B,MAAsC;IAEtC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAChD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;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G;AACH,MAAM,UAAU,UAAU,CACxB,MAA2B,EAC3B,aAA+C;IAE/C,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,KAA8B;IAE9B,OAAO,KAAK,EAAE,WAAW,KAAK,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { Syllable } from "../syllable/syllable.js";
2
+ import { type DictionaryEntry } from "./entry.js";
3
+ /**
4
+ * What the repair pass changed.
5
+ */
6
+ export interface ConstituentRepair {
7
+ readonly entries: readonly DictionaryEntry[];
8
+ /** Entries given a reading from a word inside them. */
9
+ readonly repaired: number;
10
+ }
11
+ /**
12
+ * Read a phrase entry as the corroborated words inside it read it.
13
+ *
14
+ * 做什么 is stored `zuò shí mǒ` upstream, and 什么 is `shén me` in the same file
15
+ * and in CC-CEDICT besides. The decode has no way back from that: the four
16
+ * characters are one dictionary key, so the key answers and the word inside it
17
+ * is never asked. 什么意思, 不记得 and 这么说 are the same defect, and between
18
+ * them they account for 160 of the 290 sentences a downstream corpus of 13,182
19
+ * reported as misread.
20
+ *
21
+ * The pass runs over entries **nothing but the phrase corpus attests** — no
22
+ * CC-CEDICT headword under either script, no jieba frequency — and takes each
23
+ * one's constituents from `ConstituentIndex`, the same segmentation the locale
24
+ * composition uses. Only a constituent CC-CEDICT holds may correct anything, so
25
+ * this never trades one uncorroborated reading for another. What survives
26
+ * {@link corrects} replaces the span it covers.
27
+ *
28
+ * Measured on the full dictionary it repairs 1,727 entries of the 250,417 it
29
+ * looks at. Sampled by hand at every 61st, the repairs are neutral tones the
30
+ * corpus wrote out in full (骨头, 大夫, 秀才, 和尚), spellings it got wrong
31
+ * (相扑 `xiàng pū`, 武侯 `wǔ hòu`, 用尽 `yòng jǐn`) and one entry with no tones
32
+ * at all (激昂青云). The doubtful ones are homographs either reading is
33
+ * defensible for: 倒数比 and 面糊盆.
34
+ */
35
+ export declare function repairConstituentReadings(entries: readonly DictionaryEntry[], sensesOf: (word: string) => readonly (readonly Syllable[])[]): ConstituentRepair;
36
+ //# sourceMappingURL=constituent-repair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constituent-repair.d.ts","sourceRoot":"","sources":["../../src/dictionary/constituent-repair.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,YAAY,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AA0CD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,SAAS,QAAQ,EAAE,CAAC,EAAE,GAC3D,iBAAiB,CAmDnB"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Holding a phrase entry to what the words inside it already read.
3
+ *
4
+ * The phrase corpus is a reading source and not a word list, and 251,528 of its
5
+ * 411,956 keys are in neither CC-CEDICT nor jieba. Much of that tail is running
6
+ * text rather than vocabulary — 做什么, 什么意思, 不记得, 一个幽灵在欧洲游荡 —
7
+ * and where a key like that carries a defective reading there is nothing to
8
+ * correct it against, because `settleReading` compares a phrase entry with the
9
+ * CC-CEDICT sense of the *same* headword and CC-CEDICT has no such headword.
10
+ *
11
+ * This is that missing correction, taken from the words inside instead.
12
+ */
13
+ import { toCharacters } from "../script/characters.js";
14
+ import { NEUTRAL_TONE } from "../tone/tone.js";
15
+ import { isSameReading } from "./entry.js";
16
+ import { ConstituentIndex } from "./locale-segments.js";
17
+ /**
18
+ * Whether a constituent may correct the span it covers.
19
+ *
20
+ * Four tests, and each one rules out a class of damage:
21
+ *
22
+ * 1. **Multi-character only.** A character's own reading is the prior the
23
+ * phrase entry was built from, so correcting against it says nothing new.
24
+ * It is the same reasoning `composeLocaleDeltas` gives for the same
25
+ * restriction.
26
+ * 2. **One syllable per character on both sides**, or the two readings are not
27
+ * describing the same span character for character.
28
+ * 3. **The span must match no sense CC-CEDICT gives the constituent.** A word
29
+ * with two readings has two senses, and a phrase using the other one is
30
+ * right: 分子 is `fēn zǐ` as a molecule and `fèn zǐ` as a member, so
31
+ * 分子结构 keeps the reading it was given. The build's tier check found this
32
+ * one, which is what that check is for.
33
+ * 4. **No 轻声 may gain a tone.** The phrase corpus writes full tones where
34
+ * CC-CEDICT has neutral and never the reverse, so a correction pushing the
35
+ * other way is not a correction at all — it is a constituent that fell
36
+ * across a boundary. Every 地 in the 268 entries this rules out is the
37
+ * adverbial particle, and the words claiming it are 心地, 性地 and 野地.
38
+ */
39
+ function corrects(part, span, own, senses) {
40
+ if (toCharacters(part.text).length < 2 || own.length !== span.length) {
41
+ return false;
42
+ }
43
+ if (senses.some((sense) => isSameReading(sense, span))) {
44
+ return false;
45
+ }
46
+ return !span.some((syllable, at) => syllable.tone === NEUTRAL_TONE && own[at]?.tone !== NEUTRAL_TONE);
47
+ }
48
+ /**
49
+ * Read a phrase entry as the corroborated words inside it read it.
50
+ *
51
+ * 做什么 is stored `zuò shí mǒ` upstream, and 什么 is `shén me` in the same file
52
+ * and in CC-CEDICT besides. The decode has no way back from that: the four
53
+ * characters are one dictionary key, so the key answers and the word inside it
54
+ * is never asked. 什么意思, 不记得 and 这么说 are the same defect, and between
55
+ * them they account for 160 of the 290 sentences a downstream corpus of 13,182
56
+ * reported as misread.
57
+ *
58
+ * The pass runs over entries **nothing but the phrase corpus attests** — no
59
+ * CC-CEDICT headword under either script, no jieba frequency — and takes each
60
+ * one's constituents from `ConstituentIndex`, the same segmentation the locale
61
+ * composition uses. Only a constituent CC-CEDICT holds may correct anything, so
62
+ * this never trades one uncorroborated reading for another. What survives
63
+ * {@link corrects} replaces the span it covers.
64
+ *
65
+ * Measured on the full dictionary it repairs 1,727 entries of the 250,417 it
66
+ * looks at. Sampled by hand at every 61st, the repairs are neutral tones the
67
+ * corpus wrote out in full (骨头, 大夫, 秀才, 和尚), spellings it got wrong
68
+ * (相扑 `xiàng pū`, 武侯 `wǔ hòu`, 用尽 `yòng jǐn`) and one entry with no tones
69
+ * at all (激昂青云). The doubtful ones are homographs either reading is
70
+ * defensible for: 倒数比 and 面糊盆.
71
+ */
72
+ export function repairConstituentReadings(entries, sensesOf) {
73
+ const index = new ConstituentIndex(entries);
74
+ let repaired = 0;
75
+ const repair = (entry) => {
76
+ const reading = entry.readings.cn;
77
+ if (entry.frequency > 0 ||
78
+ sensesOf(entry.hans).length > 0 ||
79
+ sensesOf(entry.hant).length > 0 ||
80
+ reading.length !== toCharacters(entry.hans).length ||
81
+ reading.length < 2) {
82
+ return entry;
83
+ }
84
+ const path = index.segment(entry.hans);
85
+ if (path === undefined) {
86
+ return entry;
87
+ }
88
+ let corrected = [...reading];
89
+ let isMoved = false;
90
+ for (const part of path) {
91
+ const own = part.entry.readings.cn;
92
+ const senses = [
93
+ ...sensesOf(part.entry.hans),
94
+ ...sensesOf(part.entry.hant),
95
+ ];
96
+ if (senses.length === 0) {
97
+ continue;
98
+ }
99
+ if (!corrects(part, reading.slice(part.from, part.to), own, senses)) {
100
+ continue;
101
+ }
102
+ corrected = [
103
+ ...corrected.slice(0, part.from),
104
+ ...own,
105
+ ...corrected.slice(part.to),
106
+ ];
107
+ isMoved = true;
108
+ }
109
+ if (!isMoved) {
110
+ return entry;
111
+ }
112
+ repaired++;
113
+ return { ...entry, readings: { ...entry.readings, cn: corrected } };
114
+ };
115
+ return { entries: entries.map((entry) => repair(entry)), repaired };
116
+ }
117
+ //# sourceMappingURL=constituent-repair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constituent-repair.js","sourceRoot":"","sources":["../../src/dictionary/constituent-repair.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAwB,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAgB,MAAM,sBAAsB,CAAC;AAWtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAS,QAAQ,CACf,IAAa,EACb,IAAyB,EACzB,GAAwB,EACxB,MAAwC;IAExC,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,IAAI,CACf,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CACf,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,KAAK,YAAY,CACnE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAmC,EACnC,QAA4D;IAE5D,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,MAAM,MAAM,GAAG,CAAC,KAAsB,EAA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AC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;gBAChC,GAAG,GAAG;gBACN,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;aAC5B,CAAC;YACF,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACf,CAAC;QAED,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC;IACtE,CAAC,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;AACtE,CAAC"}
@@ -42,6 +42,11 @@ export interface MergeStats {
42
42
  readonly scriptPairs: number;
43
43
  /** Entries a source writes more than one 繁體 spelling of. */
44
44
  readonly variantSpellings: number;
45
+ /**
46
+ * Phrase entries read as a corroborated word inside them reads them — see
47
+ * {@link import("./constituent-repair.js").repairConstituentReadings}.
48
+ */
49
+ readonly repairedConstituents: number;
45
50
  /** Entries carrying a zh-TW reading delta a source stated. */
46
51
  readonly taiwanReadings: number;
47
52
  /** Compounds given a zh-TW delta composed from their constituents. */
@@ -85,8 +90,9 @@ export interface WordSources {
85
90
  * What one word contributed to the build's counts.
86
91
  *
87
92
  * The per-word view of {@link MergeStats}, minus the counts no single word can
88
- * move: `reducedNeutrals` and `composedTaiwanReadings` are settled by passes
89
- * over the whole dictionary, and `rejected` is counted by the caller.
93
+ * move: `reducedNeutrals`, `repairedConstituents` and `composedTaiwanReadings`
94
+ * are settled by passes over the whole dictionary, and `rejected` is counted by
95
+ * the caller.
90
96
  */
91
97
  export interface WordTally {
92
98
  readonly neutralToneCorrections: number;
@@ -1 +1 @@
1
- {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AC,sBAAsB,GAAG,KAAK,CAAC,sBAAsB;QAC7D,YAAY,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY;QACrD,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC,kBAAkB;QACvE,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;QAClD,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB;QACjE,cAAc,EAAE,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc;QAC3D,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB;QACjE,cAAc,EAAE,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc;QAC3D,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU;QAC/C,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;QAClD,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;KACnD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { CedictEntry } from "../sources/cedict.js";
2
+ import type { DictionaryEntry } from "./entry.js";
3
+ import { type WordSources, type WordTally } from "./merge-types.js";
4
+ /**
5
+ * Every spelling the merge will try to give an entry.
6
+ *
7
+ * The characters Unihan knows, the phrase corpus's headwords and CC-CEDICT's,
8
+ * less the phrase headwords that are really 繁體 spellings of another word —
9
+ * see {@link isSpeltTraditionally}. jieba is absent on purpose: it carries
10
+ * frequencies and tags rather than readings, so a word only it has would arrive
11
+ * with nothing to read it by.
12
+ */
13
+ export declare function wordList(phrase: ReadonlyMap<string, readonly string[]>, defaults: ReadonlyMap<string, unknown>, cedictByWord: ReadonlyMap<string, readonly CedictEntry[]>, cedictByHant: ReadonlyMap<string, readonly CedictEntry[]>): readonly string[];
14
+ /**
15
+ * What the walk produced: the entries, what it turned away, and the counts.
16
+ */
17
+ export interface MergedWords {
18
+ readonly entries: readonly DictionaryEntry[];
19
+ /** Spellings no source gave a usable reading, and what it gave instead. */
20
+ readonly rejected: ReadonlyMap<string, readonly string[]>;
21
+ readonly counts: WordTally;
22
+ }
23
+ /**
24
+ * Settle every word in the list.
25
+ */
26
+ export declare function mergeWords(words: readonly string[], sources: WordSources): MergedWords;
27
+ //# sourceMappingURL=merge-walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-walk.d.ts","sourceRoot":"","sources":["../../src/dictionary/merge-walk.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,EAC9C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,EACzD,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,GACxD,SAAS,MAAM,EAAE,CASnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC1D,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,WAAW,GACnB,WAAW,CAmBb"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The word list the merge walks, and what walking it comes to.
3
+ *
4
+ * Which spellings get an entry at all, and the loop that settles each of them.
5
+ * `merge.ts` is the order of the passes; this is the pass over the words.
6
+ */
7
+ import { byCodeUnit } from "./artifact-format.js";
8
+ import { isSpeltTraditionally } from "./cedict-senses.js";
9
+ import { mergeWord } from "./merge-word.js";
10
+ import { addTally, NO_TALLY, } from "./merge-types.js";
11
+ /**
12
+ * Every spelling the merge will try to give an entry.
13
+ *
14
+ * The characters Unihan knows, the phrase corpus's headwords and CC-CEDICT's,
15
+ * less the phrase headwords that are really 繁體 spellings of another word —
16
+ * see {@link isSpeltTraditionally}. jieba is absent on purpose: it carries
17
+ * frequencies and tags rather than readings, so a word only it has would arrive
18
+ * with nothing to read it by.
19
+ */
20
+ export function wordList(phrase, defaults, cedictByWord, cedictByHant) {
21
+ const words = new Set([
22
+ ...defaults.keys(),
23
+ ...[...phrase.keys()].filter((word) => !isSpeltTraditionally(word, cedictByWord, cedictByHant)),
24
+ ...cedictByWord.keys(),
25
+ ]);
26
+ return [...words].toSorted(byCodeUnit);
27
+ }
28
+ /**
29
+ * Settle every word in the list.
30
+ */
31
+ export function mergeWords(words, sources) {
32
+ const entries = [];
33
+ const rejected = new Map();
34
+ let counts = NO_TALLY;
35
+ for (const word of words) {
36
+ const merged = mergeWord(word, sources);
37
+ counts = addTally(counts, merged.tally);
38
+ if (merged.rejected !== undefined) {
39
+ rejected.set(word, merged.rejected);
40
+ continue;
41
+ }
42
+ /* c8 ignore next 3 -- a word is either rejected or gives an entry */
43
+ if (merged.entry !== undefined) {
44
+ entries.push(merged.entry);
45
+ }
46
+ }
47
+ return { entries, rejected, counts };
48
+ }
49
+ //# sourceMappingURL=merge-walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-walk.js","sourceRoot":"","sources":["../../src/dictionary/merge-walk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,M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M,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type MergeResult, type MergeSources } from "./merge-types.js";
1
+ import type { MergeResult, MergeSources } from "./merge-types.js";
2
2
  export type { MergeResult, MergeSources, MergeStats } from "./merge-types.js";
3
3
  /**
4
4
  * Build the merged dictionary from the four parsed sources.
@@ -6,8 +6,8 @@ export type { MergeResult, MergeSources, MergeStats } from "./merge-types.js";
6
6
  * The order of operations is the one MERGE.md sets out, and it is not
7
7
  * arbitrary — each step depends on the one before. Spelling, tones, sandhi and
8
8
  * validation happen in {@link import("./reading.js").readAlignedReading} as each source is read;
9
- * {@link mergeWord} then settles one word at a time, and this walks the words
10
- * and gathers what each of them came to.
9
+ * {@link mergeWords} then settles one word at a time, and the passes after it
10
+ * see every entry at once.
11
11
  */
12
12
  export declare function mergeSources(sources: MergeSources): MergeResult;
13
13
  //# sourceMappingURL=merge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/dictionary/merge.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAGlB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9E;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAkE/D"}
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/dictionary/merge.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,kBAAkB,CAAC;AAE/E,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9E;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAuD/D"}