summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/gendoublepinyinheader.py60
-rw-r--r--scripts/pinyin.py16
-rw-r--r--src/storage/pinyin_parser2.cpp9
3 files changed, 76 insertions, 9 deletions
diff --git a/scripts/gendoublepinyinheader.py b/scripts/gendoublepinyinheader.py
index 61fb249..749c2d3 100644
--- a/scripts/gendoublepinyinheader.py
+++ b/scripts/gendoublepinyinheader.py
@@ -20,4 +20,64 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+import os
import pinyin
+
+
+def gen_shengmu_table(scheme):
+ entries = []
+ #select shengmu mapping
+ sheng = pinyin.SHUANGPIN_SCHEMAS[scheme][0]
+ for c in "abcdefghijklmnopqrstuvwxyz;":
+ sh = sheng.get(c, "NULL")
+ if sh != "NULL":
+ sh = '"{0}"'.format(sh)
+ entry = '{0: <5} /* {1} */'.format(sh, c.upper())
+ entries.append(entry)
+ return ',\n'.join(entries)
+
+
+def gen_yunmu_table(scheme):
+ entries = []
+ #select yunmu mapping
+ yun = pinyin.SHUANGPIN_SCHEMAS[scheme][1]
+ for c in "abcdefghijklmnopqrstuvwxyz;":
+ y = yun.get(c, ("NULL", "NULL"))
+ if len(y) == 1:
+ y1 = y[0]
+ y2 = "NULL"
+ else:
+ y1, y2 = y
+ if y1 != "NULL":
+ y1 = '"{0}"'.format(y1)
+ if y2 != "NULL":
+ y2 = '"{0}"'.format(y2)
+ entry = '{{{0: <7}, {1: <7}}} /* {2} */'.format(y1, y2, c.upper())
+ entries.append(entry)
+ return ',\n'.join(entries)
+
+
+def get_table_content(tablename):
+ (scheme, part) = tablename.split('_', 1)
+ if part == "SHENG":
+ return gen_shengmu_table(scheme)
+ if part == "YUN":
+ return gen_yunmu_table(scheme)
+
+def expand_file(filename):
+ infile = open(filename, "r")
+ for line in infile.readlines():
+ line = line.rstrip(os.linesep)
+ if len(line) < 3 :
+ print(line)
+ continue
+ if line[0] == '@' and line[-1] == '@':
+ tablename = line[1:-1]
+ print(get_table_content(tablename))
+ else:
+ print(line)
+
+
+### main function ###
+if __name__ == "__main__":
+ expand_file("double_pinyin_table.h.in")
diff --git a/scripts/pinyin.py b/scripts/pinyin.py
index 517d59d..c959886 100644
--- a/scripts/pinyin.py
+++ b/scripts/pinyin.py
@@ -388,12 +388,12 @@ XHE_SHUANGPIN_YUNMU_DICT = {
"z" : ("ou",),
}
-SHUANGPIN_SCHEMAS = [
- (N_("MSPY"), (MSPY_SHUANGPIN_SHENGMU_DICT, MSPY_SHUANGPIN_YUNMU_DICT)),
- (N_("ZRM"), (ZRM_SHUANGPIN_SHENGMU_DICT, ZRM_SHUANGPIN_YUNMU_DICT)),
- (N_("ABC"), (ABC_SHUANGPIN_SHENGMU_DICT, ABC_SHUANGPIN_YUNMU_DICT)),
- (N_("ZGPY"), (ZGPY_SHUANGPIN_SHENGMU_DICT, ZGPY_SHUANGPIN_YUNMU_DICT)),
- (N_("PYJJ"), (PYJJ_SHUANGPIN_SHENGMU_DICT, PYJJ_SHUANGPIN_YUNMU_DICT)),
- (N_("XHE"), (XHE_SHUANGPIN_SHENGMU_DICT, XHE_SHUANGPIN_YUNMU_DICT)),
-]
+SHUANGPIN_SCHEMAS = {
+ N_("MSPY") : (MSPY_SHUANGPIN_SHENGMU_DICT, MSPY_SHUANGPIN_YUNMU_DICT),
+ N_("ZRM") : (ZRM_SHUANGPIN_SHENGMU_DICT, ZRM_SHUANGPIN_YUNMU_DICT),
+ N_("ABC") : (ABC_SHUANGPIN_SHENGMU_DICT, ABC_SHUANGPIN_YUNMU_DICT),
+ N_("ZGPY") : (ZGPY_SHUANGPIN_SHENGMU_DICT, ZGPY_SHUANGPIN_YUNMU_DICT),
+ N_("PYJJ") : (PYJJ_SHUANGPIN_SHENGMU_DICT, PYJJ_SHUANGPIN_YUNMU_DICT),
+ N_("XHE") : (XHE_SHUANGPIN_SHENGMU_DICT, XHE_SHUANGPIN_YUNMU_DICT),
+}
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index ad4f05e..565b1e5 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -392,7 +392,7 @@ bool DoublePinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
assert(FALSE);
}
- options &= ~PINYIN_CORRECT_ALL;
+ options &= ~(PINYIN_CORRECT_ALL|PINYIN_AMB_ALL);
if (2 == len || 3 == len) {
/* parse shengmu and yunmu here. */
@@ -407,3 +407,10 @@ bool DoublePinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
return false;
}
+
+
+int DoublePinyinParser2::parse (guint32 options, ChewingKeyVector & keys,
+ ChewingKeyRestVector & key_rests,
+ const char *str, int len) const{
+ assert(FALSE);
+}