add Jieba::Tag

This commit is contained in:
yanyiwu 2015-11-26 00:47:16 +08:00
parent c27d89c60d
commit 60ca5093a9
4 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,9 @@
# CppJieba ChangeLog
## next version
1. 在 class Jieba 中新增词性标注的接口函数 Jieba::Tag
## v4.1.0
1. QuerySegment切词时加一层判断当长词满足IsAllAscii(比如英文单词)时,不进行细粒度分词。

View File

@ -295,7 +295,7 @@ Query方法先使用Mix方法切词对于切出来的较长的词再使用Ful
```
我是蓝翔技工拖拉机学院手扶拖拉机专业的。不用多久我就会升职加薪当上总经理出任CEO迎娶白富美走上人生巅峰。
["我:r", "是:v", "蓝翔:x", "技工:n", "拖拉机:n", "学院:n", "手扶拖拉机:n", "专业:n", "的:uj", "。:x", "不用:v", "多久:m", ":x", "我:r", "就:d", "会:v", "升职:v", "加薪:nr", ":x", "当:t", "上:f", "总经理:n", ":x", "出任:v", "CEO:eng", ":x", "迎娶:v", "白富美:x", ":x", "走上:v", "人生:n", "巅峰:n", "。:x"]
["我:r", "是:v", "拖拉机:n", "学院:n", "手扶拖拉机:n", "专业:n", "的:uj", "。:x", "不用:v", "多久:m", ":x", "我:r", "就:d", "会:v", "升职:v", "加薪:nr", ":x", "当上:t", "CEO:eng", ":x", "走上:v", "人生:n", "巅峰:n", "。:x"]
```
详细请看 `test/demo.cpp`.

View File

@ -17,7 +17,8 @@ class Jieba {
mix_seg_(&dict_trie_, &model_),
full_seg_(&dict_trie_),
query_seg_(&dict_trie_, &model_),
level_seg_(&dict_trie_) {
level_seg_(&dict_trie_),
pos_tagger_(&dict_trie_, &model_) {
}
~Jieba() {
}
@ -43,6 +44,9 @@ class Jieba {
void CutSmall(const string& sentence, vector<string>& words, size_t max_word_len) const {
mp_seg_.Cut(sentence, words, max_word_len);
}
void Tag(const string& sentence, vector<pair<string, string> >& words) const {
pos_tagger_.Tag(sentence, words);
}
bool InsertUserWord(const string& word, const string& tag = UNKNOWN_TAG) {
return dict_trie_.InsertUserWord(word, tag);
}
@ -69,6 +73,8 @@ class Jieba {
QuerySegment query_seg_;
LevelSegment level_seg_;
PosTagger pos_tagger_;
}; // class Jieba
} // namespace Jieba

View File

@ -33,11 +33,11 @@ int main(int argc, char** argv) {
jieba.Cut("男默女泪", words);
cout << limonp::join(words.begin(), words.end(), "/") << endl;
//cout << "[demo] TAGGING" << endl;
//vector<pair<string, string> > tagres;
//jieba.Tag(s, tagres);
//cout << s << endl;
//cout << tagres << endl;;
cout << "[demo] TAGGING" << endl;
vector<pair<string, string> > tagres;
jieba.Tag(s, tagres);
cout << s << endl;
cout << tagres << endl;;
//cout << "[demo] KEYWORD" << endl;
//vector<pair<string, double> > keywordres;