chop

Chinese Words Segementation Utilities


Keywords
NLP, chinese-nlp, chinese-segmenter, parser, segment, segmenter
License
MIT
Install
pip install chop==1.0

Documentation

chatoper banner

chop

Python 中文分词工具包

欢迎

GitHub: https://github.com/samurais/chop

Pypi: https://pypi.python.org/pypi/chop

依赖

Python3

使用说明

代码对 Python 3 兼容

  • 全自动安装: easy_install chop 或者 pip install chop / pip3 install chop

  • 接口

from chop.hmm import Tokenizer as HMMTokenizer
from chop.mmseg import Tokenizer as MMSEGTokenizer

sentence = "工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作。"

def main():
    HT = HMMTokenizer()
    MT = MMSEGTokenizer()
    print('HMM Tokenizer:', ' '.join(HT.cut(sentence)))
    print('MMSEG Tokenizer:', ' '.join(MT.cut(sentence)))

  • 代码通俗易懂,方便掌握算法

API

  • chop.[mmseg|hmm].Tokenizer Object

t = chop.mmseg.Tokenizer([dict_path="自定义词典位置"])

  • t#cut(sentence[, punctuation = True])

参数:

sentence 中文句子 punctuation=True 分词输出标点.

返回:

Token 使用yield返回的generator

测试

./scripts/test-badcase.sh "工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作"

算法

Other references: http://blog.csdn.net/nciaebupt/article/details/8114460 http://www.codes51.com/itwd/1802849.html

  • HMM & Viterbi:

基于层叠隐马尔可夫模型的中文命名实体识别

词典

Dict: https://github.com/Samurais/jieba/blob/master/jieba/dict.txt

评测

chop-evaluate

贡献代码

virtualenv --no-site-packages -p /usr/local/bin/python3.6 ~/venv-py3
CHOP_LOG_LVL=DEBUG
./scripts/test.sh

感谢

hanlp

jieba

mmseg

Python实现mmseg分词算法和吐嘈

测评

中文分词工具测评

授权协议

MIT