@hakkacl/hakka 0.1.0 → 0.1.1
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 +25 -25
- package/data/dialects.json +1 -1
- package/package.json +2 -2
- package/src/dialects.js +1 -1
- package/src/phon/converter.js +15 -15
- package/src/phon/parser.js +23 -23
- package/src/phon/schemes.js +26 -30
- package/src/phon/syllable.js +11 -11
- package/src/phon/validate.js +6 -6
- package/src/sandhi.js +24 -28
- package/types/index.d.ts +14 -22
package/src/sandhi.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
baseOf,
|
|
17
17
|
createSyllable,
|
|
18
18
|
finalOf,
|
|
19
|
-
|
|
19
|
+
hppOf,
|
|
20
20
|
isSyllabicConsonant,
|
|
21
21
|
syllableFields,
|
|
22
22
|
} from "./phon/syllable.js";
|
|
@@ -84,13 +84,9 @@ function createResult(syllables, changes, dialect, profileName) {
|
|
|
84
84
|
profile: profileName,
|
|
85
85
|
};
|
|
86
86
|
Object.defineProperties(result, {
|
|
87
|
-
|
|
87
|
+
hpp: {
|
|
88
88
|
enumerable: false,
|
|
89
|
-
get: () => result.syllables.map((syllable) =>
|
|
90
|
-
},
|
|
91
|
-
hpsExt: {
|
|
92
|
-
enumerable: false,
|
|
93
|
-
get: () => result.syllables.map((syllable) => hpsExtOf(syllable)).join(" "),
|
|
89
|
+
get: () => result.syllables.map((syllable) => hppOf(syllable)).join(" "),
|
|
94
90
|
},
|
|
95
91
|
});
|
|
96
92
|
return Object.freeze(result);
|
|
@@ -113,8 +109,8 @@ function applyMeixian(syllables, chars, profileName) {
|
|
|
113
109
|
createChange(
|
|
114
110
|
i,
|
|
115
111
|
i < chars.length ? chars[i] : "",
|
|
116
|
-
`${
|
|
117
|
-
`${
|
|
112
|
+
`${hppOf(cur)}[${cur.tone_value || "44"}]`,
|
|
113
|
+
`${hppOf(updated)}[45]`,
|
|
118
114
|
"meixian:yinping_44_to_45_before_low_onset",
|
|
119
115
|
),
|
|
120
116
|
);
|
|
@@ -130,8 +126,8 @@ function applyMeixian(syllables, chars, profileName) {
|
|
|
130
126
|
createChange(
|
|
131
127
|
i,
|
|
132
128
|
i < chars.length ? chars[i] : "",
|
|
133
|
-
`${
|
|
134
|
-
`${
|
|
129
|
+
`${hppOf(cur)}[${cur.tone_value || "52"}]`,
|
|
130
|
+
`${hppOf(updated)}[55]`,
|
|
135
131
|
"meixian:qusheng_52_to_55_before_high_onset",
|
|
136
132
|
),
|
|
137
133
|
);
|
|
@@ -201,7 +197,7 @@ function applyWuhua(syllables, chars, _profileName) {
|
|
|
201
197
|
|
|
202
198
|
if (applied.length > 0) {
|
|
203
199
|
out[i] = updated;
|
|
204
|
-
changes.push(createChange(i, char,
|
|
200
|
+
changes.push(createChange(i, char, hppOf(cur), hppOf(updated), applied.join("+")));
|
|
205
201
|
}
|
|
206
202
|
}
|
|
207
203
|
return [out, changes];
|
|
@@ -223,8 +219,8 @@ function applyChangting(syllables, chars, profileName) {
|
|
|
223
219
|
createChange(
|
|
224
220
|
i,
|
|
225
221
|
i < chars.length ? chars[i] : "",
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
hppOf(cur),
|
|
223
|
+
hppOf(updated),
|
|
228
224
|
"changting:shang_3_to_2_before_shang",
|
|
229
225
|
),
|
|
230
226
|
);
|
|
@@ -236,8 +232,8 @@ function applyChangting(syllables, chars, profileName) {
|
|
|
236
232
|
createChange(
|
|
237
233
|
i,
|
|
238
234
|
i < chars.length ? chars[i] : "",
|
|
239
|
-
`${
|
|
240
|
-
`${
|
|
235
|
+
`${hppOf(cur)}[${cur.tone_value}]`,
|
|
236
|
+
`${hppOf(updated)}[11]`,
|
|
241
237
|
"changting:ping_to_11_before_shang",
|
|
242
238
|
),
|
|
243
239
|
);
|
|
@@ -248,8 +244,8 @@ function applyChangting(syllables, chars, profileName) {
|
|
|
248
244
|
createChange(
|
|
249
245
|
i,
|
|
250
246
|
i < chars.length ? chars[i] : "",
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
hppOf(cur),
|
|
248
|
+
hppOf(updated),
|
|
253
249
|
"changting:yangqu_6_to_2_before_yinqu",
|
|
254
250
|
),
|
|
255
251
|
);
|
|
@@ -260,8 +256,8 @@ function applyChangting(syllables, chars, profileName) {
|
|
|
260
256
|
createChange(
|
|
261
257
|
i,
|
|
262
258
|
i < chars.length ? chars[i] : "",
|
|
263
|
-
`${
|
|
264
|
-
`${
|
|
259
|
+
`${hppOf(cur)}[${cur.tone_value || "54"}]`,
|
|
260
|
+
`${hppOf(updated)}[55]`,
|
|
265
261
|
"changting:yinqu_54_to_55",
|
|
266
262
|
),
|
|
267
263
|
);
|
|
@@ -285,8 +281,8 @@ function applySixian(syllables, chars, _profileName) {
|
|
|
285
281
|
createChange(
|
|
286
282
|
i,
|
|
287
283
|
i < chars.length ? chars[i] : "",
|
|
288
|
-
|
|
289
|
-
|
|
284
|
+
hppOf(cur),
|
|
285
|
+
hppOf(updated),
|
|
290
286
|
"sixian:yinping_1_to_2_before_1_2_7",
|
|
291
287
|
),
|
|
292
288
|
);
|
|
@@ -308,8 +304,8 @@ function applyHailu(syllables, chars, _profileName) {
|
|
|
308
304
|
createChange(
|
|
309
305
|
i,
|
|
310
306
|
i < chars.length ? chars[i] : "",
|
|
311
|
-
|
|
312
|
-
|
|
307
|
+
hppOf(cur),
|
|
308
|
+
hppOf(updated),
|
|
313
309
|
"hailu:shang_3_to_6_nonfinal",
|
|
314
310
|
),
|
|
315
311
|
);
|
|
@@ -320,8 +316,8 @@ function applyHailu(syllables, chars, _profileName) {
|
|
|
320
316
|
createChange(
|
|
321
317
|
i,
|
|
322
318
|
i < chars.length ? chars[i] : "",
|
|
323
|
-
|
|
324
|
-
|
|
319
|
+
hppOf(cur),
|
|
320
|
+
hppOf(updated),
|
|
325
321
|
"hailu:yangru_8_to_7_nonfinal",
|
|
326
322
|
),
|
|
327
323
|
);
|
|
@@ -350,14 +346,14 @@ function resolveSandhiArguments(dialectOrOptions, extraOptions) {
|
|
|
350
346
|
* @param {object} [options]
|
|
351
347
|
* @param {string | string[]} [options.chars] Aligned Chinese characters.
|
|
352
348
|
* @param {string} [options.profile="standard"] Rule profile.
|
|
353
|
-
* @param {string} [options.scheme="
|
|
349
|
+
* @param {string} [options.scheme="hpp"] Input scheme for a string.
|
|
354
350
|
* @returns {object}
|
|
355
351
|
*/
|
|
356
352
|
export function applySandhi(syllables, dialectOrOptions = DEFAULT_DIALECT, options = {}) {
|
|
357
353
|
const resolved = resolveSandhiArguments(dialectOrOptions, options);
|
|
358
354
|
const dialectName = resolved.dialect ?? DEFAULT_DIALECT;
|
|
359
355
|
const profileName = resolved.profile ?? "standard";
|
|
360
|
-
const scheme = resolved.scheme ?? "
|
|
356
|
+
const scheme = resolved.scheme ?? "hpp";
|
|
361
357
|
|
|
362
358
|
const dialectInfo = getDialect(dialectName);
|
|
363
359
|
const slug = dialectInfo.slug;
|
package/types/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
/** Canonical transcription scheme names. */
|
|
9
9
|
export type CanonicalScheme =
|
|
10
|
-
| "
|
|
11
|
-
| "
|
|
10
|
+
| "hpp"
|
|
11
|
+
| "hpp_diacritic"
|
|
12
12
|
| "ipa"
|
|
13
13
|
| "ipa_value"
|
|
14
14
|
| "ipa_chao"
|
|
@@ -16,16 +16,12 @@ export type CanonicalScheme =
|
|
|
16
16
|
| "hkilang";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* A scheme name or one of the accepted aliases (`
|
|
19
|
+
* A scheme name or one of the accepted aliases (`hpp`, `pinyin`, `sixian`-style
|
|
20
20
|
* dialect names are not schemes; see {@link SchemeAlias}).
|
|
21
21
|
*/
|
|
22
22
|
export type SchemeAlias =
|
|
23
|
-
| "hps-ext"
|
|
24
|
-
| "hps"
|
|
25
23
|
| "hakka_pinyin"
|
|
26
24
|
| "pinyin"
|
|
27
|
-
| "hps-diacritic"
|
|
28
|
-
| "hps_mark"
|
|
29
25
|
| "diacritic"
|
|
30
26
|
| "ipa-value"
|
|
31
27
|
| "ipa_numeric"
|
|
@@ -129,8 +125,8 @@ export interface DialectInfo {
|
|
|
129
125
|
/**
|
|
130
126
|
* Canonical phonological representation of one Hakka syllable.
|
|
131
127
|
*
|
|
132
|
-
* Fields use
|
|
133
|
-
* `
|
|
128
|
+
* Fields use H++ ASCII segments. Computed accessors (`final`, `base`,
|
|
129
|
+
* `hpp`, …) and immutable update methods are non-enumerable.
|
|
134
130
|
*/
|
|
135
131
|
export interface Syllable {
|
|
136
132
|
/** Initial consonant; empty for zero onset, `"'"` for explicit glottal onset. */
|
|
@@ -158,10 +154,8 @@ export interface Syllable {
|
|
|
158
154
|
readonly final: string;
|
|
159
155
|
/** Segmental spelling without tone. */
|
|
160
156
|
readonly base: string;
|
|
161
|
-
/** Canonical
|
|
162
|
-
readonly
|
|
163
|
-
/** Camel-case alias of {@link Syllable.hps_ext}. */
|
|
164
|
-
readonly hpsExt: string;
|
|
157
|
+
/** Canonical H++ spelling including tone class. */
|
|
158
|
+
readonly hpp: string;
|
|
165
159
|
/** True for stop-coda syllables (`-b/-d/-g/-h`). */
|
|
166
160
|
readonly is_checked: boolean;
|
|
167
161
|
readonly isChecked: boolean;
|
|
@@ -199,7 +193,7 @@ export interface SyllableJSON {
|
|
|
199
193
|
tone_value: string;
|
|
200
194
|
reading_mark: string;
|
|
201
195
|
raw: string;
|
|
202
|
-
|
|
196
|
+
hpp: string;
|
|
203
197
|
}
|
|
204
198
|
|
|
205
199
|
/** Options for parsing a syllable or syllable sequence. */
|
|
@@ -267,9 +261,9 @@ export interface SandhiChange {
|
|
|
267
261
|
readonly index: number;
|
|
268
262
|
/** Aligned Chinese character, or empty when unavailable. */
|
|
269
263
|
readonly char: string;
|
|
270
|
-
/**
|
|
264
|
+
/** H++ spelling before the change. */
|
|
271
265
|
readonly before: string;
|
|
272
|
-
/**
|
|
266
|
+
/** H++ spelling after the change. */
|
|
273
267
|
readonly after: string;
|
|
274
268
|
/** Rule identifier (multiple joined with `+`). */
|
|
275
269
|
readonly rule: string;
|
|
@@ -283,10 +277,8 @@ export interface SandhiResult {
|
|
|
283
277
|
readonly dialect: string;
|
|
284
278
|
/** Sandhi profile name actually used. */
|
|
285
279
|
readonly profile: string;
|
|
286
|
-
/** Space-joined
|
|
287
|
-
readonly
|
|
288
|
-
/** Camel-case alias of {@link SandhiResult.hps_ext}. */
|
|
289
|
-
readonly hpsExt: string;
|
|
280
|
+
/** Space-joined H++ transcription of the result. */
|
|
281
|
+
readonly hpp: string;
|
|
290
282
|
}
|
|
291
283
|
|
|
292
284
|
/** Options for {@link applySandhi}. */
|
|
@@ -306,8 +298,8 @@ export type SandhiInput = string | readonly Syllable[];
|
|
|
306
298
|
/** Default dialect slug (`"huiyang"`). */
|
|
307
299
|
export const DEFAULT_DIALECT: "huiyang";
|
|
308
300
|
|
|
309
|
-
/** Default scheme name (`"
|
|
310
|
-
export const DEFAULT_SCHEME: "
|
|
301
|
+
/** Default scheme name (`"hpp"`). */
|
|
302
|
+
export const DEFAULT_SCHEME: "hpp";
|
|
311
303
|
|
|
312
304
|
/** Canonical scheme names in registry order. */
|
|
313
305
|
export const CANONICAL_SCHEMES: readonly CanonicalScheme[];
|