Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jieba

- _Scroll down for English documentation._

- Documentation 文档: https://shouldsee.github.io/jieba/

特点
========
Expand Down Expand Up @@ -37,14 +38,31 @@ jieba

主要功能
=======

1. 分词
--------
* `jieba.cut` 方法接受四个输入参数: 需要分词的字符串;cut_all 参数用来控制是否采用全模式;HMM 参数用来控制是否使用 HMM 模型;use_paddle 参数用来控制是否使用paddle模式下的分词模式,paddle模式采用延迟加载方式,通过enable_paddle接口安装paddlepaddle-tiny,并且import相关代码;
* `jieba.cut_for_search` 方法接受两个参数:需要分词的字符串;是否使用 HMM 模型。该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细
* 待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。注意:不建议直接输入 GBK 字符串,可能无法预料地错误解码成 UTF-8
* `jieba.cut` 以及 `jieba.cut_for_search` 返回的结构都是一个可迭代的 generator,可以使用 for 循环来获得分词后得到的每一个词语(unicode),或者用
* `jieba.posseg.cut(sentence, HMM=True, use_paddle=False)` : 带词性的cut
* `jieba.cut(sentence, cut_all=False, HMM=True, use_paddle=False)`: 不带词性的cut
- 输入:
- sentence: 需要分词的字符串
- cut_all: 是否采用全模式
- HMM: HMM 是否使用 HMM 模型
- use_paddle: 是否使用paddle模式下的分词模式,paddle模式采用延迟加载方式,通过enable_paddle接口安装paddlepaddle-tiny,并且import相关代码;
- 输出:
- 一个分词结果的`generator`
* `jieba.cut_for_search(sentence, HMM=True)`:
- 输入:
- sentence: 需要分词的字符串
- HMM: 是否使用 HMM 模型
- 适合用于搜索引擎构建倒排索引的分词,粒度比较细
- 输出:
- 一个分词结果的`generator`(?)
* `jieba.Tokenizer(dictionary=DEFAULT_DICT)`:
- 作用: 新建自定义分词器,可用于同时使用不同词典。`jieba.dt` 为默认分词器,所有全局分词相关函数都是该分词器的映射。
- 输入:
- dictionary: 一个指向自定义字典的文件名,文件格式见`jieba/dict.txt`
* `sentence`: 待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。注意:不建议直接输入 GBK 字符串,可能无法预料地错误解码成 UTF-8
* `jieba.lcut` 以及 `jieba.lcut_for_search` 直接返回 list
* `jieba.Tokenizer(dictionary=DEFAULT_DICT)` 新建自定义分词器,可用于同时使用不同词典。`jieba.dt` 为默认分词器,所有全局分词相关函数都是该分词器的映射。

代码示例

Expand Down Expand Up @@ -341,7 +359,7 @@ word 有限公司 start: 6 end:10

If no filename specified, use STDIN instead.

延迟加载机制
9.延迟加载机制
------------

jieba 采用延迟加载,`import jieba` 和 `jieba.Tokenizer()` 不会立即触发词典的加载,一旦有必要才开始加载词典构建前缀字典。如果你想手工初始 jieba,也可以手动初始化。
Expand Down Expand Up @@ -785,4 +803,3 @@ Segmentation speed
* 1.5 MB / Second in Full Mode
* 400 KB / Second in Default Mode
* Test Env: Intel(R) Core(TM) i7-2600 CPU @ 3.4GHz;《围城》.txt

4 changes: 4 additions & 0 deletions docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c3b5902a17372bc5d085236ad919e5bf
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added docs/.doctrees/all_module.doctree
Binary file not shown.
Binary file added docs/.doctrees/environment.pickle
Binary file not shown.
Binary file added docs/.doctrees/func-token.doctree
Binary file not shown.
Binary file added docs/.doctrees/index.doctree
Binary file not shown.
Binary file added docs/.doctrees/token_module.doctree
Binary file not shown.
Binary file added docs/.doctrees/tokenization.doctree
Binary file not shown.
Binary file added docs/.doctrees/usage.doctree
Binary file not shown.
Empty file added docs/.nojekyll
Empty file.
13 changes: 13 additions & 0 deletions docs/_sources/all_module.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
模块列表
==============

.. automodule:: jieba
:members:
:undoc-members:
:show-inheritance:


.. automodule:: jieba.posseg
:members:
:undoc-members:
:show-inheritance:
68 changes: 68 additions & 0 deletions docs/_sources/func-token.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
功能简介
=========

分词
#####


不带词性的切分: 参见 :py:func:`jieba.cut`, :py:func:`jieba.lcut`
-----------------------------------------------------------------------

默认使用带HMM的精确模式,不使用paddle, 调用默认分词器 :py:meth:`jieba.Tokenizer.cut`
对序列进行不带词性的切分.

例子:


.. code-block:: python

# encoding=utf-8
import jieba

jieba.enable_paddle()# 启动paddle模式。 0.40版之后开始支持,早期版本不支持
strs=["我来到北京清华大学","乒乓球拍卖完了","中国科学技术大学"]
for str in strs:
seg_list = jieba.cut(str,use_paddle=True) # 使用paddle模式
print("Paddle Mode: " + '/'.join(list(seg_list)))

seg_list = jieba.cut("我来到北京清华大学", cut_all=True)
print("Full Mode: " + "/ ".join(seg_list)) # 全模式

seg_list = jieba.cut("我来到北京清华大学", cut_all=False)
print("Default Mode: " + "/ ".join(seg_list)) # 精确模式

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

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

结果:

.. code-block::

【全模式】: 我/ 来到/ 北京/ 清华/ 清华大学/ 华大/ 大学

【精确模式】: 我/ 来到/ 北京/ 清华大学

【新词识别】:他, 来到, 了, 网易, 杭研, 大厦 (此处,“杭研”并没有在词典中,但是也被Viterbi算法识别出来了)

【搜索引擎模式】: 小明, 硕士, 毕业, 于, 中国, 科学, 学院, 科学院, 中国科学院, 计算, 计算所, 后, 在, 日本, 京都, 大学, 日本京都大学, 深造


带词性的切分: 参见 :py:func:`jieba.posseg.cut`, :py:func:`jieba.posseg.lcut`
-------------------------------------------------------------------------


适合用于搜索引擎构建倒排索引的分词,粒度比较细 参见 :py:func:`jieba.cut_for_search`
-------------------------------------------------------------------------


新建自定义分词器,可用于同时使用不同词典。参见 :py:meth:`jieba.Tokenizer.__init__`
-------------------------------------------------------------------------

备注
------------

- :py:class:`sentence` : 待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。注意:不建议直接输入 GBK 字符串,可能无法预料地错误解码成 UTF-8
- :py:func:`jieba.lcut` 以及 :py:func:`jieba.lcut_for_search` 直接返回 list
Loading