File: import_ziguang_userdict.py

package info (click to toggle)
sunpinyin 3.0.0~rc1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,944 kB
  • sloc: cpp: 13,586; python: 923; makefile: 198
file content (33 lines) | stat: -rwxr-xr-x 765 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3

import os, sys
import codecs
from importer import import_to_sunpinyin_user_dict

def load_ziguang_user_dict (fname):
    result = []
    f = codecs.open (fname, "r", "UTF-16")
    for l in f:
        if l[0] in ('\n', '\r'):
            continue

        try:
            utf8str, pystr, _ = l.strip().split("\t")
            result.append ((pystr, utf8str))
        except:
            pass

    return result

def main ():
    if len (sys.argv) != 2:
        print("Please specify the ZiGuang PinYin exported user dict file!")
        exit (1)

    ziguang_user_dict = load_ziguang_user_dict(sys.argv[1])
    import_to_sunpinyin_user_dict (ziguang_user_dict)

if __name__ == "__main__":
    main()

# -*- indent-tabs-mode: nil -*- vim:et:ts=4