[Python] 结巴中文分词

Posted in :

免費的分詞系統,滿好玩的,還可以自定義自己的字典和權重。

github:
https://github.com/fxsjy/jieba

使用範例:

# encoding=utf-8 
import jieba seg_list = jieba.cut("請以半形數字輸入您所購買節目的演出日期,如演出日期為2019/03/30,請輸入20190330。Please enter the date of the show you purchased in halfwidth form.For example: the date of the show is 2019/03/30,please enter 20190330.") # 默认是精确模式
print(", ".join(seg_list))

結果:

Default Mode: 請/ 以半形/ 數字/ 輸入/ 您/ 所購/ 買節/ 目的/ 演出/ 日期/ ,/ 如/ 演出/ 日期/ 為/ 2019/ // 03/ // 30/ ,/ 請輸入/ 20190330/ 。/ Please/  / enter/  / the/  / date/  / of/  / the/  / show/  / you/  / purchased/  / in/  / halfwidth/  / form/ ./ For/  / example/ :/  / the/  / date/  / of/  / the/  / show/  / is/  / 2019/ // 03/ // 30/ ,/ please/  / enter/  / 20190330/ .

節和目會被切開,解法服用下面這段code:

for i in range(10):
jieba.suggest_freq(u'節目', True)

或使用外部字典:
https://github.com/fxsjy/jieba/issues/14

解决方案是在词典中补充“節目”这个词,并给予一个词频,不用太大,比如3即可。

==user.dict===
節目 3
==test.py==
import sys
import jieba
jieba.load_userdict("user.dict")

如果需要發佈執行檔給別人,你可能需要知道:
Location of global libraries for Python on Mac?

解法:Try checking your python’s sys.path list with:

import sys
print(sys.path)

相關網址:

CKIP中文斷詞系統 學術試用版 授權申請
http://ckipsvr.iis.sinica.edu.tw/ckipws/reg.php

CKIP中文斷詞系統,著作權屬中央研究院詞庫小組。智慧財產權屬中央研究院所有。不得將此中文斷詞系統之全部或部份移轉給第三人。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *