cppjieba-py
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_freqcppjieba没提供。POSTokenizer.lcut在Tokenizer.tag下, 唯一一个只提供了list返回类型的接口。
安装
-
pypi
pip install cppjieba-py或者你设置的安装源并未收录本项目
pip install -i https://pypi.org/simple/ cppjieba-py -
从发行包安装
see releasespip 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 $ python setup.py install
使用
下面是一个使用 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
性能
测试方案:先按行读取文本围城到一个数组里,然后循环对围城每行文字作为一个句子进行分词。因为只对围城这本书分词一遍太快了,容易误差。 所以循环对围城这本书分词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
Metadata
Release files for cppjieba-py 0.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cppjieba_py-0.0.13.macosx-10.14-x86_64.tar.gz | 5.1 MB | Without provenance | Details for cppjieba_py-0.0.13.macosx-10.14-x86_64.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cppjieba_py-0.0.13-py3.5-macosx-10.14-x86_64.egg | Legacy Egg format | - | - | Details for cppjieba_py-0.0.13-py3.5-macosx-10.14-x86_64.egg |
Total release size: 10.3 MB
Release files / cppjieba_py-0.0.13.macosx-10.14-x86_64.tar.gz
| Download URL | cppjieba_py-0.0.13.macosx-10.14-x86_64.tar.gz |
|---|---|
| Size | 5.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39b834c2fa6bc853b0660d21fb87b1655ac019fad38a2e7aa6e060bf41d1fecc
|
|
BLAKE2b-256 checksum How to use checksums |
401a0a4a512453eb9b59535671fd32f889ce64f2f551ae83baafdca410cbb05d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.37.0 CPython/2.7.15
|
Release files / cppjieba_py-0.0.13-py3.5-macosx-10.14-x86_64.egg
| Download URL | cppjieba_py-0.0.13-py3.5-macosx-10.14-x86_64.egg |
|---|---|
| Size | 5.2 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
0bf7f4da16f0aaa7e91dd5bf0b9a14a6a31ba9d61461adbb9eac4df7887dc37d
|
|
BLAKE2b-256 checksum How to use checksums |
0f89936229995bb1ae3c9c62f91a74643e24eaf430c9b8db46cc7acac81a7f03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.37.0 CPython/2.7.15
|
Security for cppjieba-py 0.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.