fix #1370 Cmn voice not correctly translated

1. Rewrite cmn_rules. Vowel will be spoken as Mandarin only when it's
with a tone number. Otherwise, it will be regarded as English. This will
make English words translated more correctly.
2. Fix issue of word item in cmn_listx not taking effect.
3. Fix dictionary_skipwords bug. It should be injected when re-structing
method TranslateWord3.
This commit is contained in:
Juho Hiltunen
2022-09-29 07:09:34 +03:00
committed by GitHub
7 changed files with 173 additions and 230 deletions
+30 -28
View File
@@ -1,4 +1,3 @@
_?? @:11 // unrecognized character _?? @:11 // unrecognized character
//numbers //numbers
@@ -26,33 +25,34 @@ _0M1 tS;h'iE55n_| // 1,000
_0M2 w'A51n_| // 10,000 _0M2 w'A51n_| // 10,000
//_0M3 j'i51_| // 100,000,000 //_0M3 j'i51_| // 100,000,000
//Latin letters with Chinese accent // Latin letters with Chinese accent
a ei51 // This will make letter within English sentense translated not correctly. i.e. "ma is a horse". "a" will be translated as ei51.
b pi51 //a ei51
c sei55 //b pi51
d ti51 //c sei55
e ji51 //d ti51
f ai35f //e ji51
g ts.i51 //f ai35f
h ei35ts.h //g ts.i51
i ai51 //h ei35ts.h
j ts.ei51 //i ai51
k khei51 //j ts.ei51
l ai35l //k khei51
m ai35m //l ai35l
n @n55 //m ai35m
o ou55 //n @n55
p phi51 //o ou55
q khiou55 //p phi51
r @r35 //q khiou55
s ai35s //r @r35
t thi51 //s ai35s
u jiou55 //t thi51
v vei55 //u jiou55
w ta35pliou //v vei55
x ai35ks //w ta35pliou
y wuai51 //x ai35ks
z zi51 //y wuai51
//z zi51
//bopomofo letters //bopomofo letters
ㄅ po55 ㄅ po55
@@ -93,6 +93,8 @@ z zi51
ㄨ wu55 ㄨ wu55
ㄩ y55 ㄩ y55
$textmode
// Most frequent pronunciations of the 3799 most common characters (from Unihan database ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip, kHanyuPinlu field with some corrections) // Most frequent pronunciations of the 3799 most common characters (from Unihan database ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip, kHanyuPinlu field with some corrections)
涉 she4 涉 she4
礦 kuang4 礦 kuang4
+131 -196
View File
@@ -11,9 +11,9 @@
ˋ 4 ˋ 4
ā a1 ā a1
á a2 á a2
ă a3
ǎ a3 ǎ a3
à a4 à a4
// TODO: àn is not handled
ō o1 ō o1
ó o2 ó o2
ŏ o3 ŏ o3
@@ -48,6 +48,9 @@
ŝ sh ŝ sh
.L01 j q x y .L01 j q x y
.L02 1 2 3 4 5 // tone number
.L03 a o e i u v ai ei ui ao ou iu ie ve er an en in un vn ang eng ing ong ua ue uo uai uan uang ia iao ian iang
// Note: ngK matches "ng" if not followed by a vowel // Note: ngK matches "ng" if not followed by a vowel
// (D will match on a digit and also if no digit is present. (special for tone // (D will match on a digit and also if no digit is present. (special for tone
@@ -56,211 +59,159 @@ language).
// 儿 兒 erhua // 儿 兒 erhua
.group a .group a
?1 a _^_EN a _^_EN
a A
ai ai
a1i ai55
a2i ai35
a3i ai214
a4i ai51
ao Au
a1o Au55
a2o Au35
a3o Au214
a4o Au51
a (DnK a a (L02 A
ch) a (DngK A ai (L02 ai
ch) a (4ngK a ao (L02 Au
ch) a (ng4K a a (nL02 a
k) a (DngK A a (ngL02 A
_) a (DngK A
y) a iA y) a (L02 iA
y) ao Au y) a (L02 Au
y) a1o Au55 y) a (nL02 iE
y) a2o Au35 y) a (ngL02 iA
y) a3o Au214
y) a4o Au51
y) a (DnK iE
y) a (DngK iA
.group b .group b
?1 b _^_EN b _^_EN
b p b (L03L02 p
@) b (K _^_EN
.group c .group c
?1 c _^_EN c _^_EN
c tsh c (L03L02 tsh
ch (+ ts.h ch (L03L02 ts.h
@) c (K _^_EN
.group d .group d
?1 d _^_EN d _^_EN
d t d (L03L02 t
@) d (K _^_EN
.group e .group e
?1 e _^_EN e _^_EN
e o-
e (L02 o-
d) e @ d) e @
t) e @ t) e @
n) e @ n) e @
l) e @ l) e @
y) e iE y) e iE
ea E
ei ei
e1i ei55
e2i ei35
e3i ei214
e4i ei51
e (Dn @ //en eng ei (L02 ei
e (nL02 @ // en
er (K @r e (ngL02 @ // eng
e1r (K @r55 er (L02 @r
e2r (K @r35
e3r (K @r214
e4r (K @r51
.group f .group f
?1 f _^_EN f _^_EN
f f f (L03L02 f
@) f (K _^_EN
.group g .group g
?1 g _^_EN g _^_EN
g k g (L03L02 k
@) g (K _^_EN
.group h .group h
?1 h _^_EN h _^_EN
h X h (L03L02 X
@) h (K _^_EN
.group i .group i
?1 i _^_EN i _^_EN
i i //i in ing
z) i i[ i (L02 i
c) i i[ i (nL02 i // in
s) i i[ i (ngL02 i // ing
h) i i. //after zh ch sh
r) i i. z) i (L02 i[
ia iA c) i (L02 i[
ia (DnK iE s) i (L02 i[
ia (DngK iA h) i (L02 i. //after zh ch sh
iao jAu r) i (L02 i.
ia1o jAu55 ia (L02 iA
ia2o jAu35 ia (nL02 iE
ia3o jAu214 ia (ngL02 iA
ia4o jAu51
ie iE iao (L02 jAu
io (DngK y ie (L02 iE
q) io (DngK u io (ngL02 y
iu iou q) io (ngL02 u
iu (L02 iou
.group j .group j
?1 j _^_EN j _^_EN
j tS; j (L03L02 tS;
@) j (K _^_EN
.group k .group k
?1 k _^_EN k _^_EN
k kh k (L03L02 kh
@) k (K _^_EN
.group l .group l
?1 l _^_EN l _^_EN
l l l (L03L02 l
@) l (K _^_EN
@) l (v l
.group m .group m
?1 m _^_EN m _^_EN
m m m (L03L02 m
@) m (K _^_EN
.group n .group n
?1 n _^_EN n _^_EN
n n n (L03L02 n
ng (K N // consider (ng+vowel) as (n g+vowel) ?? n (L02 n
ng (L02 N // consider (ng+vowel) as (n g+vowel) ??
_) ng (K N- // syllablic [N] _) ng (K N- // syllablic [N]
.group o .group o
?1 o _^_EN o _^_EN
o o
ou ou o (L02 o
o1u ou55 ou (L02 ou
o2u ou35 ong (L02 ong
o3u ou214
o4u ou51
ong (K ong y) o (L02 io
o1ng (K ong55 y) ou (L02 iou
o2ng (K ong35
o3ng (K ong214
o4ng (K ong51
y) o io
y) ou iou
y) o1u iou55
y) o2u iou35
y) o3u iou214
y) o4u iou51
.group p .group p
?1 p _^_EN p _^_EN
p ph p (L03L02 ph
@) p (K _^_EN
.group q .group q
?1 q _^_EN q _^_EN
q tS;h q (L03L02 tS;h
@) q (K _^_EN
.group r .group r
?1 r _^_EN r _^_EN
r z. r (L03L02 z.
r (K @r11
.group s .group s
?1 s _^_EN s _^_EN
s s s (L03L02 s
sh (+ s. sh (L03L02 s.
@) s (K _^_EN
.group t .group t
?1 t _^_EN t _^_EN
t th t (L03L02 th
@) t (K _^_EN
.group u .group u
?1 u _^_EN u _^_EN
u u
ua wA
ua (DnK ua
g) ua (DnK wa
k) ua (DnK wa
ua (DngK wA
uai uai
ua1i uai55
ua2i uai35
ua3i uai214
ua4i uai51
ue yE //üe
ui uei
sh) ui wei
u (DnK u@
k) u (DnK wu@
_h) u (DnK wu@
t) u (DnK wu@
uo uo
sh) ui rei u (L02 u
sh) u (DnK wo- ua (L02 wA
sh) uo wo ua (nL02 ua
g) ua (nL02 wa
k) ua (nL02 wa
ua (ngL02 wA
uai (L02 uai
ue (L02 yE // üe
ui (L02 uei
sh) ui (L02 wei
u (nL02 u@
k) u (nL02 wu@
_h) u (nL02 wu@
t) u (nL02 wu@
uo (L02 uo
sh) ui (L02 rei
sh) u (nL02 wo-
sh) uo (L02 wo
L01) u y /// j,q,x,y + u L01) u y /// j,q,x,y + u
L01) u (DnK y@ L01) u (DnK y@
@@ -268,60 +219,44 @@ language).
L01) ua (DnK y& L01) ua (DnK y&
L01) ue yE L01) ue yE
.group ü .group ü
?1 ü _^_EN ü _^_EN
ü y ü (L02 y
üe yE üe (L02 yE
.group v //variant of ü .group v //variant of ü
?1 v _^_EN v _^_EN
v v // foreign words l) v (L02 y // ü
l) v y //ü n) v (L02 y // ü
n) v y //ü l) ve (L02 yE // üe
l) ve yE //üe n) ve (L02 yE // üe
n) ve yE //üe
.group w .group w
?1 w _^_EN w _^_EN
@) w (K _^_EN wa (L02 wA // wa
wa wA //wa wan wang wa (nL02 wA // wan
wai wai wa (ngL02 wA // wang
wa1i wai55 wai (L02 wai
wa2i wai35 wei (L02 wei
wa3i wai214 we (nL02 wu@ // wen
wa4i wai51 we (ngL02 wu@ // weng
wei wei wo (L02 wo
we1i wei55 wu (L02 wu
we2i wei35
we3i wei214
we4i wei51
we wu@ //wen weng
wo wo
wu wu
.group x .group x
?1 x _^_EN x _^_EN
x S; x (L03L02 S;
@) x (K _^_EN
.group y .group y
?1 y _^_EN y _^_EN
y j //before a o e i y (L03L02 j
y (u //NULL before u
y (uK ;
y (uDn ;
yo (DngK yu
y (K i // foreign words
@) y (K _^_EN
.group z .group z
?1 z _^_EN z _^_EN
z ts z (L03L02 ts
zh (+ ts. zh (L03L02 ts.
@) z (K _^_EN
//tone number // tone number
.group .group
1 55 1 55
2 35 2 35
+1
View File
@@ -1,6 +1,7 @@
//From Unihan database ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip kMandarin entries (except the ones that have kHanyuPinlu, which are in zh_list) //From Unihan database ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip kMandarin entries (except the ones that have kHanyuPinlu, which are in zh_list)
//with compounds from CC-CEDICT http://www.mdbg.net/chindict/chindict.php?page=cedict and some corrections //with compounds from CC-CEDICT http://www.mdbg.net/chindict/chindict.php?page=cedict and some corrections
//21611 single characters plus 36500 compound exceptions (includes 320 added 'yi' and 10721 added 'bu' exceptions, and 9700 extra 2-syllable words for 3rd-tone sandhi blocking) //21611 single characters plus 36500 compound exceptions (includes 320 added 'yi' and 10721 added 'bu' exceptions, and 9700 extra 2-syllable words for 3rd-tone sandhi blocking)
$textmode
〇 ling2 〇 ling2
㐀 qiu1 㐀 qiu1
㐁 tian3 㐁 tian3
-2
View File
@@ -10,8 +10,6 @@ pitch 80 118
dict_min 100000 dict_min 100000
dictrules 1 // interpret latin characters as English text
//for some dialects //for some dialects
//[en]: replace ng with n //[en]: replace ng with n
+2 -2
View File
@@ -1590,14 +1590,14 @@ Translator *SelectTranslator(const char *name)
tr->langopts.our_alphabet = 0x3100; tr->langopts.our_alphabet = 0x3100;
tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
tr->langopts.textmode = true; tr->langopts.textmode = true;
tr->langopts.listx = 1; // compile *_listx after *_list
if (name2 == L3('y', 'u', 'e')) { if (name2 == L3('y', 'u', 'e')) {
tr->langopts.listx = 1; // compile zh_listx after zh_list
tr->langopts.numbers = NUM_DEFAULT; tr->langopts.numbers = NUM_DEFAULT;
tr->langopts.numbers2 = NUM2_ZERO_TENS; tr->langopts.numbers2 = NUM2_ZERO_TENS;
tr->langopts.break_numbers = BREAK_INDIVIDUAL; tr->langopts.break_numbers = BREAK_INDIVIDUAL;
} }
break;
} }
break;
default: default:
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
break; break;
+5
View File
@@ -164,6 +164,10 @@ int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_o
wtab->flags &= ~FLAG_FIRST_UPPER; wtab->flags &= ~FLAG_FIRST_UPPER;
} }
// dictionary_skipwords is a global variable and TranslateWord3 will reset it to 0 at the beginning.
// However, dictionary_skipwords value is still needed outside this scope.
// So we backup and restore it at the end of this scope.
int skipwords = dictionary_skipwords;
TranslateWord3(tr, word_out, wtab, NULL, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes)); TranslateWord3(tr, word_out, wtab, NULL, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes));
int n; int n;
@@ -182,6 +186,7 @@ int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_o
while (!isspace(*word_out)) ++word_out; while (!isspace(*word_out)) ++word_out;
while (isspace(*word_out)) ++word_out; while (isspace(*word_out)) ++word_out;
} }
dictionary_skipwords = skipwords;
} }
// If the list file contains a text replacement to another // If the list file contains a text replacement to another
+4 -2
View File
@@ -101,5 +101,7 @@ test_phon fa "j'ek j'ek" "1‌1"
# Mandarin and Cantonese Chinese with different Latin character fallback # Mandarin and Cantonese Chinese with different Latin character fallback
test_phon yue "n'ei5_| h'ou2_| m'aa5_| (en)h@1l'oU1_| D'e@1(yue)_|" "你好馬 hello there" test_phon yue "n'ei5_| h'ou2_| m'aa5_| (en)h@1l'oU1_| D'e@1(yue)_|" "你好馬 hello there"
test_phon yue-latn-jyutping "n'ei5_| h'ou2_| m'aa5_| n'ei5_| h'ou2_| m'aa5_|" "你好馬 nei5 hou2 maa5" test_phon yue-latn-jyutping "n'ei5_| h'ou2_| m'aa5_| n'ei5_| h'ou2_| m'aa5_|" "你好馬 nei5 hou2 maa5"
test_phon cmn "n'i3_| ha11'o3_| m'a3_| (en)h@11loU11_| De@11(cmn)_|" "你好馬 hello there" test_phon cmn "ni35X'Au35_| m'A21_| (en)h@44loU11_| De@11(cmn)_|" "你好馬 hello there"
test_phon cmn-latn-pinyin "n'i3_| ha11'o3_| m'a3_| n'i35_| X'Au35_| m'A214_|" "你好馬 ni3 hao3 ma3" test_phon cmn-latn-pinyin "ni35X'Au35_| m'A35_| n'i35_| X'Au35_| m'A214_|" "你好馬 ni3 hao3 ma3"
test_phon cmn "thiE55nt'i51_|" "天地"