@kensio/pinyinjs 1.6.0 → 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 +211 -5
- package/data/core.entries +397 -396
- package/data/core.freq +0 -0
- package/data/core.keys +1 -0
- package/data/full.entries +9717 -9717
- package/data/manifest.json +12 -12
- package/data/script.map +7 -7
- package/data/standard.entries +967 -966
- package/data/standard.freq +0 -0
- package/data/standard.keys +1 -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 +207 -1
- 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 +16 -0
- package/dist/decode/convert.d.ts.map +1 -1
- package/dist/decode/convert.js +3 -28
- package/dist/decode/convert.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/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/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +16 -8
- 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/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 +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- 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 +9 -0
- package/dist/sources/unihan.d.ts.map +1 -1
- package/dist/sources/unihan.js +12 -1
- package/dist/sources/unihan.js.map +1 -1
- package/package.json +2 -3
- package/CHANGELOG.md +0 -634
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";
|
|
@@ -68,6 +68,16 @@ export type { YaleOptions } from "./transcription/yale.js";
|
|
|
68
68
|
export { readGwoyeu, writeGwoyeu, writeGwoyeuWord, } from "./transcription/gwoyeu.js";
|
|
69
69
|
export { readIpa, writeIpa, writeIpaSymbols, writeIpaWord, } from "./transcription/ipa.js";
|
|
70
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";
|
|
71
81
|
export { splitRuns } from "./decode/runs.js";
|
|
72
82
|
export type { TextRun } from "./decode/runs.js";
|
|
73
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;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EACZ,aAAa,EACb,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAErE,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
|
@@ -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,M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,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"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { encodeReading } from "../dictionary/artifact.js";
|
|
2
|
+
import { convertCharacters } from "../script/conversion.js";
|
|
3
|
+
import { toCanonicalGlyphs } from "../script/glyphs.js";
|
|
4
|
+
import { normaliseUmlaut, readSyllable, writeSyllable, } from "../syllable/syllable.js";
|
|
5
|
+
import { applyToneMark, stripToneMarks } from "../tone/tone-mark.js";
|
|
6
|
+
import { TONES } from "../tone/tone.js";
|
|
7
|
+
import { readingKey } from "./reverse-index.js";
|
|
8
|
+
/**
|
|
9
|
+
* What a query may write between syllables, all of which mean nothing here.
|
|
10
|
+
*
|
|
11
|
+
* The same set the matcher accepts, minus its meaning: `match` treats a written
|
|
12
|
+
* boundary as evidence, because a haystack it is filtering can be read more than
|
|
13
|
+
* one way. A reverse index is asked for one reading and answers with the words
|
|
14
|
+
* that have it, so `yin hang` and `yinhang` are the same question.
|
|
15
|
+
*/
|
|
16
|
+
const SEPARATORS = /[\s'’‘-]+/gu;
|
|
17
|
+
/**
|
|
18
|
+
* A tone written as a digit, which is the last character of a syllable.
|
|
19
|
+
*/
|
|
20
|
+
const TONE_DIGIT = /^[0-5]$/u;
|
|
21
|
+
/**
|
|
22
|
+
* Every tone a syllable that wrote none could be standing for.
|
|
23
|
+
*/
|
|
24
|
+
const TONE_DIGITS = ["1", "2", "3", "4", "5"];
|
|
25
|
+
/**
|
|
26
|
+
* The umlaut the readings are written with, and the letter a keyboard has.
|
|
27
|
+
*/
|
|
28
|
+
const UMLAUT = "ü";
|
|
29
|
+
const PLAIN_U = "u";
|
|
30
|
+
/**
|
|
31
|
+
* The 儿化 suffix, which is the one letter a reading key keeps and a query may
|
|
32
|
+
* leave off.
|
|
33
|
+
*/
|
|
34
|
+
const ERHUA = "r";
|
|
35
|
+
/**
|
|
36
|
+
* Put a typed query into both the forms a search needs.
|
|
37
|
+
*
|
|
38
|
+
* Case, spacing and the ways of writing ü are all noise on the way to the key,
|
|
39
|
+
* and the tone is noise there too — the index is keyed toneless. None of it is
|
|
40
|
+
* noise on the way to the *filter*, which is what honours a tone the query
|
|
41
|
+
* wrote, so the resolved spelling is kept alongside.
|
|
42
|
+
*
|
|
43
|
+
* A tone written as a mark counts here, unlike in `match`. The reason it cannot
|
|
44
|
+
* count there is that a mark says nothing about where its syllable ends and a
|
|
45
|
+
* half-typed query is exactly where that is unsettled; here the candidate's own
|
|
46
|
+
* reading says where every syllable ends, so the mark has somewhere to land.
|
|
47
|
+
*/
|
|
48
|
+
function readQuery(query) {
|
|
49
|
+
const written = normaliseUmlaut(query.normalize("NFC").toLowerCase()).replaceAll(SEPARATORS, "");
|
|
50
|
+
return { key: readingKey(stripToneMarks(written)), written };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Every way a typist may write one syllable of a stored reading.
|
|
54
|
+
*
|
|
55
|
+
* `shi4` is written `shi`, `shi4` or `shì`; `lü4` adds `lu` and `lu4`, since ü
|
|
56
|
+
* is not on the keyboard; and an 儿化 `wanr2` adds the whole set again with the
|
|
57
|
+
* r left off, because 玩儿 is `wanr` to one typist and `wan` to another.
|
|
58
|
+
*
|
|
59
|
+
* The r comes off only where the syllable really is 儿化. 儿 itself is `er2`,
|
|
60
|
+
* and letting that shed its r would answer `e` with 儿.
|
|
61
|
+
*/
|
|
62
|
+
function writingsOf(token) {
|
|
63
|
+
const digit = token.slice(-1);
|
|
64
|
+
const toned = TONE_DIGIT.test(digit);
|
|
65
|
+
const spelling = toned ? token.slice(0, -1) : token;
|
|
66
|
+
const syllable = readSyllable(token);
|
|
67
|
+
// A reading with no tone written cannot contradict one, so a query is free to
|
|
68
|
+
// write any. Every reading the shipped artifacts hold has a tone digit on it,
|
|
69
|
+
// so this is a case a hand-built dictionary reaches rather than a real one.
|
|
70
|
+
const tones = toned ? [digit] : TONE_DIGITS;
|
|
71
|
+
const written = new Set();
|
|
72
|
+
const add = (form) => {
|
|
73
|
+
const plain = form.replaceAll(UMLAUT, PLAIN_U);
|
|
74
|
+
written.add(form);
|
|
75
|
+
written.add(plain);
|
|
76
|
+
for (const tone of tones) {
|
|
77
|
+
written.add(`${form}${tone}`);
|
|
78
|
+
written.add(`${plain}${tone}`);
|
|
79
|
+
}
|
|
80
|
+
if (!toned) {
|
|
81
|
+
for (const tone of TONES) {
|
|
82
|
+
written.add(applyToneMark(form, tone));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
add(spelling);
|
|
87
|
+
if (syllable !== undefined) {
|
|
88
|
+
written.add(writeSyllable(syllable, "marks"));
|
|
89
|
+
if (syllable.erhua === true) {
|
|
90
|
+
add(spelling.slice(0, -ERHUA.length));
|
|
91
|
+
written.add(writeSyllable({ ...syllable, erhua: false }, "marks"));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return [...written];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether a query spells a reading, syllable by syllable.
|
|
98
|
+
*
|
|
99
|
+
* Walked as a set of positions the query can have been read up to rather than
|
|
100
|
+
* one cursor, because a syllable can be written more than one way and the ways
|
|
101
|
+
* are different lengths: `wanr2` is `wan` or `wanr`, and only what follows says
|
|
102
|
+
* which was meant.
|
|
103
|
+
*/
|
|
104
|
+
function spells(query, reading, writings) {
|
|
105
|
+
let reached = new Set([0]);
|
|
106
|
+
for (const token of reading.split(" ")) {
|
|
107
|
+
let forms = writings.get(token);
|
|
108
|
+
if (forms === undefined) {
|
|
109
|
+
forms = writingsOf(token);
|
|
110
|
+
writings.set(token, forms);
|
|
111
|
+
}
|
|
112
|
+
const next = new Set();
|
|
113
|
+
for (const at of reached) {
|
|
114
|
+
for (const form of forms) {
|
|
115
|
+
if (query.startsWith(form, at)) {
|
|
116
|
+
next.add(at + form.length);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (next.size === 0) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
reached = next;
|
|
124
|
+
}
|
|
125
|
+
return reached.has(query.length);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The reading the dictionary itself reports for a word, in numbered spelling.
|
|
129
|
+
*
|
|
130
|
+
* Asked of the dictionary rather than re-derived, which is what makes the
|
|
131
|
+
* filter also the answer to the ghost keys: 校覈 is a key, `Dictionary.lookup`
|
|
132
|
+
* folds it to 校核 before it searches, and the reading that comes back is
|
|
133
|
+
* `jiao4 he2` rather than the `xiao4 he2` the raw key derives to. So a candidate
|
|
134
|
+
* the dictionary would disown does not survive being checked against it.
|
|
135
|
+
*/
|
|
136
|
+
function readingOf(index, word) {
|
|
137
|
+
const entry = index.dictionary.lookup(word);
|
|
138
|
+
/* c8 ignore next -- only asked of a canonical key, which always looks up */
|
|
139
|
+
return entry === undefined ? "" : encodeReading(entry.reading);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The positions in every group a query can reach, likeliest first.
|
|
143
|
+
*
|
|
144
|
+
* Two groups, not one: the query as typed, and the query with the 儿化 r on the
|
|
145
|
+
* end. `wan` has to reach 玩儿 as well as 玩, and the r is kept in the key so
|
|
146
|
+
* that `wanr` can still reach only 玩儿. Whatever the second group brings in is
|
|
147
|
+
* then made honest by the filter, which is what stops `e` answering with 儿.
|
|
148
|
+
*/
|
|
149
|
+
function rankedPositions(index, key) {
|
|
150
|
+
const found = [
|
|
151
|
+
...index.positionsFor(key),
|
|
152
|
+
...index.positionsFor(`${key}${ERHUA}`),
|
|
153
|
+
];
|
|
154
|
+
// Both groups are already ranked, so this only has to interleave them. Sorted
|
|
155
|
+
// rather than merged because the comparison is one array read and the lists
|
|
156
|
+
// are short: the busiest reading in the full dictionary has 805 words in it.
|
|
157
|
+
return found.toSorted((left, right) => index.dictionary.frequencyAt(right) - index.dictionary.frequencyAt(left));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Keep one writing of a word where the group holds both scripts.
|
|
161
|
+
*
|
|
162
|
+
* Paired by 简体 form in both directions rather than by converting toward the
|
|
163
|
+
* preference, because simplification is many-to-one and so the 简体 form is the
|
|
164
|
+
* one both writings agree on. Going the other way needs a reading to tell 發
|
|
165
|
+
* from 髮, and a pair that failed to meet would simply be left as two.
|
|
166
|
+
*
|
|
167
|
+
* The kept writing takes the rank of the better-placed of the two, so
|
|
168
|
+
* collapsing a list never reorders what is left of it.
|
|
169
|
+
*/
|
|
170
|
+
function preferScript(words, script) {
|
|
171
|
+
/** Whether a candidate is the writing the caller asked for. */
|
|
172
|
+
const isWanted = (word, simplified) => script.prefer === "Hans" ? word === simplified : word !== simplified;
|
|
173
|
+
const chosen = new Map();
|
|
174
|
+
const order = [];
|
|
175
|
+
for (const word of words) {
|
|
176
|
+
const simplified = convertCharacters(script.tables.toSimplified, word);
|
|
177
|
+
const held = chosen.get(simplified);
|
|
178
|
+
if (held === undefined) {
|
|
179
|
+
chosen.set(simplified, word);
|
|
180
|
+
order.push(simplified);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!isWanted(held, simplified) && isWanted(word, simplified)) {
|
|
184
|
+
chosen.set(simplified, word);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/* c8 ignore next -- every entry in `order` was put in `chosen` beside it */
|
|
188
|
+
return order.map((simplified) => chosen.get(simplified) ?? simplified);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The words a pinyin query could be spelling, likeliest first.
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* candidates(index, "shi"); // 是, 时, 事, 使, 市, …
|
|
195
|
+
* candidates(index, "shi4"); // narrowed by tone
|
|
196
|
+
* candidates(index, "shì"); // the same, written the other way
|
|
197
|
+
* candidates(index, "yinhang"); // 銀行, 银行, 引吭, 引航, 印航
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* This is the half of search that has no haystack: `match` filters Chinese text
|
|
201
|
+
* you already hold, and this answers a query with nothing but the dictionary
|
|
202
|
+
* behind it — pinyin-only lookup, a homophone list, or an input method for
|
|
203
|
+
* somebody with no Chinese keyboard.
|
|
204
|
+
*
|
|
205
|
+
* **A query is a whole reading, not a prefix.** `yinhang` finds 银行 and `yinha`
|
|
206
|
+
* finds nothing, because a reading key is a key rather than a stem. What a query
|
|
207
|
+
* may leave out is the parts a keyboard makes awkward: the tones, the ü, the
|
|
208
|
+
* spaces between syllables, and the r of 儿化.
|
|
209
|
+
*
|
|
210
|
+
* Both scripts are dictionary keys, so 银行 and 銀行 both come back unless a
|
|
211
|
+
* {@link ScriptPreference} says which to keep.
|
|
212
|
+
*/
|
|
213
|
+
export function candidates(index, query, options = {}) {
|
|
214
|
+
const { key, written } = readQuery(query);
|
|
215
|
+
if (key === "") {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
const writings = new Map();
|
|
219
|
+
const found = [];
|
|
220
|
+
for (const position of rankedPositions(index, key)) {
|
|
221
|
+
const word = index.dictionary.wordAt(position);
|
|
222
|
+
// A key whose glyphs are not the canonical ones can never be returned by
|
|
223
|
+
// `Dictionary.lookup`, which folds them before it searches, so offering it
|
|
224
|
+
// would be offering 中峯 beside the 中峰 that is already here. 281 of the
|
|
225
|
+
// full tier's keys are like that, and dropping them at the query rather
|
|
226
|
+
// than the build is what makes it free: filtering the whole key list with
|
|
227
|
+
// `toCanonicalGlyphs` costs 52.9 ms, and filtering one answer costs nothing.
|
|
228
|
+
if (toCanonicalGlyphs(word) !== word) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (spells(written, readingOf(index, word), writings)) {
|
|
232
|
+
found.push(word);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const preferred = options.script === undefined ? found : preferScript(found, options.script);
|
|
236
|
+
return options.limit === undefined
|
|
237
|
+
? preferred
|
|
238
|
+
: preferred.slice(0, Math.max(0, options.limit));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The other words read exactly as this one is, likeliest first.
|
|
242
|
+
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* homophonesOf(index, "长城"); // 長城, 長程, 长程, 常程 — everything read chángchéng
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* A homophone list wants the tone, where a typist's query does not, and it gets
|
|
248
|
+
* one without a second index: the toneless group is narrowed to the words whose
|
|
249
|
+
* stored reading is the same string. Over the eight busiest readings in the full
|
|
250
|
+
* dictionary — 4,659 candidates — that narrowing costs 1.2 ms in total.
|
|
251
|
+
*
|
|
252
|
+
* The word itself is never in its own list. Neither is its other-script writing
|
|
253
|
+
* where a {@link ScriptPreference} is given, since 銀行 is not a homophone of
|
|
254
|
+
* 银行 but the same word spelled for a different reader.
|
|
255
|
+
*
|
|
256
|
+
* Returns nothing for a word the dictionary does not hold, since a word with no
|
|
257
|
+
* reading has no homophones rather than all of them.
|
|
258
|
+
*/
|
|
259
|
+
export function homophonesOf(index, word, options = {}) {
|
|
260
|
+
const entry = index.dictionary.lookup(word);
|
|
261
|
+
if (entry === undefined) {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
const reading = encodeReading(entry.reading);
|
|
265
|
+
const same = new Set([word, entry.word]);
|
|
266
|
+
if (options.script !== undefined) {
|
|
267
|
+
same.add(convertCharacters(options.script.tables.toSimplified, word));
|
|
268
|
+
}
|
|
269
|
+
const found = [];
|
|
270
|
+
for (const position of rankedPositions(index, readingKey(reading))) {
|
|
271
|
+
const candidate = index.dictionary.wordAt(position);
|
|
272
|
+
if (toCanonicalGlyphs(candidate) !== candidate) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const pairing = options.script === undefined
|
|
276
|
+
? candidate
|
|
277
|
+
: convertCharacters(options.script.tables.toSimplified, candidate);
|
|
278
|
+
if (same.has(candidate) || same.has(pairing)) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (readingOf(index, candidate) === reading) {
|
|
282
|
+
found.push(candidate);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const preferred = options.script === undefined ? found : preferScript(found, options.script);
|
|
286
|
+
return options.limit === undefined
|
|
287
|
+
? preferred
|
|
288
|
+
: preferred.slice(0, Math.max(0, options.limit));
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=candidates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidates.js","sourceRoot":"","sources":["../../src/search/candidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,aAAa,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC;;GAEG;AACH,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B;;GAEG;AACH,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,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,OAAO,EAAE,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GACb,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7E,OAAO,OAAO,CAAC,KAAK,KAAK,SAAS;QAChC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Dictionary } from "../dictionary/dictionary.js";
|
|
2
|
+
/**
|
|
3
|
+
* A stretch of the haystack the query spelled out.
|
|
4
|
+
*/
|
|
5
|
+
export interface MatchRange {
|
|
6
|
+
/**
|
|
7
|
+
* Where it starts, in code points from the start of the haystack.
|
|
8
|
+
*
|
|
9
|
+
* Code points rather than UTF-16 units, exactly as `Segment.at` is, so that a
|
|
10
|
+
* character outside the basic plane counts as the one character it is.
|
|
11
|
+
*/
|
|
12
|
+
readonly at: number;
|
|
13
|
+
/** How many characters it covers. */
|
|
14
|
+
readonly length: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What a query matched, and how well.
|
|
18
|
+
*/
|
|
19
|
+
export interface PinyinMatch {
|
|
20
|
+
/**
|
|
21
|
+
* The stretches of the haystack the query spelled, in order.
|
|
22
|
+
*
|
|
23
|
+
* Usually one. There is more than one where the query ran over something
|
|
24
|
+
* with no reading of its own: 北京·大学 is matched by `bjdx` as two ranges
|
|
25
|
+
* with the separator between them left out, so that highlighting them marks
|
|
26
|
+
* what was matched rather than what lay between.
|
|
27
|
+
*/
|
|
28
|
+
readonly ranges: readonly MatchRange[];
|
|
29
|
+
/**
|
|
30
|
+
* How good the match is, where higher is better.
|
|
31
|
+
*
|
|
32
|
+
* For ordering the haystacks one query matched — sort descending and the
|
|
33
|
+
* best is first. Comparable within a query and not across queries: what it
|
|
34
|
+
* weighs is described at {@link CONTEXT_READING}, and none of it is a
|
|
35
|
+
* probability.
|
|
36
|
+
*/
|
|
37
|
+
readonly score: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find where a pinyin query matches a Chinese text, for filtering and
|
|
41
|
+
* highlighting.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* match(dictionary, "北京大学", "bjdx")?.ranges; // [{ at: 0, length: 4 }]
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* The query is what somebody types on a Latin keyboard with no Chinese input
|
|
48
|
+
* method in front of them: full syllables joined or spaced, `beijing` and
|
|
49
|
+
* `bei jing`; initials, `bj`; the two mixed, `beij` and `bjing`; tones as
|
|
50
|
+
* digits where they are worth writing, `bei3jing1`; and `v` or `u:` for ü.
|
|
51
|
+
* Returns undefined where none of it matches.
|
|
52
|
+
*
|
|
53
|
+
* **No index is built and none is needed.** The haystack is Chinese, so the
|
|
54
|
+
* query is tested as a path over each character's readings rather than the text
|
|
55
|
+
* being spelled out in advance and searched — which is what makes every reading
|
|
56
|
+
* of a polyphone matchable rather than whichever one a default table picked.
|
|
57
|
+
* 行 is found by `xing` and by `hang`, and 长江 by `cj` as well as by `zj`.
|
|
58
|
+
*
|
|
59
|
+
* The reading the decoder settles on in context is then what ranks them, so the
|
|
60
|
+
* one that reads correctly here sorts above the one that merely could:
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* const scoreOf = (query: string) => match(dictionary, "银行", query)?.score;
|
|
64
|
+
* scoreOf("yh") > scoreOf("yx"); // true — 银行 is yínháng, not yínxíng
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Ranges rather than a boolean, so that a caller can mark what matched, in code
|
|
68
|
+
* points from the start of the text. Everything this needs is in the `core`
|
|
69
|
+
* dictionary, so a page that never loads a word list can still do it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function match(dictionary: Dictionary, haystack: string, query: string): PinyinMatch | undefined;
|
|
72
|
+
//# sourceMappingURL=match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/search/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAe9D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AA+cD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,KAAK,CACnB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,WAAW,GAAG,SAAS,CAMzB"}
|