@kensio/pinyinjs 0.1.0-beta.0 → 1.0.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/CHANGELOG.md +87 -0
- package/NOTICE +7 -0
- package/README.md +144 -19
- package/data/full.entries +13400 -13400
- package/data/manifest.json +4 -4
- package/data/standard.entries +2492 -2492
- package/dist/cli/arguments.d.ts +67 -0
- package/dist/cli/arguments.d.ts.map +1 -1
- package/dist/cli/arguments.js +79 -0
- package/dist/cli/arguments.js.map +1 -1
- package/dist/cli/colour.d.ts +77 -0
- package/dist/cli/colour.d.ts.map +1 -0
- package/dist/cli/colour.js +117 -0
- package/dist/cli/colour.js.map +1 -0
- package/dist/cli/commands.d.ts +49 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +404 -42
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/environment.d.ts.map +1 -1
- package/dist/cli/environment.js +20 -0
- package/dist/cli/environment.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +43 -16
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/run.d.ts +11 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -2
- package/dist/cli/run.js.map +1 -1
- package/dist/decode/convert.d.ts +20 -0
- package/dist/decode/convert.d.ts.map +1 -1
- package/dist/decode/convert.js +170 -12
- 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 +17 -4
- package/dist/decode/decode.js.map +1 -1
- package/dist/decode/reading-rules.d.ts +56 -0
- package/dist/decode/reading-rules.d.ts.map +1 -0
- package/dist/decode/reading-rules.js +107 -0
- package/dist/decode/reading-rules.js.map +1 -0
- package/dist/decode/rules.d.ts +66 -0
- package/dist/decode/rules.d.ts.map +1 -0
- package/dist/decode/rules.js +138 -0
- package/dist/decode/rules.js.map +1 -0
- package/dist/decode/sandhi.d.ts +1 -1
- package/dist/decode/sandhi.d.ts.map +1 -1
- package/dist/decode/sandhi.js +60 -1
- package/dist/decode/sandhi.js.map +1 -1
- package/dist/decode/word.d.ts +18 -0
- package/dist/decode/word.d.ts.map +1 -1
- package/dist/dictionary/artifact.d.ts.map +1 -1
- package/dist/dictionary/artifact.js +28 -1
- package/dist/dictionary/artifact.js.map +1 -1
- package/dist/dictionary/dictionary.d.ts +9 -0
- package/dist/dictionary/dictionary.d.ts.map +1 -1
- package/dist/dictionary/dictionary.js +7 -0
- package/dist/dictionary/dictionary.js.map +1 -1
- package/dist/dictionary/entry.d.ts +12 -0
- package/dist/dictionary/entry.d.ts.map +1 -1
- package/dist/dictionary/entry.js.map +1 -1
- package/dist/dictionary/merge.d.ts +3 -1
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +19 -1
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/format/transcription.d.ts +52 -0
- package/dist/format/transcription.d.ts.map +1 -0
- package/dist/format/transcription.js +88 -0
- package/dist/format/transcription.js.map +1 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/numerals/cardinal.d.ts +39 -0
- package/dist/numerals/cardinal.d.ts.map +1 -0
- package/dist/numerals/cardinal.js +111 -0
- package/dist/numerals/cardinal.js.map +1 -0
- package/dist/numerals/characters.d.ts +31 -0
- package/dist/numerals/characters.d.ts.map +1 -0
- package/dist/numerals/characters.js +80 -0
- package/dist/numerals/characters.js.map +1 -0
- package/dist/numerals/numerals.d.ts +76 -0
- package/dist/numerals/numerals.d.ts.map +1 -0
- package/dist/numerals/numerals.js +119 -0
- package/dist/numerals/numerals.js.map +1 -0
- package/dist/numerals/text.d.ts +52 -0
- package/dist/numerals/text.d.ts.map +1 -0
- package/dist/numerals/text.js +248 -0
- package/dist/numerals/text.js.map +1 -0
- package/dist/orthography/grouping.d.ts +56 -11
- package/dist/orthography/grouping.d.ts.map +1 -1
- package/dist/orthography/grouping.js +109 -35
- package/dist/orthography/grouping.js.map +1 -1
- package/dist/orthography/idiom-list.d.ts +56 -0
- package/dist/orthography/idiom-list.d.ts.map +1 -0
- package/dist/orthography/idiom-list.js +296 -0
- package/dist/orthography/idiom-list.js.map +1 -0
- package/dist/orthography/idioms.d.ts +18 -0
- package/dist/orthography/idioms.d.ts.map +1 -0
- package/dist/orthography/idioms.js +22 -0
- package/dist/orthography/idioms.js.map +1 -0
- package/dist/orthography/reduplication.d.ts +52 -0
- package/dist/orthography/reduplication.d.ts.map +1 -0
- package/dist/orthography/reduplication.js +99 -0
- package/dist/orthography/reduplication.js.map +1 -0
- package/dist/orthography/rule.d.ts +50 -0
- package/dist/orthography/rule.d.ts.map +1 -0
- package/dist/orthography/rule.js +101 -0
- package/dist/orthography/rule.js.map +1 -0
- package/dist/sources/cedict.d.ts +23 -0
- package/dist/sources/cedict.d.ts.map +1 -1
- package/dist/sources/cedict.js +28 -0
- package/dist/sources/cedict.js.map +1 -1
- package/dist/syllable/syllable.d.ts +1 -1
- package/dist/syllable/syllable.d.ts.map +1 -1
- package/dist/syllable/syllable.js +2 -37
- package/dist/syllable/syllable.js.map +1 -1
- package/dist/tone/tone-mark.d.ts +23 -0
- package/dist/tone/tone-mark.d.ts.map +1 -1
- package/dist/tone/tone-mark.js +49 -0
- package/dist/tone/tone-mark.js.map +1 -1
- package/dist/transcription/bopomofo.d.ts +46 -0
- package/dist/transcription/bopomofo.d.ts.map +1 -0
- package/dist/transcription/bopomofo.js +371 -0
- package/dist/transcription/bopomofo.js.map +1 -0
- package/dist/transcription/gwoyeu.d.ts +32 -0
- package/dist/transcription/gwoyeu.d.ts.map +1 -0
- package/dist/transcription/gwoyeu.js +491 -0
- package/dist/transcription/gwoyeu.js.map +1 -0
- package/dist/transcription/ipa.d.ts +40 -0
- package/dist/transcription/ipa.d.ts.map +1 -0
- package/dist/transcription/ipa.js +221 -0
- package/dist/transcription/ipa.js.map +1 -0
- package/dist/transcription/spelling-index.d.ts +23 -0
- package/dist/transcription/spelling-index.d.ts.map +1 -0
- package/dist/transcription/spelling-index.js +61 -0
- package/dist/transcription/spelling-index.js.map +1 -0
- package/dist/transcription/wade-giles.d.ts +108 -0
- package/dist/transcription/wade-giles.d.ts.map +1 -0
- package/dist/transcription/wade-giles.js +656 -0
- package/dist/transcription/wade-giles.js.map +1 -0
- package/dist/transcription/yale.d.ts +43 -0
- package/dist/transcription/yale.d.ts.map +1 -0
- package/dist/transcription/yale.js +242 -0
- package/dist/transcription/yale.js.map +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bopomofo (注音符號), in both directions.
|
|
3
|
+
*
|
|
4
|
+
* This is the easy half of romanisation interchange, and the reason is
|
|
5
|
+
* [phonology.ts](../syllable/phonology.ts): a parsed syllable already holds the
|
|
6
|
+
* underlying initial and final rather than the spelling, and bopomofo writes
|
|
7
|
+
* exactly those. 就 is
|
|
8
|
+
* `j` + `iou` and ㄐㄧㄡ; 军 is `j` + `ün` and ㄐㄩㄣ; 中 is `zh` + `ong` and
|
|
9
|
+
* ㄓㄨㄥ. Nothing here undoes a pinyin spelling rule, because `readSyllable`
|
|
10
|
+
* never applied one.
|
|
11
|
+
*
|
|
12
|
+
* So the mapping is compositional — an initial symbol, a medial symbol and a
|
|
13
|
+
* rhyme symbol — and it is a bijection over the whole syllable inventory. The
|
|
14
|
+
* three places it is not quite mechanical are recorded on the tables below.
|
|
15
|
+
*/
|
|
16
|
+
import { toCharacters } from "../script/characters.js";
|
|
17
|
+
import { NEUTRAL_TONE } from "../tone/tone.js";
|
|
18
|
+
/**
|
|
19
|
+
* The symbol each initial is written with.
|
|
20
|
+
*
|
|
21
|
+
* A syllable with no initial has no entry and writes nothing, which is what the
|
|
22
|
+
* empty string stands for throughout this file.
|
|
23
|
+
*/
|
|
24
|
+
const INITIAL_SYMBOLS = new Map([
|
|
25
|
+
["b", "ㄅ"],
|
|
26
|
+
["p", "ㄆ"],
|
|
27
|
+
["m", "ㄇ"],
|
|
28
|
+
["f", "ㄈ"],
|
|
29
|
+
["d", "ㄉ"],
|
|
30
|
+
["t", "ㄊ"],
|
|
31
|
+
["n", "ㄋ"],
|
|
32
|
+
["l", "ㄌ"],
|
|
33
|
+
["g", "ㄍ"],
|
|
34
|
+
["k", "ㄎ"],
|
|
35
|
+
["h", "ㄏ"],
|
|
36
|
+
["j", "ㄐ"],
|
|
37
|
+
["q", "ㄑ"],
|
|
38
|
+
["x", "ㄒ"],
|
|
39
|
+
["zh", "ㄓ"],
|
|
40
|
+
["ch", "ㄔ"],
|
|
41
|
+
["sh", "ㄕ"],
|
|
42
|
+
["r", "ㄖ"],
|
|
43
|
+
["z", "ㄗ"],
|
|
44
|
+
["c", "ㄘ"],
|
|
45
|
+
["s", "ㄙ"],
|
|
46
|
+
]);
|
|
47
|
+
/**
|
|
48
|
+
* The symbol each medial is written with.
|
|
49
|
+
*/
|
|
50
|
+
const MEDIAL_SYMBOLS = new Map([
|
|
51
|
+
["i", "ㄧ"],
|
|
52
|
+
["u", "ㄨ"],
|
|
53
|
+
["ü", "ㄩ"],
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* The symbol each rhyme is written with.
|
|
57
|
+
*
|
|
58
|
+
* ㄦ is here as a rhyme of its own and also serves as the 儿化 suffix, which is
|
|
59
|
+
* what bopomofo does with it: 歌儿 gēr is ㄍㄜㄦ.
|
|
60
|
+
*
|
|
61
|
+
* The three syllabic nasals at the end are the marginal case. ㄇ and ㄋ are
|
|
62
|
+
* initial letters doing rhyme duty, as bopomofo writes 呣 and 嗯; ㄫ is the
|
|
63
|
+
* obsolete letter for a syllabic ng, used here rather than ㄥ so that 嗯 ǹg and
|
|
64
|
+
* the rare 鞥 ēng do not come out identical.
|
|
65
|
+
*/
|
|
66
|
+
const RHYME_SYMBOLS = new Map([
|
|
67
|
+
["a", "ㄚ"],
|
|
68
|
+
["o", "ㄛ"],
|
|
69
|
+
["e", "ㄜ"],
|
|
70
|
+
["ê", "ㄝ"],
|
|
71
|
+
["ai", "ㄞ"],
|
|
72
|
+
["ei", "ㄟ"],
|
|
73
|
+
["ao", "ㄠ"],
|
|
74
|
+
["ou", "ㄡ"],
|
|
75
|
+
["an", "ㄢ"],
|
|
76
|
+
["en", "ㄣ"],
|
|
77
|
+
["ang", "ㄤ"],
|
|
78
|
+
["eng", "ㄥ"],
|
|
79
|
+
["er", "ㄦ"],
|
|
80
|
+
["m", "ㄇ"],
|
|
81
|
+
["n", "ㄋ"],
|
|
82
|
+
["ng", "ㄫ"],
|
|
83
|
+
]);
|
|
84
|
+
/**
|
|
85
|
+
* How each final divides into a medial and a rhyme.
|
|
86
|
+
*
|
|
87
|
+
* Written out rather than split off the front of the spelling, because the
|
|
88
|
+
* division is phonological and the spelling only mostly follows it: `in` is
|
|
89
|
+
* ㄧㄣ, an i medial over the ㄣ rhyme rather than over an n of its own, and
|
|
90
|
+
* `iong` is ㄩㄥ — a ü medial despite the i in the spelling, which is why
|
|
91
|
+
* 兄 xiōng and 军 jūn share a medial.
|
|
92
|
+
*/
|
|
93
|
+
const FINAL_PARTS = {
|
|
94
|
+
a: ["", "a"],
|
|
95
|
+
o: ["", "o"],
|
|
96
|
+
e: ["", "e"],
|
|
97
|
+
ê: ["", "ê"],
|
|
98
|
+
er: ["", "er"],
|
|
99
|
+
ai: ["", "ai"],
|
|
100
|
+
ei: ["", "ei"],
|
|
101
|
+
ao: ["", "ao"],
|
|
102
|
+
ou: ["", "ou"],
|
|
103
|
+
an: ["", "an"],
|
|
104
|
+
en: ["", "en"],
|
|
105
|
+
ang: ["", "ang"],
|
|
106
|
+
eng: ["", "eng"],
|
|
107
|
+
ong: ["u", "eng"],
|
|
108
|
+
i: ["i", ""],
|
|
109
|
+
ia: ["i", "a"],
|
|
110
|
+
io: ["i", "o"],
|
|
111
|
+
ie: ["i", "ê"],
|
|
112
|
+
iao: ["i", "ao"],
|
|
113
|
+
iou: ["i", "ou"],
|
|
114
|
+
ian: ["i", "an"],
|
|
115
|
+
in: ["i", "en"],
|
|
116
|
+
iang: ["i", "ang"],
|
|
117
|
+
ing: ["i", "eng"],
|
|
118
|
+
iong: ["ü", "eng"],
|
|
119
|
+
u: ["u", ""],
|
|
120
|
+
ua: ["u", "a"],
|
|
121
|
+
uo: ["u", "o"],
|
|
122
|
+
uai: ["u", "ai"],
|
|
123
|
+
uei: ["u", "ei"],
|
|
124
|
+
uan: ["u", "an"],
|
|
125
|
+
uen: ["u", "en"],
|
|
126
|
+
uang: ["u", "ang"],
|
|
127
|
+
ueng: ["u", "eng"],
|
|
128
|
+
ü: ["ü", ""],
|
|
129
|
+
üe: ["ü", "ê"],
|
|
130
|
+
üan: ["ü", "an"],
|
|
131
|
+
ün: ["ü", "en"],
|
|
132
|
+
m: ["", "m"],
|
|
133
|
+
n: ["", "n"],
|
|
134
|
+
ng: ["", "ng"],
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* The initials whose syllable with an i final is written as the initial alone:
|
|
138
|
+
* 知 is ㄓ, not ㄓㄧ.
|
|
139
|
+
*
|
|
140
|
+
* The i of zhi, chi, shi, ri, zi, ci and si is not the i of ji at all — it is
|
|
141
|
+
* the syllabic continuation of the initial (空韻), and bopomofo simply does not
|
|
142
|
+
* write it. This is the one place the correspondence is not one symbol per
|
|
143
|
+
* part.
|
|
144
|
+
*/
|
|
145
|
+
const EMPTY_RHYME_INITIALS = new Set([
|
|
146
|
+
"zh",
|
|
147
|
+
"ch",
|
|
148
|
+
"sh",
|
|
149
|
+
"r",
|
|
150
|
+
"z",
|
|
151
|
+
"c",
|
|
152
|
+
"s",
|
|
153
|
+
]);
|
|
154
|
+
/**
|
|
155
|
+
* The mark each tone takes.
|
|
156
|
+
*
|
|
157
|
+
* The neutral tone's dot goes *before* the syllable and the other four go
|
|
158
|
+
* after, which is where bopomofo puts them.
|
|
159
|
+
*/
|
|
160
|
+
const TONE_MARKS = new Map([
|
|
161
|
+
[1, "ˉ"],
|
|
162
|
+
[2, "ˊ"],
|
|
163
|
+
[3, "ˇ"],
|
|
164
|
+
[4, "ˋ"],
|
|
165
|
+
[NEUTRAL_TONE, "˙"],
|
|
166
|
+
]);
|
|
167
|
+
/**
|
|
168
|
+
* The tone each mark stands for, including the shapes a keyboard produces.
|
|
169
|
+
*
|
|
170
|
+
* Tolerant input and standard output, as the rest of the package has: `´` and
|
|
171
|
+
* `` ` `` are the ASCII neighbours of ˊ and ˋ, and are what text that was typed
|
|
172
|
+
* rather than composed tends to carry.
|
|
173
|
+
*/
|
|
174
|
+
const TONES_BY_MARK = new Map([
|
|
175
|
+
["ˉ", 1],
|
|
176
|
+
["¯", 1],
|
|
177
|
+
["ˊ", 2],
|
|
178
|
+
["´", 2],
|
|
179
|
+
["ˇ", 3],
|
|
180
|
+
["ˋ", 4],
|
|
181
|
+
["`", 4],
|
|
182
|
+
["˙", NEUTRAL_TONE],
|
|
183
|
+
["·", NEUTRAL_TONE],
|
|
184
|
+
]);
|
|
185
|
+
/**
|
|
186
|
+
* Write a syllable in bopomofo: 就 jiù becomes ㄐㄧㄡˋ.
|
|
187
|
+
*
|
|
188
|
+
* Total over well-formed syllables — every initial and every final has a
|
|
189
|
+
* symbol — so anything the syllable parser accepts can be written, including
|
|
190
|
+
* the syllables no dictionary uses.
|
|
191
|
+
*/
|
|
192
|
+
export function writeBopomofo(syllable, options = {}) {
|
|
193
|
+
const { initial, final, tone } = syllable;
|
|
194
|
+
const [medial, rhyme] = FINAL_PARTS[final];
|
|
195
|
+
const isEmptyRhyme = final === "i" && EMPTY_RHYME_INITIALS.has(initial);
|
|
196
|
+
const written = [
|
|
197
|
+
INITIAL_SYMBOLS.get(initial) ?? "",
|
|
198
|
+
isEmptyRhyme ? "" : (MEDIAL_SYMBOLS.get(medial) ?? ""),
|
|
199
|
+
isEmptyRhyme ? "" : (RHYME_SYMBOLS.get(rhyme) ?? ""),
|
|
200
|
+
syllable.erhua === true ? "ㄦ" : "",
|
|
201
|
+
].join("");
|
|
202
|
+
const mark = tone === undefined ? undefined : TONE_MARKS.get(tone);
|
|
203
|
+
if (mark === undefined || (tone === 1 && options.firstTone !== "mark")) {
|
|
204
|
+
return written;
|
|
205
|
+
}
|
|
206
|
+
return tone === NEUTRAL_TONE ? `${mark}${written}` : `${written}${mark}`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Write a word in bopomofo, one syllable after another.
|
|
210
|
+
*
|
|
211
|
+
* Separated by spaces, as 教育部's dictionaries write them. A syllable boundary
|
|
212
|
+
* is findable without the space — an initial symbol can only start one — but a
|
|
213
|
+
* long unbroken run of symbols is hard to read, and the space costs nothing.
|
|
214
|
+
*/
|
|
215
|
+
export function writeBopomofoWord(syllables, options = {}) {
|
|
216
|
+
return syllables
|
|
217
|
+
.map((syllable) => writeBopomofo(syllable, options))
|
|
218
|
+
.join(" ");
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The final each medial and rhyme pair spells, keyed as `medial|rhyme`.
|
|
222
|
+
*/
|
|
223
|
+
const FINALS_BY_PARTS = new Map(Object.entries(FINAL_PARTS).map(([final, [medial, rhyme]]) => [
|
|
224
|
+
`${medial}|${rhyme}`,
|
|
225
|
+
final,
|
|
226
|
+
]));
|
|
227
|
+
/**
|
|
228
|
+
* The initial each symbol stands for.
|
|
229
|
+
*/
|
|
230
|
+
const INITIALS_BY_SYMBOL = new Map([...INITIAL_SYMBOLS].map(([initial, symbol]) => [symbol, initial]));
|
|
231
|
+
/**
|
|
232
|
+
* The medial each symbol stands for.
|
|
233
|
+
*/
|
|
234
|
+
const MEDIALS_BY_SYMBOL = new Map([...MEDIAL_SYMBOLS].map(([medial, symbol]) => [symbol, medial]));
|
|
235
|
+
/**
|
|
236
|
+
* The rhyme each symbol stands for.
|
|
237
|
+
*/
|
|
238
|
+
const RHYMES_BY_SYMBOL = new Map([...RHYME_SYMBOLS].map(([rhyme, symbol]) => [symbol, rhyme]));
|
|
239
|
+
/**
|
|
240
|
+
* Whether one character is a bopomofo letter or tone mark.
|
|
241
|
+
*/
|
|
242
|
+
function isSymbol(symbol) {
|
|
243
|
+
return (INITIALS_BY_SYMBOL.has(symbol) ||
|
|
244
|
+
MEDIALS_BY_SYMBOL.has(symbol) ||
|
|
245
|
+
RHYMES_BY_SYMBOL.has(symbol) ||
|
|
246
|
+
TONES_BY_MARK.has(symbol));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Whether a string is written in bopomofo at all.
|
|
250
|
+
*
|
|
251
|
+
* This is the one thing bopomofo makes easy that Wade-Giles cannot: it has a
|
|
252
|
+
* script of its own, so it is never mistaken for pinyin and a caller never has
|
|
253
|
+
* to be told which system its input is in.
|
|
254
|
+
*/
|
|
255
|
+
export function isBopomofo(text) {
|
|
256
|
+
const trimmed = text.trim();
|
|
257
|
+
return (trimmed !== "" && toCharacters(trimmed).every((symbol) => isSymbol(symbol)));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Take the tone mark off, wherever it was written.
|
|
261
|
+
*
|
|
262
|
+
* The neutral dot belongs at the front and the other four at the back, but text
|
|
263
|
+
* in the wild puts them either side, so both are read. A mark at each end is
|
|
264
|
+
* rejected rather than resolved, which is the same call `readSyllable` makes
|
|
265
|
+
* about `běi3`.
|
|
266
|
+
*/
|
|
267
|
+
function splitTone(text) {
|
|
268
|
+
const leading = TONES_BY_MARK.get(text.slice(0, 1));
|
|
269
|
+
if (leading !== undefined) {
|
|
270
|
+
const rest = text.slice(1);
|
|
271
|
+
return TONES_BY_MARK.has(rest.slice(-1)) ? undefined : [rest, leading];
|
|
272
|
+
}
|
|
273
|
+
const trailing = TONES_BY_MARK.get(text.slice(-1));
|
|
274
|
+
return trailing === undefined
|
|
275
|
+
? [text, undefined]
|
|
276
|
+
: [text.slice(0, -1), trailing];
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Read the symbols of one syllable, in the order bopomofo writes them.
|
|
280
|
+
*
|
|
281
|
+
* `hasInitial` is what recovers the syllabic nasals on a second pass: ㄇ is an
|
|
282
|
+
* initial letter, so 呣 m̄ parses as an m initial with nothing after it and has
|
|
283
|
+
* to be retried as a rhyme standing alone. `readParts` in
|
|
284
|
+
* [syllable.ts](../syllable/syllable.ts) retries n and ng the same way, for the
|
|
285
|
+
* same reason.
|
|
286
|
+
*/
|
|
287
|
+
function parseSymbols(text, hasInitial) {
|
|
288
|
+
const symbols = toCharacters(text);
|
|
289
|
+
let at = 0;
|
|
290
|
+
const initial = hasInitial
|
|
291
|
+
? INITIALS_BY_SYMBOL.get(symbols[at] ?? "")
|
|
292
|
+
: undefined;
|
|
293
|
+
if (initial !== undefined) {
|
|
294
|
+
at += 1;
|
|
295
|
+
}
|
|
296
|
+
const medial = MEDIALS_BY_SYMBOL.get(symbols[at] ?? "");
|
|
297
|
+
if (medial !== undefined) {
|
|
298
|
+
at += 1;
|
|
299
|
+
}
|
|
300
|
+
// ㄦ is the 儿化 suffix everywhere except at the very front of a syllable,
|
|
301
|
+
// where it is the rhyme of 儿 ér itself. That is what separates ㄦ from ㄕㄦ:
|
|
302
|
+
// 事儿 shìr writes no rhyme at all, so the ㄦ can only be the suffix, and
|
|
303
|
+
// 二儿 èr with a suffix is ㄦㄦ.
|
|
304
|
+
const isSuffix = at > 0 && symbols[at] === "ㄦ";
|
|
305
|
+
const rhyme = isSuffix ? undefined : RHYMES_BY_SYMBOL.get(symbols[at] ?? "");
|
|
306
|
+
if (rhyme !== undefined) {
|
|
307
|
+
at += 1;
|
|
308
|
+
}
|
|
309
|
+
const hasErhua = at > 0 && symbols[at] === "ㄦ";
|
|
310
|
+
if (hasErhua) {
|
|
311
|
+
at += 1;
|
|
312
|
+
}
|
|
313
|
+
return at === symbols.length
|
|
314
|
+
? {
|
|
315
|
+
initial: initial ?? "",
|
|
316
|
+
medial: medial ?? "",
|
|
317
|
+
rhyme: rhyme ?? "",
|
|
318
|
+
hasErhua,
|
|
319
|
+
}
|
|
320
|
+
: undefined;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Resolve parsed symbols to an underlying final.
|
|
324
|
+
*
|
|
325
|
+
* ㄨㄥ is the one context-dependent rhyme in the system: with an initial it is
|
|
326
|
+
* `ong` (中 ㄓㄨㄥ) and without one it is `ueng` (翁 ㄨㄥ). Everything else
|
|
327
|
+
* reads the same wherever it stands.
|
|
328
|
+
*/
|
|
329
|
+
function finalOf(parsed) {
|
|
330
|
+
const { initial, medial, rhyme } = parsed;
|
|
331
|
+
if (medial === "" && rhyme === "") {
|
|
332
|
+
return EMPTY_RHYME_INITIALS.has(initial) ? "i" : undefined;
|
|
333
|
+
}
|
|
334
|
+
if (medial === "u" && rhyme === "eng") {
|
|
335
|
+
return initial === "" ? "ueng" : "ong";
|
|
336
|
+
}
|
|
337
|
+
return FINALS_BY_PARTS.get(`${medial}|${rhyme}`);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Read one parse of a bopomofo string, or nothing if it does not resolve.
|
|
341
|
+
*/
|
|
342
|
+
function readParsed(text, hasInitial) {
|
|
343
|
+
const parsed = parseSymbols(text, hasInitial);
|
|
344
|
+
const final = parsed === undefined ? undefined : finalOf(parsed);
|
|
345
|
+
return parsed === undefined || final === undefined
|
|
346
|
+
? undefined
|
|
347
|
+
: {
|
|
348
|
+
initial: parsed.initial,
|
|
349
|
+
final,
|
|
350
|
+
tone: undefined,
|
|
351
|
+
...(parsed.hasErhua && { erhua: true }),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Read a bopomofo syllable: ㄐㄧㄡˋ becomes 就 jiù.
|
|
356
|
+
*
|
|
357
|
+
* An unmarked syllable is a first tone rather than a toneless one, because
|
|
358
|
+
* bopomofo marks the first tone by leaving it off — the omission is itself
|
|
359
|
+
* written, in a way that a bare `bei` typed as pinyin is not. Undefined for
|
|
360
|
+
* anything that is not exactly one well-formed syllable.
|
|
361
|
+
*/
|
|
362
|
+
export function readBopomofo(text) {
|
|
363
|
+
const split = splitTone(text.trim().normalize("NFC"));
|
|
364
|
+
if (split === undefined || split[0] === "") {
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
const [written, tone] = split;
|
|
368
|
+
const read = readParsed(written, true) ?? readParsed(written, false);
|
|
369
|
+
return read === undefined ? undefined : { ...read, tone: tone ?? 1 };
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=bopomofo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bopomofo.js","sourceRoot":"","sources":["../../src/transcription/bopomofo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAa,MAAM,iBAAiB,CAAC;AA8B1D;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAkB;IAC/C,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GA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AAC,CAAC;IACtD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QAC3C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACrE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Syllable } from "../syllable/syllable.js";
|
|
2
|
+
/**
|
|
3
|
+
* Write a syllable in Gwoyeu Romatzyh: 就 jiù becomes `jiow`.
|
|
4
|
+
*
|
|
5
|
+
* An unwritten tone is written as the basic form, because GR has no other
|
|
6
|
+
* form to write — which means it reads back as a first tone, exactly as
|
|
7
|
+
* bopomofo's unmarked syllable does. The neutral tone takes the dot in front,
|
|
8
|
+
* and the syllable behind it is the basic form rather than the etymological
|
|
9
|
+
* spelling GR would use, for the reason the module comment gives.
|
|
10
|
+
*/
|
|
11
|
+
export declare function writeGwoyeu(syllable: Syllable): string;
|
|
12
|
+
/**
|
|
13
|
+
* Write a word in Gwoyeu Romatzyh, one syllable after another.
|
|
14
|
+
*
|
|
15
|
+
* Solid, as GR writes a word: 北京 is `Beeijing`, which is the convention
|
|
16
|
+
* pinyin inherited. GR uses an apostrophe where the join is ambiguous — its own
|
|
17
|
+
* name for pinyin, `Pin'in`, is the standard example — and that is not written
|
|
18
|
+
* here, for the same reason `readGwoyeu` takes one syllable at a time: knowing
|
|
19
|
+
* where the boundary is ambiguous means being able to split the word, and
|
|
20
|
+
* nothing here splits a GR word.
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeGwoyeuWord(syllables: readonly Syllable[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Read a Gwoyeu Romatzyh syllable: `jiow` becomes 就 jiù.
|
|
25
|
+
*
|
|
26
|
+
* A leading dot is the neutral tone, and it wins over whatever tone the
|
|
27
|
+
* spelling behind it carries — `.yeou` is a neutral 友, which is what GR means
|
|
28
|
+
* by it. Returns every syllable the spelling stands for, and nothing at all for
|
|
29
|
+
* a spelling no syllable of the inventory writes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readGwoyeu(text: string): readonly Syllable[];
|
|
32
|
+
//# sourceMappingURL=gwoyeu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gwoyeu.d.ts","sourceRoot":"","sources":["../../src/transcription/gwoyeu.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAkZtE;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAStD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,CAEtE;AAqDD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAS5D"}
|