From 111fb007cfa0614ff7e54bb12a414ca8bb402cef Mon Sep 17 00:00:00 2001 From: zhoupeng Date: Sat, 9 Jun 2018 16:21:13 +0800 Subject: [PATCH] exposes InsertUserWord Find --- include/cppjieba/DictTrie.hpp | 19 +++++++++++++++++++ include/cppjieba/Jieba.hpp | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/include/cppjieba/DictTrie.hpp b/include/cppjieba/DictTrie.hpp index 25aa5cf..33fa5c6 100644 --- a/include/cppjieba/DictTrie.hpp +++ b/include/cppjieba/DictTrie.hpp @@ -72,6 +72,25 @@ class DictTrie { trie_->Find(begin, end, res, max_word_len); } + bool Find(const string& word) + { + const DictUnit *tmp = NULL; + RuneStrArray runes; + if (!DecodeRunesInString(word, runes)) + { + XLOG(ERROR) << "Decode failed."; + } + tmp = Find(runes.begin(), runes.end()); + if (tmp == NULL) + { + return false; + } + else + { + return true; + } + } + bool IsUserDictSingleChineseWord(const Rune& word) const { return IsIn(user_dict_single_chinese_word_, word); } diff --git a/include/cppjieba/Jieba.hpp b/include/cppjieba/Jieba.hpp index a8f6751..abd321d 100644 --- a/include/cppjieba/Jieba.hpp +++ b/include/cppjieba/Jieba.hpp @@ -72,6 +72,15 @@ class Jieba { return dict_trie_.InsertUserWord(word, tag); } + bool InsertUserWord(const string& word,int freq, const string& tag = UNKNOWN_TAG) { + return dict_trie_.InsertUserWord(word,freq, tag); + } + + bool Find(const string& word) + { + return dict_trie_.Find(word); + } + void ResetSeparators(const string& s) { //TODO mp_seg_.ResetSeparators(s);