diff --git a/Makefile b/Makefile index f49d634..c111257 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,11 @@ $(CMLIB): $(CMDIR) #unit test Trie.ut: Trie.cpp Trie.h $(CMLIB) - g++ -o $@ $< -DTRIE_UT $(CMLIB) + $(CC) -o $@ $< -DTRIE_UT $(CMLIB) + +Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h $(CMLIB) + $(CC) -o $@ Segment.cpp Trie.cpp -DSEGMENT_UT $(CMLIB) + clean: rm -f *.o *.ut $(CMLIB) main diff --git a/Trie.cpp b/Trie.cpp index 8db90f6..0fffa2e 100644 --- a/Trie.cpp +++ b/Trie.cpp @@ -91,6 +91,24 @@ namespace CppJieba return p->isLeaf; } + bool Trie::find(const vector& uniVec) + { + TrieNode * p = _root; + for(size_t i = 0; i < uniVec.size(); i++) + { + ChUnicode chUni = uniVec[i]; + if(p->hmap.find(chUni) == p->hmap.end()) + { + return false; + } + else + { + p = p-> hmap[chUni]; + } + } + return p->isLeaf; + } + bool Trie::cut(const ChUnicode* chUniStr, size_t len, vector< vector >& res) { res.clear(); diff --git a/Trie.h b/Trie.h index 005caf7..c6097da 100644 --- a/Trie.h +++ b/Trie.h @@ -96,6 +96,7 @@ namespace CppJieba bool destroy(); void display(); bool find(const ChUnicode* chUniStr, size_t len); + bool find(const vector& uniVec); public: bool cut(const ChUnicode* chUniStr, size_t len, vector< vector >& res);