1 Star 1 Fork 0

fronkx / cppjieba-py

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

cppjieba-py

Build Status PyPI

cppjieba-py 是 cppjieba的 Python 封装。

由于只是对cppjieba的接口进行的封装,所以执行效率上非常接近于原cppjieba。

项目主要分为两个部分libcppjieba 为 cppjieba 的 python extension,
cppjieba_py 为使开发者平滑过渡到使用cppjieba-py而作的 python package。 具体见example.py

区别

  • 原jieba的.cut族接口基本都由python的iter()函数包裹list结果来实现。
  • 原jieba的.set_*方法基本都由class传入初始化的参数来完成。
  • .del_word.suggest_freq cppjieba没提供。
  • POSTokenizer.lcutTokenizer.tag 下, 唯一一个只提供了list返回类型的接口。

安装

  • pypi

    pip install cppjieba-py

    或者你设置的安装源并未收录本项目

    pip install -i https://pypi.org/simple/ cppjieba-py

  • 从发行包安装
    see releases

    pip install https://github.com/bung87/cppjieba-py/files/<xxxxxxx>/cppjieba_py-<x.x.x>.tar.gz

  • 从源代码安装

     $ git clone --recursive https://github.com/bung87/cppjieba-py
     $ pip install . # or 
     $ python setup.py install --old-and-unmanageable 
     without argument will install under egg dir,which cause libcppjieba found wrong default dictionaries directory

使用

下面是一个使用 cppjieba-py 进行分词的例子

# -*- coding: utf-8 -*-
import cppjieba_py as jieba 
# or use defualt Tokenizer: jieba.cut 
jieba_instance = Tokenizer()
seg_list = jieba_instance.cut("我来到北京清华大学",cut_all = True)
print("Full Mode: " + "/ ".join(seg_list))  # 全模式


seg_list = jieba_instance.cut("他来到了网易杭研大厦")  # 默认是精确模式
print(", ".join(seg_list))

seg_list = jieba_instance.cut_for_search(
    "小明硕士毕业于中国科学院计算所,后在日本京都大学深造")  # 搜索引擎模式
print(", ".join(seg_list))
    

for more: example.py , tests

性能

performace_test/speed.py

测试方案:先按行读取文本围城到一个数组里,然后循环对围城每行文字作为一个句子进行分词。因为只对围城这本书分词一遍太快了,容易误差。 所以循环对围城这本书分词50次。基本上每次分词耗时都很稳定。 分词算法都是采用【精确模式】。

lcut HMM=False

方案 速度
cppjieba-py 10.642102
jieba-fast==0.51 26.129298
jieba==0.39 50.623866

lcut HMM=True

方案 速度
cppjieba-py 13.139232
jieba-fast==0.51 34.574907
jieba==0.39 1:26.756226

posseg.lcut

方案 速度
cppjieba-py 20.382905
jieba==0.39 1:19.411649

Test

pip install ".[test]"
nosetests -c nose.cfg

MIT License Copyright (c) 2017 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

cppjieba-py 是 cppjieba的 Python 封装。 由于只是对cppjieba的接口进行的封装,所以执行效率上非常接近于原cppjieba。 展开 收起
Python 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/fronkx/cppjieba-py.git
git@gitee.com:fronkx/cppjieba-py.git
fronkx
cppjieba-py
cppjieba-py
master

搜索帮助