@kensio/pinyinjs 1.2.0 → 1.2.2

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 (51) hide show
  1. package/CHANGELOG.md +111 -16
  2. package/README.md +35 -35
  3. package/data/core.entries +89 -89
  4. package/data/full.entries +257 -257
  5. package/data/manifest.json +6 -6
  6. package/data/standard.entries +102 -102
  7. package/dist/decode/convert.d.ts.map +1 -1
  8. package/dist/decode/convert.js +91 -40
  9. package/dist/decode/convert.js.map +1 -1
  10. package/dist/decode/decode.d.ts +12 -2
  11. package/dist/decode/decode.d.ts.map +1 -1
  12. package/dist/decode/decode.js +64 -7
  13. package/dist/decode/decode.js.map +1 -1
  14. package/dist/decode/reading-rules.d.ts +57 -0
  15. package/dist/decode/reading-rules.d.ts.map +1 -1
  16. package/dist/decode/reading-rules.js +178 -1
  17. package/dist/decode/reading-rules.js.map +1 -1
  18. package/dist/dictionary/assertions.d.ts.map +1 -1
  19. package/dist/dictionary/assertions.js +20 -0
  20. package/dist/dictionary/assertions.js.map +1 -1
  21. package/dist/dictionary/locale.d.ts +55 -0
  22. package/dist/dictionary/locale.d.ts.map +1 -0
  23. package/dist/dictionary/locale.js +323 -0
  24. package/dist/dictionary/locale.js.map +1 -0
  25. package/dist/dictionary/merge.d.ts +3 -1
  26. package/dist/dictionary/merge.d.ts.map +1 -1
  27. package/dist/dictionary/merge.js +54 -10
  28. package/dist/dictionary/merge.js.map +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -2
  32. package/dist/index.js.map +1 -1
  33. package/dist/numerals/cardinal.d.ts +15 -1
  34. package/dist/numerals/cardinal.d.ts.map +1 -1
  35. package/dist/numerals/cardinal.js +8 -1
  36. package/dist/numerals/cardinal.js.map +1 -1
  37. package/dist/numerals/characters.d.ts +9 -0
  38. package/dist/numerals/characters.d.ts.map +1 -1
  39. package/dist/numerals/characters.js +18 -0
  40. package/dist/numerals/characters.js.map +1 -1
  41. package/dist/numerals/numerals.d.ts.map +1 -1
  42. package/dist/numerals/numerals.js +12 -4
  43. package/dist/numerals/numerals.js.map +1 -1
  44. package/dist/numerals/text.d.ts +23 -9
  45. package/dist/numerals/text.d.ts.map +1 -1
  46. package/dist/numerals/text.js +93 -9
  47. package/dist/numerals/text.js.map +1 -1
  48. package/dist/orthography/capitals.d.ts.map +1 -1
  49. package/dist/orthography/capitals.js +25 -8
  50. package/dist/orthography/capitals.js.map +1 -1
  51. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -11,6 +11,15 @@ which a dictionary rebuild can change, and the artifact format under `data/`.
11
11
 
12
12
  ### Added
13
13
 
14
+ - **`TEACHING_JIAO` and `COUNTED_MEASURE`,** two more lattice rules, and
15
+ `QUANTITY_CHARACTERS`, the 汉字 a quantity is written with that the second of
16
+ them asks about. See the fixes below for what they do and what they measure.
17
+ - **`counts` on the numeral options.** Whether the number stands immediately in
18
+ front of something it counts, which is what makes a lone 2 两:
19
+ `numeralHanzi(2, { counts: true })` is `两` and `numeralHanzi(2)` is `二`.
20
+ Unlike `liang` it is not a variable choice — 二个 is simply wrong — but
21
+ nothing about the number says whether it is counting, so the caller says.
22
+ `convert` sets it from the character after the digits.
14
23
  - **`SYLLABLE_TONES` and `isAttestedTone`.** Which tones each of the 424
15
24
  syllables is actually written in, extracted from the merged dictionary and
16
25
  held to it by a build assertion. 424 syllables in five tones would be 2,120
@@ -24,23 +33,81 @@ which a dictionary rebuild can change, and the artifact format under `data/`.
24
33
  en.wiktionary's Mandarin pronunciation blocks, in bopomofo, Wade-Giles, Yale
25
34
  and GR with their tones, and all 50 rows of Wikipedia's _Help:IPA/Mandarin_
26
35
  key. The 417-row syllabary already checked was toneless, so it could say
27
- nothing about tone marks, the neutral tone, 儿化 or how a word is joined —
36
+ nothing about tone marks, the neutral tone, 儿化 or how a word is joined,
28
37
  which is where the four fixes below were found.
29
38
 
30
39
  ### Fixed
31
40
 
41
+ - **教 was `jiào` even where it was teaching.** 他在北京大学教了三年书 came out
42
+ `jiàole sān nián shū`, and 我教英语, 谁教你法语 and 她教我如何游泳 with it.
43
+ The dictionary stores 教 as `jiào` with `jiāo` as an alternate, and `jiào` is
44
+ right for the compounds — 教育, 教师, 宗教, 主教 — which are words and reach
45
+ their reading through the word; what is left is the 教 standing as a word of
46
+ its own, and that one is the verb. The object is what says so: a pronoun, a
47
+ noun or a name after it, or an aspect particle, since only a verb takes 了,
48
+ 过 or 得. Forcing the character's own reading was not enough on its own,
49
+ because a two-character reading carries its 教 into the position from
50
+ outside — 王老师教我们汉语 read `jiào` off 师教 and 来教我 off 来教 — so an
51
+ untagged pair ending in 教 goes too, while every tagged word keeps its
52
+ reading: 任教, 宗教, 主教, 佛教, 传教, 执教, 请教, 家教. Over 88,866 lines
53
+ 181 教 decode as a word of their own and every one read `jiào`; 158 are now
54
+ `jiāo`, three of them wrongly — 统一教创始人, 方法教深思 and 做到了教政分离,
55
+ where a nominal compound takes an object's shape. CPP's polyphone score is
56
+ 89.05%, up from 89.04%.
57
+ - **A 量词 was swallowed by the word behind it.** 三个人 was `sān gèrén`, three
58
+ _personals_, because 个人 is a common noun and nothing weighed it against the
59
+ 个 belonging to the 三 in front of it. It is now `sān gè rén`, and so are
60
+ 两家人, 三杯水, 四匹马, 十八层楼 and 一段长时间. What makes it decidable is
61
+ that the dictionary tags the 量词: 个, 次, 天 and 杯 are `q`, while the
62
+ characters that only look like measure words in this position are not — 分 is
63
+ a verb, 部 and 成 are nouns, 年 and 点 are numerals — so 五分钟, 三部分,
64
+ 五成分, 五年级 and 三点钟 are untouched, and those are exactly the words a
65
+ blanket rule would break. Nor does an ordinal count anything (第三集团军), nor
66
+ a numeral inside a longer word (唯一道路), and a number and its measure
67
+ written solid survive whole where the dictionary has them: 一辈子, 一会儿,
68
+ 一口气 and 两口子 are unchanged. Over 88,866 lines the rule forbids 561 edges
69
+ and moves 53 decodes, three of them wrongly — 一批评, 这一名词 and 六七股灾,
70
+ where the 一 and the 六七 count nothing. Exactly one reading changes in the
71
+ whole corpus and it is a fix: 已经下了两天雨了 read 天雨 as `tiān yù`.
72
+ - **The Han after a number was decoded without it.** 2个人 was `liǎng gèrén`
73
+ while 两个人 written out was already `liǎng gè rén`, because a Han run was
74
+ decoded on its own and had no idea a number preceded it. A run is now decoded
75
+ with the 汉字 the digits stand for in front of it, and reported without them,
76
+ so digits and 汉字 reach the same decode. `decodeRun` and `decodeRunScored`
77
+ take that context as a fourth argument; where a reading would straddle the
78
+ join — 1点儿事, whose 一点儿 is one `yìdiǎnr` over both sides of it — the run
79
+ is decoded alone, as before.
80
+ - **A lone 2 in front of a 量词 was read 二.** 我们买了2个西瓜 came out as
81
+ `wǒmen mǎile èr gè xīguā`, and a 2 standing immediately in front of what it
82
+ counts is 两: it is now `liǎng gè`, and 2岁 is `liǎng suì`, 2点 `liǎng diǎn`
83
+ and 2万人 `liǎng wàn rén`, the same 两 that 2,000 and 2:00 already got. The
84
+ measure words a 2 can count with are an open list, so 两 is the default and
85
+ the exceptions are named — 月, 日, 号, 楼, 路, 班 and 期, where the digit
86
+ labels a position rather than counting (2月 is `èr yuè`), an ordinal, which
87
+ the 第 in front of it marks (第2次 is `dì èr cì`), and 十 and 百, which follow
88
+ 二 as 20 and 200 already do. A 2 inside a larger number is untouched: 12个 is
89
+ still `shí'èr gè`.
90
+ - **A decimal lost the grouping of its counted part.** 一共75.5元 was
91
+ `yígòng qī shí wǔ diǎn wǔ yuán`, with the 75 in loose syllables, and is now
92
+ `yígòng qīshíwǔ diǎn wǔ yuán`, the same word 一共75元 already got. Only what
93
+ follows the 点 is read a digit at a time, and that part is unchanged: 3.14 is
94
+ still `sān diǎn yī sì`, and sandhi still stops at the point.
95
+ - **A decimal point was read as a full stop.** 一共75.5元 came back as
96
+ `Yígòng …`, capitalised as though the text were a sentence, and a conversion
97
+ keeping its digits capitalised again after the point: 我有75.5个。was
98
+ `Wǒ yǒu75.5Gè.` A stop between two digits now ends no sentence.
32
99
  - **Bopomofo wrote the tone mark after the 儿化 ㄦ.** 哪儿 nǎr was `ㄋㄚㄦˇ` and
33
100
  is now `ㄋㄚˇㄦ`: the mark belongs to the nucleus and the suffix is not part of
34
101
  what it marks. A mark written after the ㄦ is still read.
35
102
  - **Wade-Giles put the tone digit on the 儿化 suffix,** so 花儿 huār was
36
- `hua-êrh¹` — a first-tone 兒. It is now `hua¹-'rh`, with the digit on the
103
+ `hua-êrh¹`, a first-tone 兒. It is now `hua¹-'rh`, with the digit on the
37
104
  syllable the tone belongs to and the suffix written as the reduced `'rh` that
38
105
  keeps it apart from 女儿 nǚ'ér's `nü³-êrh²`.
39
106
  - **Gwoyeu Romatzyh wrote 儿化 as a plain `-l` suffix.** GR fuses it into the
40
107
  rime instead, and the rules are now implemented as _Spelling in Gwoyeu
41
108
  Romatzyh_ gives them: 玩儿 wánr is `wal` rather than `wanl`, 事儿 shìr is
42
109
  `shell`, 今儿 jīnr is `jiel`. The fusion is many-to-one, so `jiel` is 今儿 and
43
- 鸡儿 both and 128 forms no longer round-trip — every one of them a form the
110
+ 鸡儿 both and 128 forms no longer round-trip, every one of them a form the
44
111
  language does not write.
45
112
  - **Gwoyeu Romatzyh wrote `.mhe` for a neutral 么.** The `-h-` is the first tone
46
113
  of a sonorant initial, and a neutral syllable is in no tone at all; the basic
@@ -49,22 +116,50 @@ which a dictionary rebuild can change, and the artifact format under `data/`.
49
116
  follows the broader IPA column of _Comparison of Standard Chinese
50
117
  transcription systems_, which is where its ground truth comes from; the two
51
118
  pages differ at the medials, -ang, the empty rhyme and the diphthongs. No
52
- output changed — the claim did.
119
+ output changed, only the claim.
53
120
  - **`--system ipa` capitalised the IPA.** 我去银行。他姓王。 came out as
54
121
  `Uo˨˩˦ ... Tʰa˥ ɕiŋ˥˩ Uaŋ˧˥`, with the sentence capital and the proper noun
55
122
  carried over from the pinyin as though a transcription spelled words. IPA
56
- letters are symbols rather than an alphabet — `[T]` is not `[t]` in a larger
57
- size but a symbol the IPA does not have — so the capitals are now dropped for
123
+ letters are symbols rather than an alphabet, since `[T]` is not `[t]` in a
124
+ larger size but a symbol the IPA does not have, so the capitals are now dropped for
58
125
  IPA and bopomofo and kept for the three romanisations. `toTranscription`
59
126
  takes `{ capitals: false }` for callers writing their own.
127
+ - **A compound lost the zh-TW reading its own parts carry.** 垃圾分類 read
128
+ `lājīfēnlèi` under `zh-TW`, because CC-CEDICT marks `Taiwan pr.` on 垃圾 and
129
+ 垃圾桶 and on no other compound, and the decoder prefers the longer word, so
130
+ the entry that had the delta was never consulted. 101 compounds now compose
131
+ one from their constituents, 垃圾 accounting for 14 of them and 比肩, 玳瑁,
132
+ 从容, 骨头, 蜗牛 and 说服 for most of the rest. Three guards keep it honest:
133
+ the constituent has to survive segmentation (運行狀況 contains 行狀 but reads
134
+ 運行 + 狀況), it has to be read in the compound exactly as its own entry reads
135
+ it, and it has to be a whole word rather than a bare character, since 會's `huǐ`
136
+ would rewrite 三合會 as `sānhéhuǐ` and 3,743 entries would compose that way
137
+ against the 101 that whole words compose.
138
+ - **A character's zh-TW delta was often a choice between its 普通话 senses.**
139
+ 从容地 read `cōngróng dì` and 他都知道 read `tā dū zhīdào` under `zh-TW`,
140
+ because 地 was stored with a Taiwan reading of `dì` and 都 with `dū`. Neither
141
+ is a locale shift: CC-CEDICT lists 地[de5] and 地[di4] as separate entries, so
142
+ `dì` is what 地 reads in 普通话 when it means the ground, and the adverbial
143
+ particle is `de` in Taipei too. A delta the word already has as a 普通话 sense
144
+ is now refused, so 71 characters and 3 words lose one, 都, 着, 应, 差, 称, 斗,
145
+ 舍, 薄 and 万 among them, while 和 `hàn`, 期 `qí`, 垃 `lè` and 髮 `fǎ` stay,
146
+ no 普通话 sense reading any of those that way. A `Taiwan pr.` note is also
147
+ only read off a sense matching the reading the entry settled on, which drops
148
+ 16 more: the note on 著's chess-move sense, which reads `zhāo`, had been
149
+ giving the aspect particle 着 a 國語 reading of `zhuó`.
150
+ - **A locale delta overwrote a reading it was not measured against.** The delta
151
+ describes the entry's own 普通话 reading, so a polyphone the decode read some
152
+ other way, such as 得 forced to the modal `děi` rather than the particle `de`
153
+ its entry stores, now keeps what the decode worked out instead of being
154
+ rewritten from the entry.
60
155
 
61
156
  ### Changed
62
157
 
63
158
  - **Reading a romanisation narrows on the tone that was written.**
64
159
  `readWadeGiles("lo²")` was `[luó, ló]` and is now `[luó]`: 咯 is a
65
160
  sentence-final particle and is only ever neutral, so ló is not a syllable
66
- Mandarin has. The same goes for `readWadeGilesLoosely` — `pan²` is pán alone
67
- — and for `readYale`, `readIpa` and `readGwoyeu`, where it settles the 儿化
161
+ Mandarin has. The same goes for `readWadeGilesLoosely`, where `pan²` is pán
162
+ alone, and for `readYale`, `readIpa` and `readGwoyeu`, where it settles the 儿化
68
163
  collisions the same way (`ell` is 二 èr, there being no first-tone 兒).
69
164
  Narrowing never empties a list: a tone no candidate is written in leaves the
70
165
  candidates alone, since that says the tone is wrong rather than the spelling.
@@ -86,7 +181,7 @@ decoder internals and the build pipeline.
86
181
  - **Transcription systems, all five, in both directions.** Bopomofo, Wade-Giles,
87
182
  Yale, Gwoyeu Romatzyh and IPA at the syllable level, plus hanzi → any of them
88
183
  end to end via `convert --system` and `convertToWadeGiles`. Checked against
89
- 417 rows of an outside syllabary in every system — 3,336 cells.
184
+ 417 rows of an outside syllabary in every system, which is 3,336 cells.
90
185
  - **Reading ambiguous Wade-Giles.** `readWadeGilesLoosely` allows for the
91
186
  apostrophes and diacritics real texts drop, and `splitWadeGiles` puts back the
92
187
  hyphens they lose. Measured: 52.07% of written syllables lose their identity
@@ -97,7 +192,7 @@ decoder internals and the build pipeline.
97
192
  follows them.
98
193
  - **Orthography rules.** The 重叠 hyphen for AABB and repeated words, the 成语
99
194
  hyphen from a curated list of 117, 老王 → `Lǎo Wáng`, and GB/T 16159 5.1 in
100
- full — 毛泽东 is `Máo Zédōng`, 北京大学 is `Běijīng Dàxué`, on boundaries
195
+ full, so 毛泽东 is `Máo Zédōng` and 北京大学 is `Běijīng Dàxué`, on boundaries
101
196
  CC-CEDICT's own capitalisation states.
102
197
  - **Typed rule overrides on the lattice** (`READING_RULES`), with the modal 得
103
198
  and attested 儿化 as the first two.
@@ -130,17 +225,17 @@ decoder internals and the build pipeline.
130
225
 
131
226
  ### Accuracy at 1.0.0
132
227
 
133
- Over the 105-case gold corpus, which is committed to the repository — not to
134
- the published package — and scored by `pnpm accuracy`:
228
+ Over the 118-case gold corpus, which is committed to the repository rather than
229
+ to the published package, and scored by `pnpm accuracy`:
135
230
 
136
231
  | | lattice | greedy baseline |
137
232
  | ---------------- | --------: | --------------: |
138
- | exact match | **97.1%** | 92.4% |
139
- | reading accuracy | 99.7% | 98.6% |
140
- | spacing (F1) | **99.7%** | 97.0% |
233
+ | exact match | **97.5%** | 88.1% |
234
+ | reading accuracy | 99.7% | 98.3% |
235
+ | spacing (F1) | **99.8%** | 96.3% |
141
236
 
142
237
  Every figure in that table is asserted against the scorer by
143
- `src/changelog.test.ts`, because a number nothing executes goes stale — which is
238
+ `src/changelog.test.ts`, because a number nothing executes goes stale, which is
144
239
  what happened to this project's README table across three releases.
145
240
 
146
241
  `pnpm polyphones` reports 89.04% for the lattice against greedy's 88.82% over
package/README.md CHANGED
@@ -70,7 +70,7 @@ A command given no arguments reads standard input, one text per line, so
70
70
  dictionary at all and start without loading one.
71
71
 
72
72
  At a terminal each syllable is written in its tone's colour, in
73
- [MDBG](https://www.mdbg.net)'s palette — red, yellow, green, blue, and the
73
+ [MDBG](https://www.mdbg.net)'s palette of red, yellow, green, blue, and the
74
74
  terminal's own colour for the neutral tone. It is off for a pipe, `NO_COLOR` is
75
75
  honoured, `--colour` and `--no-colour` force it either way, and `--json` is
76
76
  never coloured. See [the command line](docs/cli/#colour).
@@ -85,9 +85,8 @@ $ pinyinjs convert 银行
85
85
  yínháng
86
86
  ```
87
87
 
88
- Everything else has columns for a person to read. Add `--json` — to any
89
- command — and it writes one JSON document per answer instead, which is what
90
- `jq` wants:
88
+ Everything else has columns for a person to read. Add `--json` to any command
89
+ and it writes one JSON document per answer instead, which is what `jq` wants:
91
90
 
92
91
  ```console
93
92
  $ pinyinjs explain 长江大桥 --json | jq -c '.syllables[] | select(.state != "locked")'
@@ -149,16 +148,16 @@ first, convert with it, and reload as `full` arrives.
149
148
  convert(dictionary, "银行"); // "yínháng"
150
149
  convert(dictionary, "行长"); // "hángzhǎng"
151
150
  convert(dictionary, "我要去北京。"); // "Wǒ yào qù Běijīng."
152
- convert(dictionary, "3D银行"); // "sān D yínháng" — the digit is read, the letter is not
151
+ convert(dictionary, "3D银行"); // "sān D yínháng", the digit is read, the letter is not
153
152
  ```
154
153
 
155
154
  A reading the dictionary cannot settle on its own is settled by context, with
156
155
  typed rules over the lattice rather than tweaks to the output:
157
156
 
158
157
  ```ts
159
- convert(dictionary, "我得走了"); // "wǒ děi zǒule" — modal 得
160
- convert(dictionary, "他跑得很快"); // "tā pǎo de hěn kuài" — the particle
161
- convert(dictionary, "那边儿"); // "nà biānr" — 儿 does not stand on its own
158
+ convert(dictionary, "我得走了"); // "wǒ děi zǒule", modal 得
159
+ convert(dictionary, "他跑得很快"); // "tā pǎo de hěn kuài", the particle
160
+ convert(dictionary, "那边儿"); // "nà biānr", 儿 does not stand on its own
162
161
  ```
163
162
 
164
163
  See [converting](docs/converting/#rules-where-the-cost-model-cannot-reach).
@@ -226,7 +225,7 @@ writes in a way no rule reaches.
226
225
 
227
226
  ```ts
228
227
  convert(dictionary, "他看了"); // "tā kànle"
229
- convert(dictionary, "我还给你了。"); // "Wǒ huán gěi nǐ le." — sentence-final 了
228
+ convert(dictionary, "我还给你了。"); // "Wǒ huán gěi nǐ le.", sentence-final 了
230
229
  convert(dictionary, "作者"); // "zuòzhě"
231
230
  convert(dictionary, "南京市"); // "Nánjīng Shì"
232
231
  convert(dictionary, "南京市", { grouping: false }); // "Nánjīngshì"
@@ -246,7 +245,7 @@ a boundary inside it.
246
245
  ```ts
247
246
  convert(dictionary, "干干净净"); // "gāngān-jìngjìng"
248
247
  convert(dictionary, "研究研究"); // "yánjiū-yánjiū"
249
- convert(dictionary, "爸爸妈妈"); // "bàba māma" — that shape, but two words
248
+ convert(dictionary, "爸爸妈妈"); // "bàba māma", that shape, but two words
250
249
  ```
251
250
 
252
251
  **A 成语 that can be read as two disyllables** takes the same hyphen, from a
@@ -254,7 +253,7 @@ curated list of 117; the rest are written solid, as the standard writes them.
254
253
 
255
254
  ```ts
256
255
  convert(dictionary, "风平浪静"); // "fēngpíng-làngjìng"
257
- convert(dictionary, "不亦乐乎"); // "búyìlèhū" — cannot be halved
256
+ convert(dictionary, "不亦乐乎"); // "búyìlèhū", cannot be halved
258
257
  ```
259
258
 
260
259
  **Digits are read**, and the rest of a non-Han run passes through exactly as
@@ -266,7 +265,7 @@ convert(dictionary, "1988年之后"); // "yī jiǔ bā bā nián zhīhòu"
266
265
  convert(dictionary, "95%的人"); // "bǎifēnzhījiǔshíwǔ de rén"
267
266
  convert(dictionary, "3D打印"); // "sān D dǎyìn"
268
267
  convert(dictionary, "6:30起床"); // "liù diǎn sānshí fēn qǐchuáng"
269
- convert(dictionary, "16:9的"); // "16:9de" — a ratio is not a quantity
268
+ convert(dictionary, "16:9的"); // "16:9de", a ratio is not a quantity
270
269
  ```
271
270
 
272
271
  `numbers: "keep"` leaves every digit alone. See [numbers](docs/numerals/).
@@ -282,13 +281,13 @@ import { convertPieces, isUncertain, writeSyllable } from "@kensio/pinyinjs";
282
281
  const pieces = convertPieces(dictionary, "银行");
283
282
  pieces.map((piece) => piece.text); // ["yín", "háng"]
284
283
  pieces[1]?.syllable; // { initial: "h", final: "ang", tone: 2 }
285
- pieces[0]?.confidence?.isLocked; // true — nothing else can be read here
284
+ pieces[0]?.confidence?.isLocked; // true, nothing else can be read here
286
285
  pieces[1]?.confidence?.alternatives.map((found) =>
287
286
  found.reading.map((syllable) => writeSyllable(syllable)).join(""),
288
287
  ); // ["xíng", "héng", "hàng"]
289
288
  ```
290
289
 
291
- A piece with no `syllable` is the text between two of them — a space, or a run
290
+ A piece with no `syllable` is the text between two of them: a space, or a run
292
291
  that was never Han. `joinPieces(pieces)` gives back exactly what `convert`
293
292
  returns.
294
293
 
@@ -306,8 +305,8 @@ const guesses = (text: string) =>
306
305
  (piece) => piece.confidence !== undefined && isUncertain(piece.confidence),
307
306
  );
308
307
 
309
- guesses("行").map((piece) => piece.text); // ["xíng"] — nothing but a prior chose it
310
- guesses("银行").map((piece) => piece.text); // [] — the word settles both syllables
308
+ guesses("行").map((piece) => piece.text); // ["xíng"], nothing but a prior chose it
309
+ guesses("银行").map((piece) => piece.text); // [], the word settles both syllables
311
310
  ```
312
311
 
313
312
  An alternative's `cost` says how much more the cheapest conversion taking it
@@ -327,7 +326,7 @@ convertToHtml(dictionary, "行");
327
326
  One element per syllable, with `py-tone-1` to `py-tone-5` (5 is the neutral
328
327
  tone), and `py-uncertain` plus the rejected readings where the decoder was
329
328
  guessing. Text that is not Han is escaped, not marked up. No styles are
330
- included — write your own:
329
+ included, so write your own:
331
330
 
332
331
  ```css
333
332
  .py-tone-1 {
@@ -348,12 +347,12 @@ have.
348
347
  const entry = dictionary.lookup("头发");
349
348
  entry?.reading; // [{ initial: "t", final: "ou", tone: 2 }, { initial: "f", final: "a", tone: 5 }]
350
349
  entry?.isProperNoun; // false
351
- entry?.partOfSpeech; // "n" — jieba's tag
350
+ entry?.partOfSpeech; // "n", jieba's tag
352
351
 
353
352
  dictionary.lookup("頭髮")?.reading; // the same reading, found under 繁體
354
353
  dictionary.lookup("重複")?.reading; // 重複 and 重覆 are both keys for 重复
355
- dictionary.hasPrefix("银"); // true — does any word start with this?
356
- dictionary.readingsOf("行"); // xíng, háng, héng, hàng — likeliest first
354
+ dictionary.hasPrefix("银"); // true, does any word start with this?
355
+ dictionary.readingsOf("行"); // xíng, háng, héng, hàng, likeliest first
357
356
  ```
358
357
 
359
358
  Both scripts are keys in the same dictionary, so nothing is converted before a
@@ -367,12 +366,12 @@ The syllable layer needs no dictionary and no network.
367
366
  import { isSyllable, readSyllable, writeSyllable } from "@kensio/pinyinjs";
368
367
 
369
368
  readSyllable("jiù"); // { initial: "j", final: "iou", tone: 4 }
370
- readSyllable("jiu4"); // the same — both notations parse
369
+ readSyllable("jiu4"); // the same, both notations parse
371
370
  readSyllable("lv4"); // { initial: "l", final: "ü", tone: 4 }
372
371
  readSyllable("hello"); // undefined
373
- readSyllable("běi3"); // undefined — one notation at a time
372
+ readSyllable("běi3"); // undefined, one notation at a time
374
373
 
375
- isSyllable("wánr"); // true — 儿化 is a suffix, not a syllable of its own
374
+ isSyllable("wánr"); // true, 儿化 is a suffix, not a syllable of its own
376
375
  ```
377
376
 
378
377
  Initials and finals are the _underlying_ forms rather than the spelling, so 就 is
@@ -390,7 +389,7 @@ Input takes either notation, the `v` and `u:` conventions for ü, and raised ton
390
389
  digits. Output is standard diacritics unless asked otherwise.
391
390
 
392
391
  Parsing answers whether a spelling is _well formed_, not whether Mandarin uses
393
- it — `shong` parses and is not a real syllable. The attested inventory is
392
+ it: `shong` parses and is not a real syllable. The attested inventory is
394
393
  separate:
395
394
 
396
395
  ```ts
@@ -410,7 +409,7 @@ splitSyllables("nǐhǎo"); // ["nǐ", "hǎo"]
410
409
  splitSyllables("Xī'ān"); // ["Xī", "ān"]
411
410
  splitSyllables("yinhang"); // ["yin", "hang"]
412
411
  splitSyllables("guórén"); // ["guó", "rén"], not ["guór", "én"]
413
- splitSyllables("hǎiōu"); // ["hǎi", "ōu"] — missing apostrophe, read anyway
412
+ splitSyllables("hǎiōu"); // ["hǎi", "ōu"], missing apostrophe, read anyway
414
413
  readWord("yínháng"); // the same, parsed into Syllable objects
415
414
  ```
416
415
 
@@ -436,20 +435,21 @@ written at all.
436
435
 
437
436
  ## Numbers
438
437
 
439
- Reading a number needs no dictionary — arithmetic and about twenty readings —
440
- so this works with nothing loaded.
438
+ Reading a number needs no dictionary, just arithmetic and about twenty
439
+ readings, so this works with nothing loaded.
441
440
 
442
441
  ```ts
443
442
  import { numeralHanzi, percentHanzi, readNumeral } from "@kensio/pinyinjs";
444
443
 
445
444
  numeralHanzi(12345); // "一万两千三百四十五"
446
- numeralHanzi(1005); // "一千零五" — a skipped place is spoken
447
- numeralHanzi(2000); // "两千" — a leading lone 2 before a big unit
448
- percentHanzi(95); // "百分之九十五" — the order reverses
445
+ numeralHanzi(1005); // "一千零五", a skipped place is spoken
446
+ numeralHanzi(2000); // "两千", a leading lone 2 before a big unit
447
+ numeralHanzi(2, { counts: true }); // "两", as in 两个西瓜, never 二个
448
+ percentHanzi(95); // "百分之九十五", the order reverses
449
449
  ```
450
450
 
451
- The same digits are read two ways and nothing in the number says which — 2026年
452
- is spelled out and 2026个 is counted — so the style is the caller's:
451
+ The same digits are read two ways and nothing in the number says which, since
452
+ 2026年 is spelled out and 2026个 is counted, so the style is the caller's:
453
453
 
454
454
  ```ts
455
455
  numeralHanzi(2026); // "两千零二十六"
@@ -484,7 +484,7 @@ writeIpa(jiu); // "tɕiou˥˩"
484
484
  ```
485
485
 
486
486
  Gwoyeu Romatzyh is the odd one, and it needs no tone mark because the tone is
487
- spelled into the syllable — which is why 陝西 is Shaanxi in English and 山西 is
487
+ spelled into the syllable, which is why 陝西 is Shaanxi in English and 山西 is
488
488
  Shanxi:
489
489
 
490
490
  ```ts
@@ -496,7 +496,7 @@ Reading Wade-Giles back gives an **array**, because real text drops the
496
496
  apostrophes and diacritics that carry the distinctions:
497
497
 
498
498
  ```ts
499
- readWadeGilesLoosely("chi¹"); // [jī, qī] — chi is jī, ch'i is qī
499
+ readWadeGilesLoosely("chi¹"); // [jī, qī]: chi is jī, ch'i is qī
500
500
  readWadeGilesLoosely("chu¹"); // [zhū, chū, jū, qū]
501
501
  ```
502
502
 
@@ -514,7 +514,7 @@ array, so it can be switched off and works across word boundaries.
514
514
  import { applySandhi, readWord } from "@kensio/pinyinjs";
515
515
 
516
516
  const buShi = readWord("bùshì") ?? [];
517
- applySandhi(buShi); // bú shì — 不 flattens before a fourth tone
517
+ applySandhi(buShi); // bú shì, 不 flattens before a fourth tone
518
518
  applySandhi(buShi, { yiBu: false }); // unchanged
519
519
 
520
520
  const niHao = readWord("nǐhǎo") ?? [];