@kensio/pinyinjs 1.5.3 → 1.7.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/README.md +252 -5
- package/data/core.entries +462 -460
- package/data/core.freq +0 -0
- package/data/core.keys +2 -0
- package/data/full.entries +13732 -13734
- package/data/full.freq +0 -0
- package/data/full.keys +0 -2
- package/data/manifest.json +15 -15
- package/data/script.map +34 -55
- package/data/standard.entries +1354 -1352
- package/data/standard.freq +0 -0
- package/data/standard.keys +2 -0
- package/dist/cli/arguments.d.ts +38 -0
- package/dist/cli/arguments.d.ts.map +1 -1
- package/dist/cli/arguments.js +46 -0
- package/dist/cli/arguments.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +229 -2
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +5 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/decode/convert.d.ts +58 -0
- package/dist/decode/convert.d.ts.map +1 -1
- package/dist/decode/convert.js +135 -37
- package/dist/decode/convert.js.map +1 -1
- package/dist/decode/decode.d.ts +3 -2
- package/dist/decode/decode.d.ts.map +1 -1
- package/dist/decode/decode.js +15 -10
- package/dist/decode/decode.js.map +1 -1
- package/dist/decode/hints.d.ts +138 -0
- package/dist/decode/hints.d.ts.map +1 -0
- package/dist/decode/hints.js +214 -0
- package/dist/decode/hints.js.map +1 -0
- package/dist/decode/lattice.d.ts +9 -1
- package/dist/decode/lattice.d.ts.map +1 -1
- package/dist/decode/lattice.js +5 -3
- package/dist/decode/lattice.js.map +1 -1
- package/dist/decode/reading-rules.d.ts +28 -0
- package/dist/decode/reading-rules.d.ts.map +1 -1
- package/dist/decode/reading-rules.js +157 -0
- package/dist/decode/reading-rules.js.map +1 -1
- package/dist/decode/runs.d.ts +11 -0
- package/dist/decode/runs.d.ts.map +1 -1
- package/dist/decode/runs.js +19 -0
- package/dist/decode/runs.js.map +1 -1
- package/dist/decode/segment.d.ts +66 -0
- package/dist/decode/segment.d.ts.map +1 -0
- package/dist/decode/segment.js +79 -0
- package/dist/decode/segment.js.map +1 -0
- package/dist/dictionary/artifact.d.ts +10 -0
- package/dist/dictionary/artifact.d.ts.map +1 -1
- package/dist/dictionary/artifact.js +17 -0
- package/dist/dictionary/artifact.js.map +1 -1
- package/dist/dictionary/assertions.d.ts.map +1 -1
- package/dist/dictionary/assertions.js +8 -0
- package/dist/dictionary/assertions.js.map +1 -1
- package/dist/dictionary/corpus-mass.d.ts +68 -0
- package/dist/dictionary/corpus-mass.d.ts.map +1 -0
- package/dist/dictionary/corpus-mass.js +123 -0
- package/dist/dictionary/corpus-mass.js.map +1 -0
- package/dist/dictionary/dictionary.d.ts +56 -0
- package/dist/dictionary/dictionary.d.ts.map +1 -1
- package/dist/dictionary/dictionary.js +116 -1
- package/dist/dictionary/dictionary.js.map +1 -1
- package/dist/dictionary/erhua.d.ts +4 -0
- package/dist/dictionary/erhua.d.ts.map +1 -1
- package/dist/dictionary/erhua.js +6 -0
- package/dist/dictionary/erhua.js.map +1 -1
- package/dist/dictionary/frequency-table.js +1 -1
- package/dist/dictionary/locale.js +2 -2
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +46 -9
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/dictionary/tiers.d.ts +2 -1
- package/dist/dictionary/tiers.d.ts.map +1 -1
- package/dist/dictionary/tiers.js +77 -11
- package/dist/dictionary/tiers.js.map +1 -1
- package/dist/format/html.d.ts +32 -0
- package/dist/format/html.d.ts.map +1 -1
- package/dist/format/html.js +144 -0
- package/dist/format/html.js.map +1 -1
- package/dist/grade/check.d.ts +156 -0
- package/dist/grade/check.d.ts.map +1 -0
- package/dist/grade/check.js +356 -0
- package/dist/grade/check.js.map +1 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/search/candidates.d.ts +84 -0
- package/dist/search/candidates.d.ts.map +1 -0
- package/dist/search/candidates.js +290 -0
- package/dist/search/candidates.js.map +1 -0
- package/dist/search/match.d.ts +72 -0
- package/dist/search/match.d.ts.map +1 -0
- package/dist/search/match.js +419 -0
- package/dist/search/match.js.map +1 -0
- package/dist/search/query.d.ts +49 -0
- package/dist/search/query.d.ts.map +1 -0
- package/dist/search/query.js +115 -0
- package/dist/search/query.js.map +1 -0
- package/dist/search/reverse-index.d.ts +141 -0
- package/dist/search/reverse-index.d.ts.map +1 -0
- package/dist/search/reverse-index.js +356 -0
- package/dist/search/reverse-index.js.map +1 -0
- package/dist/sources/unihan.d.ts +22 -4
- package/dist/sources/unihan.d.ts.map +1 -1
- package/dist/sources/unihan.js +74 -13
- package/dist/sources/unihan.js.map +1 -1
- package/package.json +2 -3
- package/CHANGELOG.md +0 -485
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { alignSequences } from "../accuracy/align.js";
|
|
2
|
+
import { tokenisePinyin } from "../accuracy/tokenise.js";
|
|
3
|
+
import { convertPieces, convertPiecesUnscored, } from "../decode/convert.js";
|
|
4
|
+
import { READING_CHARGE } from "../decode/lattice.js";
|
|
5
|
+
import { toCharacters } from "../script/characters.js";
|
|
6
|
+
import { readSyllable, writeSyllableSpelling, } from "../syllable/syllable.js";
|
|
7
|
+
import { NEUTRAL_TONE } from "../tone/tone.js";
|
|
8
|
+
/**
|
|
9
|
+
* The other corner of the sandhi square.
|
|
10
|
+
*
|
|
11
|
+
* A learner may write the underlying tones or the tones actually said, and both
|
|
12
|
+
* are right — 你好 is written `nǐ hǎo` and said `ní hǎo`. Rather than convert
|
|
13
|
+
* four times for the four combinations of {@link SandhiOptions}, this converts
|
|
14
|
+
* twice and inverts both switches at once, which reaches every tone: 一 and 不
|
|
15
|
+
* sandhi applies to syllables in the first and fourth tones, third-tone sandhi
|
|
16
|
+
* only to syllables in the third, so the two passes never touch the same
|
|
17
|
+
* syllable and each one's two forms both appear across the two corners.
|
|
18
|
+
*/
|
|
19
|
+
function oppositeSandhi(sandhi) {
|
|
20
|
+
return {
|
|
21
|
+
yiBu: !(sandhi?.yiBu ?? true),
|
|
22
|
+
thirdTone: !(sandhi?.thirdTone ?? false),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where each piece's source characters start, in code points.
|
|
27
|
+
*
|
|
28
|
+
* Read off the sources rather than tracked through the conversion, which works
|
|
29
|
+
* because every character of the text is named by exactly one piece — a piece
|
|
30
|
+
* naming none is either pinyin orthography the source has no trace of, such as
|
|
31
|
+
* the space between two words, or a syllable reading on into the characters the
|
|
32
|
+
* piece before it named.
|
|
33
|
+
*/
|
|
34
|
+
function sourcePositions(pieces) {
|
|
35
|
+
const positions = [];
|
|
36
|
+
let at = 0;
|
|
37
|
+
for (const piece of pieces) {
|
|
38
|
+
positions.push(at);
|
|
39
|
+
at += toCharacters(piece.source ?? "").length;
|
|
40
|
+
}
|
|
41
|
+
return positions;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What a piece written between two syllables makes of the join.
|
|
45
|
+
*
|
|
46
|
+
* Only a hyphen written where the syllables would otherwise have run together
|
|
47
|
+
* is 分词连写's internal boundary; anything else — a space, punctuation, a
|
|
48
|
+
* stretch that was never Han — separates two words.
|
|
49
|
+
*/
|
|
50
|
+
function junctionOver(text, held) {
|
|
51
|
+
return text === "-" && held === "join" ? "hyphen" : "break";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The syllables a conversion writes, with their positions and what joins them.
|
|
55
|
+
*
|
|
56
|
+
* A conversion writes its syllables as adjacent pieces within a word — the
|
|
57
|
+
* 隔音符号 is part of a syllable's own spelling rather than a piece of its own —
|
|
58
|
+
* so anything standing between two of them is a boundary, and the hyphen of
|
|
59
|
+
* 分词连写 is the one that is not a word boundary.
|
|
60
|
+
*/
|
|
61
|
+
function readingSyllables(pieces) {
|
|
62
|
+
const positions = sourcePositions(pieces);
|
|
63
|
+
const syllables = [];
|
|
64
|
+
// The first syllable of a text begins a word, whatever comes before it.
|
|
65
|
+
let junction = "break";
|
|
66
|
+
for (const [at, piece] of pieces.entries()) {
|
|
67
|
+
if (piece.syllable === undefined) {
|
|
68
|
+
junction = junctionOver(piece.text, junction);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
syllables.push({
|
|
72
|
+
piece: { ...piece, syllable: piece.syllable },
|
|
73
|
+
/* c8 ignore next -- one position is recorded for each piece there is */
|
|
74
|
+
at: positions[at] ?? 0,
|
|
75
|
+
junction,
|
|
76
|
+
});
|
|
77
|
+
junction = "join";
|
|
78
|
+
}
|
|
79
|
+
return syllables;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The readings the decode turned down without much reason to.
|
|
83
|
+
*
|
|
84
|
+
* The decode charges {@link READING_CHARGE} for a word boundary, so a rejected
|
|
85
|
+
* reading costing less than that was available without breaking any dictionary
|
|
86
|
+
* word apart — see {@link import("../decode/confidence.js").isUncertain}, which
|
|
87
|
+
* is the same threshold read as a question rather than as a filter. The library
|
|
88
|
+
* knows it was guessing there, so a learner who guessed the other way is not
|
|
89
|
+
* wrong.
|
|
90
|
+
*
|
|
91
|
+
* Only a rejected reading of exactly the one character this syllable reads is
|
|
92
|
+
* taken. An alternative can cover a different stretch — 玩儿 read as `wánr`
|
|
93
|
+
* competes with 玩 `wán` and 儿 `ér` — and a claim about other characters says
|
|
94
|
+
* nothing about what belongs in this position.
|
|
95
|
+
*/
|
|
96
|
+
function rejectedReadings(piece) {
|
|
97
|
+
const { confidence, source } = piece;
|
|
98
|
+
if (source === undefined || toCharacters(source).length !== 1) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
return (confidence?.alternatives ?? []).flatMap((alternative) => {
|
|
102
|
+
const [syllable] = alternative.reading;
|
|
103
|
+
return alternative.cost < READING_CHARGE &&
|
|
104
|
+
alternative.to - alternative.from === 1 &&
|
|
105
|
+
alternative.reading.length === 1 &&
|
|
106
|
+
syllable !== undefined
|
|
107
|
+
? [syllable]
|
|
108
|
+
: [];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gather readings into the spellings and tones they allow.
|
|
113
|
+
*
|
|
114
|
+
* The tone is allowed to be undefined only because {@link Syllable.tone} is: a
|
|
115
|
+
* reading that came out of the dictionary always carries one.
|
|
116
|
+
*/
|
|
117
|
+
function acceptedReadings(readings) {
|
|
118
|
+
const accepted = new Map();
|
|
119
|
+
for (const syllable of readings) {
|
|
120
|
+
const base = writeSyllableSpelling(syllable);
|
|
121
|
+
const tones = accepted.get(base) ?? new Set();
|
|
122
|
+
tones.add(syllable.tone);
|
|
123
|
+
accepted.set(base, tones);
|
|
124
|
+
}
|
|
125
|
+
return accepted;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Read the text, and work out what a typed syllable is allowed to be.
|
|
129
|
+
*
|
|
130
|
+
* Three conversions of the same text, and each one answers a different question.
|
|
131
|
+
* The first is the answer itself, with the confidence report beside it. The
|
|
132
|
+
* second is the other corner of the sandhi square, which is where the second
|
|
133
|
+
* form of every tone comes from. The third is the same text written under the
|
|
134
|
+
* other spacing convention, which is where a boundary's tolerance comes from:
|
|
135
|
+
* 分词连写 is what puts 了 on its verb and separates 市 from 南京, and a learner
|
|
136
|
+
* who wrote the words the dictionary knows instead — `tā kàn le`, `Nánjīngshì`
|
|
137
|
+
* — has written one of the two conventions this package implements rather than
|
|
138
|
+
* made a mistake.
|
|
139
|
+
*
|
|
140
|
+
* All three decode identically. Sandhi rewrites tones and 分词连写 moves
|
|
141
|
+
* boundaries; neither touches the syllables underneath, so all three line up one
|
|
142
|
+
* for one.
|
|
143
|
+
*/
|
|
144
|
+
function expectedReading(dictionary, text, options) {
|
|
145
|
+
const written = readingSyllables(convertPieces(dictionary, text, options));
|
|
146
|
+
const said = readingSyllables(convertPiecesUnscored(dictionary, text, {
|
|
147
|
+
...options,
|
|
148
|
+
sandhi: oppositeSandhi(options.sandhi),
|
|
149
|
+
}));
|
|
150
|
+
const spaced = readingSyllables(convertPiecesUnscored(dictionary, text, {
|
|
151
|
+
...options,
|
|
152
|
+
grouping: !(options.grouping ?? true),
|
|
153
|
+
}));
|
|
154
|
+
return written.map(({ piece, at, junction }, index) => {
|
|
155
|
+
// Sliced rather than indexed, so that a conversion somehow reporting fewer
|
|
156
|
+
// syllables than the others contributes nothing rather than needing a
|
|
157
|
+
// fallback: the caller's own conversion decides alone.
|
|
158
|
+
const alternate = said
|
|
159
|
+
.slice(index, index + 1)
|
|
160
|
+
.map((one) => one.piece.syllable);
|
|
161
|
+
const other = spaced.slice(index, index + 1).map((one) => one.junction);
|
|
162
|
+
return {
|
|
163
|
+
syllable: piece.syllable,
|
|
164
|
+
accepted: acceptedReadings([
|
|
165
|
+
piece.syllable,
|
|
166
|
+
...alternate,
|
|
167
|
+
...rejectedReadings(piece),
|
|
168
|
+
]),
|
|
169
|
+
// A hyphen is neither a break nor a join, and so allows both: it is a
|
|
170
|
+
// boundary the standard writes inside a word, and a learner rendering it
|
|
171
|
+
// as a space has not invented one.
|
|
172
|
+
acceptsBreak: junction !== "join" || other.some((one) => one !== "join"),
|
|
173
|
+
acceptsJoin: junction !== "break" || other.some((one) => one !== "break"),
|
|
174
|
+
source: piece.source,
|
|
175
|
+
at,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Read what was typed, one syllable at a time.
|
|
181
|
+
*
|
|
182
|
+
* {@link tokenisePinyin} is what the decoder is scored with, and it is tolerant
|
|
183
|
+
* in the two ways that matter here: word spacing is discarded, and the
|
|
184
|
+
* apostrophes and hyphens inside a word are read as the syllable boundaries
|
|
185
|
+
* they are and dropped. Both are orthography rather than pronunciation.
|
|
186
|
+
*
|
|
187
|
+
* A stretch that is not pinyin at all comes back whole, and is reported as
|
|
188
|
+
* written rather than thrown away.
|
|
189
|
+
*/
|
|
190
|
+
function typedReading(typed) {
|
|
191
|
+
const { syllables, wordStarts } = tokenisePinyin(typed);
|
|
192
|
+
return syllables.map((text, at) => {
|
|
193
|
+
const syllable = readSyllable(text);
|
|
194
|
+
return {
|
|
195
|
+
text,
|
|
196
|
+
syllable,
|
|
197
|
+
base: syllable === undefined
|
|
198
|
+
? text.toLowerCase().normalize("NFC")
|
|
199
|
+
: writeSyllableSpelling(syllable),
|
|
200
|
+
tone: syllable?.tone,
|
|
201
|
+
startsWord: wordStarts.has(at),
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Match the expected syllables up with the typed ones.
|
|
207
|
+
*
|
|
208
|
+
* Aligned on the toneless spellings, for the reason
|
|
209
|
+
* {@link import("../accuracy/score.js").scoreCase} aligns on them: a syllable
|
|
210
|
+
* dropped or invented halfway through would otherwise knock everything after it
|
|
211
|
+
* out of step, and be reported as a mistake on every syllable rather than on
|
|
212
|
+
* the one.
|
|
213
|
+
*
|
|
214
|
+
* What the alignment leaves over is then paired off within each gap, which is
|
|
215
|
+
* what turns two unrelated stretches into substitutions: 银行 typed `yínxíng`
|
|
216
|
+
* anchors on `yín`, leaving one expected `háng` against one typed `xíng` — one
|
|
217
|
+
* wrong syllable rather than one missing and one invented.
|
|
218
|
+
*/
|
|
219
|
+
function pairSyllables(expected, actual) {
|
|
220
|
+
const pairs = [];
|
|
221
|
+
let held = 0;
|
|
222
|
+
let typed = 0;
|
|
223
|
+
const gap = (untilExpected, untilActual) => {
|
|
224
|
+
while (held < untilExpected || typed < untilActual) {
|
|
225
|
+
const takesExpected = held < untilExpected;
|
|
226
|
+
const takesActual = typed < untilActual;
|
|
227
|
+
pairs.push({
|
|
228
|
+
expected: takesExpected ? held : undefined,
|
|
229
|
+
actual: takesActual ? typed : undefined,
|
|
230
|
+
});
|
|
231
|
+
held += takesExpected ? 1 : 0;
|
|
232
|
+
typed += takesActual ? 1 : 0;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
for (const anchor of alignSequences(expected, actual)) {
|
|
236
|
+
gap(anchor.expected, anchor.actual);
|
|
237
|
+
pairs.push({ expected: held, actual: typed });
|
|
238
|
+
held++;
|
|
239
|
+
typed++;
|
|
240
|
+
}
|
|
241
|
+
gap(expected.length, actual.length);
|
|
242
|
+
return pairs;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* What a typed syllable is, against what was expected in its place.
|
|
246
|
+
*
|
|
247
|
+
* The neutral tone is the one tone pinyin writes with no mark at all, so a
|
|
248
|
+
* syllable expected in it and typed without one has had its tone written
|
|
249
|
+
* correctly rather than left off.
|
|
250
|
+
*/
|
|
251
|
+
function verdictFor(expected, actual) {
|
|
252
|
+
const tones = expected.accepted.get(actual.base);
|
|
253
|
+
if (tones === undefined) {
|
|
254
|
+
return "wrong";
|
|
255
|
+
}
|
|
256
|
+
if (actual.tone === undefined) {
|
|
257
|
+
return tones.has(NEUTRAL_TONE) ? "correct" : "toneless";
|
|
258
|
+
}
|
|
259
|
+
return tones.has(actual.tone) ? "correct" : "tone";
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Where a typed syllable falls against the word boundaries.
|
|
263
|
+
*/
|
|
264
|
+
function spacingFor(expected, actual) {
|
|
265
|
+
if (actual.startsWord) {
|
|
266
|
+
return expected.acceptsBreak ? "correct" : "split";
|
|
267
|
+
}
|
|
268
|
+
return expected.acceptsJoin ? "correct" : "joined";
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Mark one pairing.
|
|
272
|
+
*
|
|
273
|
+
* The two axes are graded separately and reported separately, and a syllable
|
|
274
|
+
* only counts as right where both of them are: `yín háng` reads 银行 perfectly
|
|
275
|
+
* and writes it as two words, which is one mistake rather than none.
|
|
276
|
+
*/
|
|
277
|
+
function checkPair(expected, actual, required) {
|
|
278
|
+
const verdict = expected === undefined
|
|
279
|
+
? "extra"
|
|
280
|
+
: actual === undefined
|
|
281
|
+
? "missing"
|
|
282
|
+
: verdictFor(expected, actual);
|
|
283
|
+
const spacing = expected === undefined || actual === undefined
|
|
284
|
+
? undefined
|
|
285
|
+
: spacingFor(expected, actual);
|
|
286
|
+
const readRight = verdict === "correct" ||
|
|
287
|
+
(verdict === "toneless" && required.tones === "optional");
|
|
288
|
+
const spacedRight = spacing !== "split" && spacing !== "joined"
|
|
289
|
+
? true
|
|
290
|
+
: required.spacing === "optional";
|
|
291
|
+
return {
|
|
292
|
+
verdict,
|
|
293
|
+
spacing,
|
|
294
|
+
isCorrect: readRight && spacedRight,
|
|
295
|
+
expected: expected?.syllable,
|
|
296
|
+
actual: actual?.syllable,
|
|
297
|
+
text: actual?.text ?? "",
|
|
298
|
+
source: expected?.source,
|
|
299
|
+
at: expected?.at,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Mark a typed pinyin transcription against the text it was written for.
|
|
304
|
+
*
|
|
305
|
+
* ```ts
|
|
306
|
+
* check(dictionary, "北京", "bei3jing3").syllables.map((one) => one.verdict);
|
|
307
|
+
* // ["correct", "tone"]
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* **The point of doing this with a dictionary is being fair in the ways a
|
|
311
|
+
* string comparison cannot be**, and every one of these is a learner being
|
|
312
|
+
* marked wrong for being right:
|
|
313
|
+
*
|
|
314
|
+
* - **Either notation, mixed freely.** `běi` and `bei3` are the same syllable
|
|
315
|
+
* and both parse, so `bei3jīng` is not a spelling mistake.
|
|
316
|
+
* - **A reading the decoder itself was unsure of.** Where another reading of
|
|
317
|
+
* the same character was there for the taking, it is accepted — see
|
|
318
|
+
* {@link rejectedReadings}. 银行 is not one of those: the word settles both
|
|
319
|
+
* syllables, so `yínxíng` really is wrong.
|
|
320
|
+
* - **Sandhi either way.** 你好 is written `nǐ hǎo` and said `ní hǎo`, and 不是
|
|
321
|
+
* is `bú shì` written and `bù shì` underneath. Both pass.
|
|
322
|
+
* - **Tones written or not.** A syllable typed with no tone is `toneless`
|
|
323
|
+
* rather than `tone`, and {@link CheckOptions.tones} says whether that counts
|
|
324
|
+
* against the score. A neutral tone typed without a mark is simply correct,
|
|
325
|
+
* because that is how pinyin writes it.
|
|
326
|
+
* - **Apostrophes.** Not a word boundary and not a sound: `nǐhǎo`, `nǐ hǎo` and
|
|
327
|
+
* `nǐ'hǎo` all read the same, and check the same.
|
|
328
|
+
*
|
|
329
|
+
* Word spacing is graded on its own axis, reported as
|
|
330
|
+
* {@link CheckedSyllable.spacing} and counted only where
|
|
331
|
+
* {@link CheckOptions.spacing} asks for it — and tolerant in the same spirit,
|
|
332
|
+
* since 分词连写 and the words the dictionary knows are two conventions this
|
|
333
|
+
* package writes and a learner may have been taught either.
|
|
334
|
+
*
|
|
335
|
+
* What comes back is one {@link CheckedSyllable} per syllable expected or
|
|
336
|
+
* typed, in order, each naming the characters it reads and where they are, so
|
|
337
|
+
* that a mistake can be shown against the text rather than against the answer.
|
|
338
|
+
*
|
|
339
|
+
* This is {@link import("../accuracy/score.js").scoreCase} — the scorer that
|
|
340
|
+
* marks the decoder against the gold corpus — pointed at a person instead, and
|
|
341
|
+
* it costs three conversions of the text.
|
|
342
|
+
*/
|
|
343
|
+
export function check(dictionary, text, typed, options = {}) {
|
|
344
|
+
const { tones = "optional", spacing = "optional", ...converting } = options;
|
|
345
|
+
const expected = expectedReading(dictionary, text, converting);
|
|
346
|
+
const actual = typedReading(typed);
|
|
347
|
+
const syllables = pairSyllables(expected.map((one) => writeSyllableSpelling(one.syllable)), actual.map((one) => one.base)).map((pair) => checkPair(pair.expected === undefined ? undefined : expected[pair.expected], pair.actual === undefined ? undefined : actual[pair.actual], { tones, spacing }));
|
|
348
|
+
const correct = syllables.filter((one) => one.isCorrect).length;
|
|
349
|
+
return {
|
|
350
|
+
syllables,
|
|
351
|
+
isCorrect: correct === syllables.length,
|
|
352
|
+
score: syllables.length === 0 ? 1 : correct / syllables.length,
|
|
353
|
+
reading: expected.map((one) => one.syllable),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+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,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAEnC,MAAM,SAAS,GAAG,aAAa,CAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAC9B,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,SAAS,CACP,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EACjE,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAC3D,EAAE,KAAK,EAAE,OAAO,EAAE,CACnB,CACF,CAAC;IACF,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;IAEhE,OAAO;QACL,SAAS;QACT,SAAS,EAAE,OAAO,KAAK,SAAS,CAAC,MAAM;QACvC,KAAK,EAAE,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM;QAC9D,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type { ReadCharacters } from "./dictionary/reading.js";
|
|
|
24
24
|
export { pairScripts, TraditionalTable } from "./dictionary/traditional.js";
|
|
25
25
|
export type { ScriptPairing } from "./dictionary/traditional.js";
|
|
26
26
|
export { Dictionary } from "./dictionary/dictionary.js";
|
|
27
|
-
export type { WordEntry } from "./dictionary/dictionary.js";
|
|
27
|
+
export type { DictionaryReadings, WordEntry } from "./dictionary/dictionary.js";
|
|
28
28
|
export { fetchSource, loadArtifact, loadDictionary, loadScriptTables, SCRIPT_FILE, tierFiles, } from "./dictionary/source.js";
|
|
29
29
|
export type { DictionarySource } from "./dictionary/source.js";
|
|
30
30
|
export { convert, convertGreedily, convertPieces, joinPieces, } from "./decode/convert.js";
|
|
@@ -32,7 +32,7 @@ export type { ConvertedPiece, ConvertOptions } from "./decode/convert.js";
|
|
|
32
32
|
export { isUncertain, scoreReadings } from "./decode/confidence.js";
|
|
33
33
|
export type { ReadingAlternative, ReadingConfidence, ScoredUnit, } from "./decode/confidence.js";
|
|
34
34
|
export { decodeReadings, decodeRun, decodeRunScored, decodeSpacing, } from "./decode/decode.js";
|
|
35
|
-
export { convertToHtml, toHtml } from "./format/html.js";
|
|
35
|
+
export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, toHtml, } from "./format/html.js";
|
|
36
36
|
export { convertToWadeGiles, toTranscription, type TranscriptionOptions, type WriteWord, } from "./format/transcription.js";
|
|
37
37
|
export type { HtmlOptions } from "./format/html.js";
|
|
38
38
|
export { slug } from "./format/slug.js";
|
|
@@ -49,7 +49,8 @@ export { isSettled, projectReadings, settledUnits, unitsOf, } from "./decode/loc
|
|
|
49
49
|
export type { ReadingProjection, ReadingUnit } from "./decode/locking.js";
|
|
50
50
|
export { applyEdgeRules, tagOf, wordEndingAt, wordStartingAt, } from "./decode/rules.js";
|
|
51
51
|
export type { EdgeContext, EdgeRule, EdgeVerdict } from "./decode/rules.js";
|
|
52
|
-
export {
|
|
52
|
+
export type { PositionalReading, ReadingHint, ReadingHints, WordReading, } from "./decode/hints.js";
|
|
53
|
+
export { ADJECTIVAL_CHANG, ATTESTED_ERHUA, COUNTED_MEASURE, MODAL_DE, READING_RULES, TEACHING_JIAO, } from "./decode/reading-rules.js";
|
|
53
54
|
export { readingCost, shortestPath, spacingCost } from "./decode/viterbi.js";
|
|
54
55
|
export type { CostOf } from "./decode/viterbi.js";
|
|
55
56
|
export type { DecodedWord, ScoredWord, WordSeparator } from "./decode/word.js";
|
|
@@ -67,6 +68,16 @@ export type { YaleOptions } from "./transcription/yale.js";
|
|
|
67
68
|
export { readGwoyeu, writeGwoyeu, writeGwoyeuWord, } from "./transcription/gwoyeu.js";
|
|
68
69
|
export { readIpa, writeIpa, writeIpaSymbols, writeIpaWord, } from "./transcription/ipa.js";
|
|
69
70
|
export type { IpaOptions } from "./transcription/ipa.js";
|
|
71
|
+
export { segment } from "./decode/segment.js";
|
|
72
|
+
export type { Segment } from "./decode/segment.js";
|
|
73
|
+
export { match } from "./search/match.js";
|
|
74
|
+
export type { MatchRange, PinyinMatch } from "./search/match.js";
|
|
75
|
+
export { candidates, homophonesOf } from "./search/candidates.js";
|
|
76
|
+
export type { CandidateOptions, ScriptPreference, } from "./search/candidates.js";
|
|
77
|
+
export { ReverseIndex } from "./search/reverse-index.js";
|
|
78
|
+
export type { ReverseIndexBuild, ReverseIndexData, } from "./search/reverse-index.js";
|
|
79
|
+
export { check } from "./grade/check.js";
|
|
80
|
+
export type { CheckedSyllable, CheckOptions, CheckRequirement, PinyinCheck, PinyinVerdict, SpacingVerdict, } from "./grade/check.js";
|
|
70
81
|
export { splitRuns } from "./decode/runs.js";
|
|
71
82
|
export type { TextRun } from "./decode/runs.js";
|
|
72
83
|
export { applySandhi } from "./decode/sandhi.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,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E,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/E,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { fetchSource, loadArtifact, loadDictionary, loadScriptTables, SCRIPT_FIL
|
|
|
20
20
|
export { convert, convertGreedily, convertPieces, joinPieces, } from "./decode/convert.js";
|
|
21
21
|
export { isUncertain, scoreReadings } from "./decode/confidence.js";
|
|
22
22
|
export { decodeReadings, decodeRun, decodeRunScored, decodeSpacing, } from "./decode/decode.js";
|
|
23
|
-
export { convertToHtml, toHtml } from "./format/html.js";
|
|
23
|
+
export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, toHtml, } from "./format/html.js";
|
|
24
24
|
export { convertToWadeGiles, toTranscription, } from "./format/transcription.js";
|
|
25
25
|
export { slug } from "./format/slug.js";
|
|
26
26
|
export { decodeGreedily } from "./decode/greedy.js";
|
|
@@ -30,7 +30,7 @@ export { buildScriptTables } from "./dictionary/script-tables.js";
|
|
|
30
30
|
export { allEdges, buildLattice, cutPoints, READING_CHARGE, } from "./decode/lattice.js";
|
|
31
31
|
export { isSettled, projectReadings, settledUnits, unitsOf, } from "./decode/locking.js";
|
|
32
32
|
export { applyEdgeRules, tagOf, wordEndingAt, wordStartingAt, } from "./decode/rules.js";
|
|
33
|
-
export { ATTESTED_ERHUA, COUNTED_MEASURE, MODAL_DE, READING_RULES, TEACHING_JIAO, } from "./decode/reading-rules.js";
|
|
33
|
+
export { ADJECTIVAL_CHANG, ATTESTED_ERHUA, COUNTED_MEASURE, MODAL_DE, READING_RULES, TEACHING_JIAO, } from "./decode/reading-rules.js";
|
|
34
34
|
export { readingCost, shortestPath, spacingCost } from "./decode/viterbi.js";
|
|
35
35
|
export { cardinalHanzi, LARGEST_CARDINAL } from "./numerals/cardinal.js";
|
|
36
36
|
export { DIGIT_CHARACTERS, numeralSyllable, QUANTITY_CHARACTERS, UNIT_VALUES, yaoSyllable, } from "./numerals/characters.js";
|
|
@@ -40,6 +40,11 @@ export { readWadeGiles, readWadeGilesLoosely, writeWadeGiles, writeWadeGilesSpel
|
|
|
40
40
|
export { readYale, writeYale, writeYaleSpelling, writeYaleWord, } from "./transcription/yale.js";
|
|
41
41
|
export { readGwoyeu, writeGwoyeu, writeGwoyeuWord, } from "./transcription/gwoyeu.js";
|
|
42
42
|
export { readIpa, writeIpa, writeIpaSymbols, writeIpaWord, } from "./transcription/ipa.js";
|
|
43
|
+
export { segment } from "./decode/segment.js";
|
|
44
|
+
export { match } from "./search/match.js";
|
|
45
|
+
export { candidates, homophonesOf } from "./search/candidates.js";
|
|
46
|
+
export { ReverseIndex } from "./search/reverse-index.js";
|
|
47
|
+
export { check } from "./grade/check.js";
|
|
43
48
|
export { splitRuns } from "./decode/runs.js";
|
|
44
49
|
export { applySandhi } from "./decode/sandhi.js";
|
|
45
50
|
export { DEFAULT_TIER, selectTier, STANDARD_TIER_WORDS, TIERS, } from "./dictionary/tiers.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,UAAU,GACX,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EACL,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,SAAS,GACV,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iBAAiB,EACjB,cAAc,GACf,MAA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kB,EAClB,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,SAAS,EACT,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACL,UAAU,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type ScriptTables } from "../script/conversion.js";
|
|
2
|
+
import type { Script } from "../script/script.js";
|
|
3
|
+
import { type ReverseIndex } from "./reverse-index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Which script a caller wants a candidate list written in, and the tables that
|
|
6
|
+
* can tell.
|
|
7
|
+
*
|
|
8
|
+
* The two are one option because neither is any use without the other. Both
|
|
9
|
+
* scripts are dictionary keys, so a reading group holds 银行 *and* 銀行 — over a
|
|
10
|
+
* third of a typical list is that pairing — and the artifact deliberately does
|
|
11
|
+
* not record which 简体 form pairs with which 繁體 one, since conversion never
|
|
12
|
+
* needs it. So the index cannot pair them on its own, and honouring a
|
|
13
|
+
* preference means loading `script.map`: about 100 KB that the hanzi → pinyin
|
|
14
|
+
* path never fetches.
|
|
15
|
+
*
|
|
16
|
+
* Asking for the preference and the tables in one object is what keeps that
|
|
17
|
+
* cost visible at the call site rather than hidden inside a load.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const tables = await loadScriptTables(source);
|
|
21
|
+
* candidates(index, "yinhang", { script: { prefer: "Hans", tables } });
|
|
22
|
+
* // 银行, and not 銀行 beside it
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface ScriptPreference {
|
|
26
|
+
/** The script to keep where both writings of a word are candidates. */
|
|
27
|
+
readonly prefer: Script;
|
|
28
|
+
/** The conversion tables, from `loadScriptTables`. */
|
|
29
|
+
readonly tables: ScriptTables;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* How a candidate list should be narrowed.
|
|
33
|
+
*/
|
|
34
|
+
export interface CandidateOptions {
|
|
35
|
+
/** How many candidates to return at most. */
|
|
36
|
+
readonly limit?: number;
|
|
37
|
+
/** Keep one writing of a word rather than both; see {@link ScriptPreference}. */
|
|
38
|
+
readonly script?: ScriptPreference;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The words a pinyin query could be spelling, likeliest first.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* candidates(index, "shi"); // 是, 时, 事, 使, 市, …
|
|
45
|
+
* candidates(index, "shi4"); // narrowed by tone
|
|
46
|
+
* candidates(index, "shì"); // the same, written the other way
|
|
47
|
+
* candidates(index, "yinhang"); // 銀行, 银行, 引吭, 引航, 印航
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* This is the half of search that has no haystack: `match` filters Chinese text
|
|
51
|
+
* you already hold, and this answers a query with nothing but the dictionary
|
|
52
|
+
* behind it — pinyin-only lookup, a homophone list, or an input method for
|
|
53
|
+
* somebody with no Chinese keyboard.
|
|
54
|
+
*
|
|
55
|
+
* **A query is a whole reading, not a prefix.** `yinhang` finds 银行 and `yinha`
|
|
56
|
+
* finds nothing, because a reading key is a key rather than a stem. What a query
|
|
57
|
+
* may leave out is the parts a keyboard makes awkward: the tones, the ü, the
|
|
58
|
+
* spaces between syllables, and the r of 儿化.
|
|
59
|
+
*
|
|
60
|
+
* Both scripts are dictionary keys, so 银行 and 銀行 both come back unless a
|
|
61
|
+
* {@link ScriptPreference} says which to keep.
|
|
62
|
+
*/
|
|
63
|
+
export declare function candidates(index: ReverseIndex, query: string, options?: CandidateOptions): readonly string[];
|
|
64
|
+
/**
|
|
65
|
+
* The other words read exactly as this one is, likeliest first.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* homophonesOf(index, "长城"); // 長城, 長程, 长程, 常程 — everything read chángchéng
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* A homophone list wants the tone, where a typist's query does not, and it gets
|
|
72
|
+
* one without a second index: the toneless group is narrowed to the words whose
|
|
73
|
+
* stored reading is the same string. Over the eight busiest readings in the full
|
|
74
|
+
* dictionary — 4,659 candidates — that narrowing costs 1.2 ms in total.
|
|
75
|
+
*
|
|
76
|
+
* The word itself is never in its own list. Neither is its other-script writing
|
|
77
|
+
* where a {@link ScriptPreference} is given, since 銀行 is not a homophone of
|
|
78
|
+
* 银行 but the same word spelled for a different reader.
|
|
79
|
+
*
|
|
80
|
+
* Returns nothing for a word the dictionary does not hold, since a word with no
|
|
81
|
+
* reading has no homophones rather than all of them.
|
|
82
|
+
*/
|
|
83
|
+
export declare function homophonesOf(index: ReverseIndex, word: string, options?: CandidateOptions): readonly string[];
|
|
84
|
+
//# sourceMappingURL=candidates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../../src/search/candidates.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQlD,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAmCnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACpC;AA6LD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,SAAS,MAAM,EAAE,CA6BnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,gBAAqB,GAC7B,SAAS,MAAM,EAAE,CAkCnB"}
|