91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-12
  • 語言: Python
  • 標簽: python??scel??txt??

資源簡介

該工具是一個python程序,你只需要運行python 輸入搜狗詞庫源安裝包路勁就可以把scel安裝包轉(zhuǎn)化成txt

資源截圖

代碼片段和文件信息

#!/usr/bin/python??
#?-*-?coding:?utf-8?-*-??
import?struct??
import?sys??
import?binascii???
import?pdb??
import?os
import?codecs

#作者:scarecrow
#來源:核心代碼來源于?哥本草根微博?本人僅是加工包裝核心代碼方便他人使用

#搜狗的scel詞庫就是保存的文本的unicode編碼,每兩個字節(jié)一個字符(中文漢字或者英文字母)??
#找出其每部分的偏移位置即可??
#主要兩部分??
#1.全局拼音表,貌似是所有的拼音組合,字典序??
#???????格式為(indexlenpinyin)的列表??
#???????index:?兩個字節(jié)的整數(shù)?代表這個拼音的索引??
#???????len:?兩個字節(jié)的整數(shù)?拼音的字節(jié)長度??
#???????pinyin:?當前的拼音,每個字符兩個字節(jié),總長len??
#?????????
#2.漢語詞組表??
#???????格式為(samepy_table_lenpy_table{word_lenwordext_lenext})的一個列表??
#???????same:?兩個字節(jié)?整數(shù)?同音詞數(shù)量??
#???????py_table_len:??兩個字節(jié)?整數(shù)??
#???????py_table:?整數(shù)列表,每個整數(shù)兩個字節(jié)每個整數(shù)代表一個拼音的索引??
#??
#???????word_len:兩個字節(jié)?整數(shù)?代表中文詞組字節(jié)數(shù)長度??
#???????word:?中文詞組每個中文漢字兩個字節(jié),總長度word_len??
#???????ext_len:?兩個字節(jié)?整數(shù)?代表擴展信息的長度,好像都是10??
#???????ext:?擴展信息?前兩個字節(jié)是一個整數(shù)(不知道是不是詞頻)?后八個字節(jié)全是0??
#??
#??????{word_lenwordext_lenext}?一共重復(fù)same次?同音詞?相同拼音表??
??
#拼音表偏移,??
startPy?=?0x1540;??
??
??
#漢語詞組表偏移??
startChinese?=?0x2628;??
??
#全局拼音表??
??
GPy_Table?={}??
??
#解析結(jié)果??
#元組(詞頻拼音中文詞組)的列表??
GTable?=?[]??
??
def?byte2str(data):??
????‘‘‘‘‘將原始字節(jié)碼轉(zhuǎn)為字符串‘‘‘??
????i?=?0;??
????length?=?len(data)??
????ret?=?u‘‘??
????while?i?????????x?=?data[i]?+?data[i+1]??
????????t?=?unichr(struct.unpack(‘H‘x)[0])??
????????if?t?==?u‘\r‘:??
????????????ret?+=?u‘\n‘??
????????elif?t?!=?u‘?‘:??
????????????ret?+=?t??
????????i?+=?2??
????return?ret??
#獲取拼音表??
def?getPyTable(data):??
??
????if?data[0:4]?!=?“\x9D\x01\x00\x00“:??
????????return?None??
????data?=?data[4:]??
????pos?=?0??
????length?=?len(data)??
????while?pos?????????index?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????#print?index??
????????pos?+=?2??
????????l?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????#print?l??
????????pos?+=?2??
????????py?=?byte2str(data[pos:pos+l])??
????????#print?py??
????????GPy_Table[index]=py??
????????pos?+=?l??
??
#獲取一個詞組的拼音??
def?getWordPy(data):??
????pos?=?0??
????length?=?len(data)??
????ret?=?u‘‘??
????while?pos???????????
????????index?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????ret?+=?GPy_Table[index]??
????????pos?+=?2??????
????return?ret??
??
#獲取一個詞組??
def?getWord(data):??
????pos?=?0??
????length?=?len(data)??
????ret?=?u‘‘??
????while?pos???????????
????????index?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????ret?+=?GPy_Table[index]??
????????pos?+=?2??????
????return?ret??
??
#讀取中文表??????
def?getChinese(data):??
????#import?pdb??
????#pdb.set_trace()??
??????
????pos?=?0??
????length?=?len(data)??
????while?pos?????????#同音詞數(shù)量??
????????same?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????#print?‘[same]:‘same??
??????????
????????#拼音索引表長度??
????????pos?+=?2??
????????py_table_len?=?struct.unpack(‘H‘data[pos]+data[pos+1])[0]??
????????#拼音索引表??
????????pos?+=?2??
????????py?=?getWordPy(data[pos:?pos+py_table_len])??
??
????????#中文詞組??
????????pos?+=?py_table_len??
????????for?i?in?xrange(same):??
????????????#中文詞組長度??
????????????c_len?=?s

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????6486??2016-10-12?02:33??scelToTxt.py

評論

共有 條評論