diff --git a/Trie.cpp b/Trie.cpp index da6b5d4..f5eaa9d 100644 --- a/Trie.cpp +++ b/Trie.cpp @@ -22,7 +22,6 @@ namespace CppJieba return false; } _root = new TrieNode; - _root->isLeaf = false; ifstream ifile(filepath); string line; vector vecBuf; @@ -36,20 +35,11 @@ namespace CppJieba LogError(msgBuf); return false; } - //PRINT_VECTOR(vecBuf); - //getchar(); string chWord = vecBuf[0]; + unsigned int count = atoi(vecBuf[1].c_str()); + const string& tag = vecBuf[2]; size_t uniLen = utf8ToUnicode(chWord.c_str(), chWord.size(), chUniBuf); - _insert(chUniBuf, uniLen); - //for(int i = 0; i < unilen; i++) - //{ - // // printf("%x\n", strbuf[i]); - //} - //char utf8str[512]={0}; - //unicodeToUtf8(strbuf, unilen, utf8str); - //cout<hmap.end() == p->hmap.find(cu)) { TrieNode * next = new TrieNode; - next->isLeaf = false; p->hmap[cu] = next; p = next; } diff --git a/Trie.h b/Trie.h index 55e065b..f4ffdf5 100644 --- a/Trie.h +++ b/Trie.h @@ -22,6 +22,13 @@ namespace CppJieba { TrieNodeHashMap hmap; bool isLeaf; + unsigned int count; + string tag; + TrieNode() + { + isLeaf = false; + count = 0; + } }; class Trie @@ -39,7 +46,7 @@ namespace CppJieba private: bool _destroyNode(TrieNode* node); void _display(TrieNode* node, int level); - bool _insert(const ChUnicode* chUniBuf, size_t len); + bool _insert(const ChUnicode* chUniBuf, size_t len, unsigned int cnt, const string& tag); }; }