From a3e0db22e8739fa9fd0f3a20c0f0943a9fdaae69 Mon Sep 17 00:00:00 2001 From: wyy Date: Tue, 8 Apr 2014 19:59:02 +0800 Subject: [PATCH] change trie.find args --- src/FullSegment.hpp | 2 +- src/MPSegment.hpp | 2 +- src/Trie.hpp | 8 +------- test/unittest/TTrie.cpp | 6 +++--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/FullSegment.hpp b/src/FullSegment.hpp index 2f6d403..ec97067 100644 --- a/src/FullSegment.hpp +++ b/src/FullSegment.hpp @@ -61,7 +61,7 @@ namespace CppJieba for (Unicode::const_iterator uItr = begin; uItr != end; uItr++) { //find word start from uItr - if (_trie.find(uItr, end, 0, tRes)) + if (_trie.find(uItr, end, tRes, 0)) { for(DagType::const_iterator itr = tRes.begin(); itr != tRes.end(); itr++) //for (vector >::const_iterator itr = tRes.begin(); itr != tRes.end(); itr++) diff --git a/src/MPSegment.hpp b/src/MPSegment.hpp index 5220571..c1c351b 100644 --- a/src/MPSegment.hpp +++ b/src/MPSegment.hpp @@ -122,7 +122,7 @@ namespace CppJieba { SegmentChar schar(*it); size_t i = it - begin; - _trie.find(it, end, i, schar.dag); + _trie.find(it, end, schar.dag, i); //DagType::iterator dagIter; if(schar.dag.end() == schar.dag.find(i)) { diff --git a/src/Trie.hpp b/src/Trie.hpp index 36400cf..463dcd8 100644 --- a/src/Trie.hpp +++ b/src/Trie.hpp @@ -42,12 +42,6 @@ namespace CppJieba size_t freq; string tag; double logFreq; //logFreq = log(freq/sum(freq)); - TrieNodeInfo():freq(0),logFreq(0.0) - {} - TrieNodeInfo(const TrieNodeInfo& nodeInfo):word(nodeInfo.word), freq(nodeInfo.freq), tag(nodeInfo.tag), logFreq(nodeInfo.logFreq) - {} - TrieNodeInfo(const Unicode& _word):word(_word),freq(0),logFreq(MIN_DOUBLE) - {} }; inline ostream& operator << (ostream& os, const TrieNodeInfo & nodeInfo) @@ -118,7 +112,7 @@ namespace CppJieba return NULL; } - bool find(Unicode::const_iterator begin, Unicode::const_iterator end, size_t offset, DagType & res) const + bool find(Unicode::const_iterator begin, Unicode::const_iterator end, DagType & res, size_t offset = 0) const { TrieNode* p = _root; TrieNodeMap::const_iterator citer; diff --git a/test/unittest/TTrie.cpp b/test/unittest/TTrie.cpp index 166f46e..1d9fdee 100644 --- a/test/unittest/TTrie.cpp +++ b/test/unittest/TTrie.cpp @@ -26,7 +26,7 @@ TEST(TrieTest, Test1) word = "清华大学"; vector > res; map resMap; - map map; + map mp; const char * words[] = {"清", "清华", "清华大学"}; for(size_t i = 0; i < sizeof(words)/sizeof(words[0]); i++) { @@ -40,8 +40,8 @@ TEST(TrieTest, Test1) vector > vec; ASSERT_TRUE(TransCode::decode(word, uni)); //print(uni); - ASSERT_TRUE(trie.find(uni.begin(), uni.end(), 0, map)); - ASSERT_EQ(map, resMap); + ASSERT_TRUE(trie.find(uni.begin(), uni.end(), mp, 0)); + ASSERT_EQ(mp, resMap); // print(vec); }