正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

OOo,TeX,KO,ABI,GIMP,Picasa,ProE,QCAD,Inkscape,Kicad,Eagle
回复
头像
yq-ysy
论坛版主
帖子: 4648
注册时间: 2008-07-19 12:44
来自: 广西(桂)南宁(邕)

正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

#1

帖子 yq-ysy » 2016-05-15 17:38

单字的码表已经接近完成一万字,还差一半。现在考虑词组的码表生成方法,
打算用程序脚本,读取词组文件,然后生成词组码表。
但不知道,从哪里能拿到大量的“词组”(词库)?

虽然从一些字典网站可以查询到不完全的词组,
并且还要复制、粘贴、合并为一个文件,也很麻烦。
搜狗输入法带有大量的分类词库,可惜不懂如何提取出来……

请问各位还有没有什么好办法?
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

#2

帖子 月下叹逍遥 » 2016-05-15 23:36

python2解析搜狗输入法词库

代码: 全选

#!/usr/bin/env python
import struct
import os, sys

def read_utf16_str (f, offset=-1, len=2):
    if offset >= 0:
        f.seek(offset)
    str = f.read(len)
    return str.decode('UTF-16LE')

def read_uint16 (f):
    return struct.unpack ('<H', f.read(2))[0]

def get_word_from_sogou_cell_dict (fname):
    f = open (fname, 'rb')
    file_size = os.path.getsize (fname)

    hz_offset = 0
    mask = struct.unpack ('B', f.read(128)[4])[0]
    if mask == 0x44:
        hz_offset = 0x2628
    elif mask == 0x45:
        hz_offset = 0x26c4
    else:
        sys.exit(1)

    title   = read_utf16_str (f, 0x130, 0x338  - 0x130)
    type    = read_utf16_str (f, 0x338, 0x540  - 0x338)
    desc    = read_utf16_str (f, 0x540, 0xd40  - 0x540)
    samples = read_utf16_str (f, 0xd40, 0x1540 - 0xd40)

    py_map = {}
    f.seek(0x1540+4)

    while 1:
        py_code = read_uint16 (f)
        py_len  = read_uint16 (f)
        py_str  = read_utf16_str (f, -1, py_len)

        if py_code not in py_map:
            py_map[py_code] = py_str

        if py_str == 'zuo':
            break

    f.seek(hz_offset)
    while f.tell() != file_size:
        word_count   = read_uint16 (f)
        pinyin_count = read_uint16 (f) / 2

        py_set = []
        for i in range(pinyin_count):
            py_id = read_uint16(f)
            py_set.append(py_map[py_id])
        py_str = "'".join (py_set)

        for i in range(word_count):
            word_len = read_uint16(f)
            word_str = read_utf16_str (f, -1, word_len)
            f.read(12) 
            yield py_str, word_str

    f.close()

def showtxt (records):
    for (pystr, utf8str) in records:
        print (utf8str.encode('utf8'))

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

    generator = get_word_from_sogou_cell_dict (sys.argv[1])
    showtxt(generator)

if __name__ == "__main__":
    main()
浮生七十今三十,从此凄惶未可知
头像
YeLee
论坛版主
帖子: 26406
注册时间: 2008-08-13 8:48
系统: Fundu i64
来自: 东海硇州,一双管钥。
联系:

Re: 正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

#3

帖子 YeLee » 2016-05-16 8:41

南瓜神 :Grimace
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
头像
yq-ysy
论坛版主
帖子: 4648
注册时间: 2008-07-19 12:44
来自: 广西(桂)南宁(邕)

Re: 正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

#4

帖子 yq-ysy » 2016-05-16 15:22

月下叹逍遥 写了:python2解析搜狗输入法词库
好的,谢谢,我试试。
YeLee 写了:南瓜神
???不明白什么意思……
头像
qy117121
论坛版主
帖子: 50587
注册时间: 2007-12-14 13:40
系统: Winbuntu
来自: 志虚国乌由市
联系:

Re: 正在创建输入法码表,——请问谁知道,从哪里能拿到大量的“词组”(词库)?

#5

帖子 qy117121 » 2016-05-16 15:48

yq-ysy 写了:
YeLee 写了:南瓜神
???不明白什么意思……
二楼就是南瓜
渠月 · QY   
本人只会灌水,不负责回答问题
无聊可以点一下→ http://u.nu/ubuntu

邮箱 [email protected]
回复