80

FoolNLTK ——可能是目前最准的中文分词工具

 6 years ago
source link: https://www.oschina.net/p/foolnltk?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

FoolNLTK

中文处理工具包

  • 可能不是最快的开源中文分词,但很可能是最准的开源中文分词

  • 基于 BiLSTM 模型训练而成

  • 包含分词,词性标注,实体识别, 都有比较高的准确率

  • 用户自定义词典

Install

pip install foolnltk
import fool

text = "一个傻子在北京"
print(fool.cut(text))
# ['一个', '傻子', '在', '北京']

命令行分词

python -m fool [filename]

用户自定义词典

词典格式格式如下,词的权重越高,词的长度越长就越越可能出现, 权重值请大于 1

难受香菇 10
什么鬼 10
分词工具 10
北京 10
北京天安门 10
import fool
fool.load_userdict(path)
text = "我在北京天安门看你难受香菇"
print(fool.cut(text))
# ['我', '在', '北京天安门', '看', '你', '难受香菇']
fool.delete_userdict();
import fool

text = "一个傻子在北京"
print(fool.pos_cut(text))
#[('一个', 'm'), ('傻子', 'n'), ('在', 'p'), ('北京', 'ns')]
import fool 

text = "一个傻子在北京"
words, ners = fool.analysis(text)
print(ners)
#[(5, 8, 'location', '北京')]
  • 暂时只在 Python3 Linux 平台测试通过

展开阅读全文

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK