Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / python / importer / import_google_userdict.py
1 #!/usr/bin/python
2
3 import os, sys
4 import codecs
5 from importer import import_to_sunpinyin_user_dict
6
7 def load_google_user_dict (fname):
8     result = []
9     f = codecs.open (fname, "r", "GB18030")
10     for l in f:
11         v = l.strip().split()
12         utf8str = v[0]
13
14         try:
15             freq = int(v[1])
16             pystr = '\''.join (v[2:])
17         except:
18             pystr = '\''.join (v[1:])
19
20         result.append ((pystr, utf8str))
21
22     return result
23
24 def main ():
25     if len (sys.argv) != 2:
26         print "Please specify the Google Pinyin exported user dict file!"
27         exit (1)
28
29     google_user_dict = load_google_user_dict(sys.argv[1])
30     import_to_sunpinyin_user_dict (google_user_dict)
31
32 if __name__ == "__main__":
33     main()