mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add FullSegment QuerySegment TrieManger to README.md
This commit is contained in:
parent
7add684a8a
commit
82424cc7f5
51
README.md
51
README.md
@ -80,10 +80,13 @@ Output:
|
||||
```
|
||||
我来到北京清华大学
|
||||
我来/到/北京/清华大学
|
||||
|
||||
他来到了网易杭研大厦
|
||||
他来/到/了/网易/杭/研大厦
|
||||
|
||||
小明硕士毕业于中国科学院计算所,后在日本京都大学深造
|
||||
小明/硕士/毕业于/中国/科学院/计算所/,/后/在/日/本/京/都/大/学/深/造
|
||||
|
||||
我来自北京邮电大学。。。学号091111xx。。。
|
||||
我来/自北京/邮电大学/。。。/学号/091111xx/。。。
|
||||
```
|
||||
@ -94,23 +97,60 @@ Output:
|
||||
```
|
||||
我来到北京清华大学
|
||||
我/来到/北京/清华大学
|
||||
|
||||
他来到了网易杭研大厦
|
||||
他/来到/了/网易/杭研/大厦
|
||||
杭研
|
||||
杭研
|
||||
|
||||
小明硕士毕业于中国科学院计算所,后在日本京都大学深造
|
||||
小明/硕士/毕业/于/中国科学院/计算所/,/后/在/日本京都大学/深造
|
||||
|
||||
我来自北京邮电大学。。。学号091111xx。。。
|
||||
我/来自/北京邮电大学/。。。/学号/091111xx/。。。
|
||||
```
|
||||
|
||||
### FullSegment's demo
|
||||
|
||||
Output:
|
||||
```
|
||||
我来到北京清华大学
|
||||
我/来到/北京/清华/清华大学/华大/大学
|
||||
|
||||
他来到了网易杭研大厦
|
||||
他/来到/了/网易/杭/研/大厦
|
||||
|
||||
小明硕士毕业于中国科学院计算所,后在日本京都大学深造
|
||||
小/明/硕士/毕业/于/中国/中国科学院/科学/科学院/学院/计算/计算所/,/后/在/日本/日本京都大学/京都/京都大学/大学/深造
|
||||
|
||||
我来自北京邮电大学。。。 学号 091111xx。。。
|
||||
我/来自/北京/北京邮电/北京邮电大学/邮电/邮电大学/电大/大学/。/。/。/ /学号/ 091111xx/。/。/。
|
||||
```
|
||||
|
||||
### QuerySegment's demo
|
||||
|
||||
Output:
|
||||
```
|
||||
我来到北京清华大学
|
||||
我/来到/北京/清华/清华大学/华大/大学
|
||||
|
||||
他来到了网易杭研大厦
|
||||
他/来到/了/网易/杭研/大厦
|
||||
|
||||
小明硕士毕业于中国科学院计算所,后在日本京都大学深造
|
||||
小明/硕士/毕业/于/中国/中国科学院/科学/科学院/学院/计算所/,/后/在/中国/中国科学院/科学/科学院/学院/日本/日本京都大学/京都/京都大学/大学/深造
|
||||
|
||||
我来自北京邮电大学。。。 学号 091111xx。。。
|
||||
我/来自/北京/北京邮电/北京邮电大学/邮电/邮电大学/电大/大学/。/。/。/ /学号/ 091111xx/。/。/。
|
||||
```
|
||||
|
||||
### 效果分析
|
||||
|
||||
以上依次是MP,HMM,Mix三种方法的效果。
|
||||
|
||||
可以看出效果最好的是Mix,也就是融合MP和HMM的切词算法。即可以准确切出词典已有的词,又可以切出像"杭研"这样的未登录词。
|
||||
|
||||
Full方法切出所有字典里的词语。
|
||||
|
||||
Query方法先使用Mix方法切词,对于切出来的较长的词再使用Full方法。
|
||||
|
||||
## 模块详解
|
||||
|
||||
@ -120,6 +160,10 @@ Output:
|
||||
|
||||
核心目录,包含主要源代码。
|
||||
|
||||
#### TrieManager模块
|
||||
TrieManager.hpp 提供一个单例TrieManager,负责管理trie树。
|
||||
通过该单例获取trie树时,会先判断是否已经由该字典文件生成了一颗trie树,如果已有则返回已有的trie树,否则重新创建一颗trie树返回。
|
||||
|
||||
#### Trie树
|
||||
Trie.hpp 负责载入词典的trie树,主要供Segment模块使用。
|
||||
|
||||
@ -133,6 +177,9 @@ HMMSegment.hpp
|
||||
HMM模型由dicts/下面的`hmm_model.utf8`提供。
|
||||
分词算法即viterbi算法。
|
||||
|
||||
FullSegment.hpp
|
||||
枚举句子中所有可能成词的情况,找出字典里存在的即可。
|
||||
|
||||
#### TransCode模块
|
||||
|
||||
TransCode.cpp/TransCode.h 负责转换编码类型,将utf8和gbk转换成`uint16_t`类型,也负责逆转换。
|
||||
|
@ -43,12 +43,13 @@ int main(int argc, char ** argv)
|
||||
<<"\t--algorithm\tSupported methods are [cutDAG, cutHMM, cutFull, cutQuery, cutMix] for now. \n\t\t\tIf not specified, the default is cutMix\n"
|
||||
<<"\t--dictpath\tsee example\n"
|
||||
<<"\t--modelpath\tsee example\n"
|
||||
<<"\t--maxlen\tspecify the granularity of cut used in cutQuery, If not specified, the default is 3\n"
|
||||
<<"\t--maxlen\tspecify the granularity of cut used in cutQuery. \n\t\t\tIf not specified, the default is 3\n"
|
||||
<<"example:\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --algorithm cutDAG\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testlines.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutHMM\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutMix\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutQuery --maxlen 3\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --algorithm cutDAG\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --algorithm cutFull\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutHMM\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutMix\n"
|
||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dicts/jieba.dict.utf8 --modelpath ../dicts/hmm_model.utf8 --algorithm cutQuery --maxlen 3\n"
|
||||
<<endl;
|
||||
|
||||
return EXIT_FAILURE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user