Fix genpytable.py
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 18 Jan 2010 08:39:58 +0000 (16:39 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 18 Jan 2010 08:39:58 +0000 (16:39 +0800)
scripts/genpytable.py
src/PinyinParser.cc
src/PinyinParserTable.h

index 70158a5..223bc8f 100644 (file)
@@ -126,7 +126,7 @@ def get_pinyin():
                s2 + w not in pinyin_list and \
                s2 + c in pinyin_list:
                 flag_correct = "PINYIN_CORRECT_%s_TO_%s" % (w.upper(), c.upper())
-                yield s1 + w, s2, c, len(s2) + len(w), ["%s | %s" % (flag, flag_correct)]
+                yield s1 + w, s1, c, len(s2) + len(w), ["%s | %s" % (flag, flag_correct)]
 
             # if s2 + y not in pinyin_list and s1 + y in pinyin_list:
             #     yield s2 + y, s2, y, len (s2) + len(y), [flag]
@@ -253,7 +253,6 @@ def gen_tables():
 
     print '};'
     print
-    print '#define PINYIN_TABLE_NR (sizeof (pinyin_table) / sizeof (pinyin_table[0]))'
 
     return pinyins
 
@@ -325,7 +324,6 @@ def gen_full_pinyin_table(pinyins):
     for p in full_pinyin:
         print "    &pinyin_table[%d],    // %s" % (_dict[p], p[0])
     print '};'
-    print '#define FULL_PINYIN_TABLE_NR (sizeof (full_pinyin_table) / sizeof (full_pinyin_table[0]))'
     print
 
 
@@ -342,7 +340,6 @@ def gen_special_table(pinyins):
 
         print '    { %s %s %s %s },' % tuple(ids), "/* %s %s => %s %s */" % r
     print '};'
-    print '#define SPECIAL_TABLE_NR (sizeof (special_table) / sizeof (special_table[0]))'
     print
 
 
index f85c0dc..25d11b6 100644 (file)
@@ -52,7 +52,7 @@ is_pinyin (const gchar *p,
     if (G_LIKELY (len > 0)) {
         strncpy (buf, p, len);
         buf[len] = 0;
-        result = (const Pinyin *) bsearch (buf, pinyin_table, PINYIN_TABLE_NR,
+        result = (const Pinyin *) bsearch (buf, pinyin_table, G_N_ELEMENTS (pinyin_table),
                                             sizeof (Pinyin), py_cmp);
         if (check_flags (result, option))
             return result;
@@ -65,7 +65,7 @@ is_pinyin (const gchar *p,
 
     for (; len > 0; len --) {
         buf[len] = 0;
-        result = (const Pinyin *) bsearch (buf, pinyin_table, PINYIN_TABLE_NR,
+        result = (const Pinyin *) bsearch (buf, pinyin_table, G_N_ELEMENTS (pinyin_table),
                                             sizeof (Pinyin), py_cmp);
         if (G_UNLIKELY (check_flags (result, option))) {
             return result;
@@ -91,7 +91,7 @@ need_resplit(const Pinyin *p1,
 {
     const Pinyin * pys[] = {p1, p2};
 
-    return (const Pinyin **) bsearch (pys, special_table, SPECIAL_TABLE_NR,
+    return (const Pinyin **) bsearch (pys, special_table, G_N_ELEMENTS (special_table),
                                         sizeof (special_table[0]), sp_cmp);
 }
 
@@ -229,7 +229,7 @@ PinyinParser::isPinyin (gint sheng, gint yun, guint option)
     g_strlcpy (buf, id_map[sheng], sizeof (buf));
     g_strlcat (buf, id_map[yun], sizeof (buf));
 
-    result = (const Pinyin *) bsearch (buf, pinyin_table, PINYIN_TABLE_NR,
+    result = (const Pinyin *) bsearch (buf, pinyin_table, G_N_ELEMENTS (pinyin_table),
                                             sizeof (Pinyin), py_cmp);
     if (check_flags (result, option))
         return result;
index 8e830ba..493149d 100644 (file)
@@ -1964,11 +1964,11 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 151 */
         text        : "fuei",
-        sheng       : "h",
+        sheng       : "f",
         yun         : "ui",
-        sheng_id    : PINYIN_ID_H,
+        sheng_id    : PINYIN_ID_F,
         yun_id      : PINYIN_ID_UI,
-        fsheng_id   : PINYIN_ID_F,
+        fsheng_id   : PINYIN_ID_H,
         fyun_id     : PINYIN_ID_ZERO,
         fsheng_id_2 : PINYIN_ID_ZERO,
         fyun_id_2   : PINYIN_ID_ZERO,
@@ -1977,11 +1977,11 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 152 */
         text        : "fuen",
-        sheng       : "h",
+        sheng       : "f",
         yun         : "un",
-        sheng_id    : PINYIN_ID_H,
+        sheng_id    : PINYIN_ID_F,
         yun_id      : PINYIN_ID_UN,
-        fsheng_id   : PINYIN_ID_F,
+        fsheng_id   : PINYIN_ID_H,
         fyun_id     : PINYIN_ID_ZERO,
         fsheng_id_2 : PINYIN_ID_ZERO,
         fyun_id_2   : PINYIN_ID_ZERO,
@@ -4018,13 +4018,13 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 309 */
         text        : "luei",
-        sheng       : "r",
+        sheng       : "l",
         yun         : "ui",
-        sheng_id    : PINYIN_ID_R,
+        sheng_id    : PINYIN_ID_L,
         yun_id      : PINYIN_ID_UI,
-        fsheng_id   : PINYIN_ID_L,
+        fsheng_id   : PINYIN_ID_N,
         fyun_id     : PINYIN_ID_ZERO,
-        fsheng_id_2 : PINYIN_ID_ZERO,
+        fsheng_id_2 : PINYIN_ID_R,
         fyun_id_2   : PINYIN_ID_ZERO,
         len         : 4,
         flags       : PINYIN_FUZZY_L_R | PINYIN_CORRECT_UEI_TO_UI
@@ -4954,13 +4954,13 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 381 */
         text        : "nuen",
-        sheng       : "l",
+        sheng       : "n",
         yun         : "un",
-        sheng_id    : PINYIN_ID_L,
+        sheng_id    : PINYIN_ID_N,
         yun_id      : PINYIN_ID_UN,
-        fsheng_id   : PINYIN_ID_N,
+        fsheng_id   : PINYIN_ID_L,
         fyun_id     : PINYIN_ID_ZERO,
-        fsheng_id_2 : PINYIN_ID_R,
+        fsheng_id_2 : PINYIN_ID_ZERO,
         fyun_id_2   : PINYIN_ID_ZERO,
         len         : 4,
         flags       : PINYIN_FUZZY_N_L | PINYIN_CORRECT_UEN_TO_UN
@@ -5981,13 +5981,13 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 460 */
         text        : "riou",
-        sheng       : "l",
+        sheng       : "r",
         yun         : "iu",
-        sheng_id    : PINYIN_ID_L,
+        sheng_id    : PINYIN_ID_R,
         yun_id      : PINYIN_ID_IU,
-        fsheng_id   : PINYIN_ID_N,
+        fsheng_id   : PINYIN_ID_L,
         fyun_id     : PINYIN_ID_ZERO,
-        fsheng_id_2 : PINYIN_ID_R,
+        fsheng_id_2 : PINYIN_ID_ZERO,
         fyun_id_2   : PINYIN_ID_ZERO,
         len         : 4,
         flags       : PINYIN_FUZZY_R_L | PINYIN_CORRECT_IOU_TO_IU
@@ -6111,13 +6111,13 @@ static const Pinyin pinyin_table[] = {
     },
     {  /* 470 */
         text        : "rue",
-        sheng       : "l",
+        sheng       : "r",
         yun         : "ve",
-        sheng_id    : PINYIN_ID_L,
+        sheng_id    : PINYIN_ID_R,
         yun_id      : PINYIN_ID_VE,
-        fsheng_id   : PINYIN_ID_N,
+        fsheng_id   : PINYIN_ID_L,
         fyun_id     : PINYIN_ID_ZERO,
-        fsheng_id_2 : PINYIN_ID_R,
+        fsheng_id_2 : PINYIN_ID_ZERO,
         fyun_id_2   : PINYIN_ID_ZERO,
         len         : 3,
         flags       : PINYIN_FUZZY_R_L | PINYIN_CORRECT_UE_TO_VE
@@ -9023,7 +9023,6 @@ static const Pinyin pinyin_table[] = {
     },
 };
 
-#define PINYIN_TABLE_NR (sizeof (pinyin_table) / sizeof (pinyin_table[0]))
 static const Pinyin *special_table[][4] = {
     { &pinyin_table[4],    &pinyin_table[0],    &pinyin_table[0],    &pinyin_table[345],  }, /* an a => a na */
     { &pinyin_table[4],    &pinyin_table[6],    &pinyin_table[0],    &pinyin_table[351],  }, /* an ao => a nao */
@@ -9697,5 +9696,4 @@ static const Pinyin *special_table[][4] = {
     { &pinyin_table[692],  &pinyin_table[126],  &pinyin_table[684],  &pinyin_table[354],  }, /* zun ei => zu nei */
     { &pinyin_table[692],  &pinyin_table[127],  &pinyin_table[684],  &pinyin_table[356],  }, /* zun en => zu nen */
 };
-#define SPECIAL_TABLE_NR (sizeof (special_table) / sizeof (special_table[0]))