mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add THMMSegment.cpp and TMPSegment.cpp for fix little error in using hmmsegment and mpsegment.
This commit is contained in:
parent
9f35b82dd1
commit
335a7eff47
@ -10,6 +10,7 @@
|
||||
#include "TransCode.hpp"
|
||||
#include "ISegment.hpp"
|
||||
#include "SegmentBase.hpp"
|
||||
#include "Trie.hpp"
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
@ -64,6 +65,7 @@ namespace CppJieba
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
using SegmentBase::cut;
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res)const
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
|
@ -66,6 +66,7 @@ namespace CppJieba
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
using SegmentBase::cut;
|
||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
{
|
||||
assert(_getInitFlag());
|
||||
|
@ -5,7 +5,7 @@ SET(GTEST_ROOT_DIR gtest-1.6.0)
|
||||
|
||||
INCLUDE_DIRECTORIES(${GTEST_ROOT_DIR} ${GTEST_ROOT_DIR}/include ${PROJECT_SOURCE_DIR})
|
||||
ADD_LIBRARY(gtest STATIC ${GTEST_ROOT_DIR}/src/gtest-all.cc)
|
||||
ADD_EXECUTABLE(test.run gtest_main.cc TChineseFilter.cpp TMixSegment.cpp)
|
||||
ADD_EXECUTABLE(test.run gtest_main.cc TChineseFilter.cpp TMixSegment.cpp TMPSegment.cpp THMMSegment.cpp)
|
||||
TARGET_LINK_LIBRARIES(gtest pthread)
|
||||
TARGET_LINK_LIBRARIES(test.run gtest pthread)
|
||||
|
||||
|
19
test/unittest/THMMSegment.cpp
Normal file
19
test/unittest/THMMSegment.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "src/HMMSegment.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
TEST(HMMSegmentTest, Test1)
|
||||
{
|
||||
HMMSegment segment("../dicts/hmm_model.utf8");;
|
||||
const char* str = "我来自北京邮电大学。。。 学号 123456";
|
||||
const char* res[] = {"我来", "自北京", "邮电大学", "。", "。", "。", " ", "学号", " 123456"};
|
||||
//string s;
|
||||
//vector<string> buf(res, res + sizeof(res)/sizeof(res[0]));
|
||||
vector<string> words;
|
||||
ASSERT_EQ(segment.init(), true);
|
||||
ASSERT_EQ(segment.cut(str, words), true);
|
||||
//print(words);
|
||||
EXPECT_EQ(words, vector<string>(res, res + sizeof(res)/sizeof(res[0])));
|
||||
}
|
||||
|
17
test/unittest/TMPSegment.cpp
Normal file
17
test/unittest/TMPSegment.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "src/MPSegment.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
TEST(MPSegmentTest, Test1)
|
||||
{
|
||||
MPSegment segment("../dicts/jieba.dict.utf8");;
|
||||
const char* str = "我来自北京邮电大学。。。 学号 123456";
|
||||
const char* res[] = {"我", "来自", "北京邮电大学", "。","。","。"," ","学","号", " 123456"};
|
||||
vector<string> words;
|
||||
ASSERT_EQ(segment.init(), true);
|
||||
ASSERT_EQ(segment.cut(str, words), true);
|
||||
//print(words);
|
||||
EXPECT_EQ(words, vector<string>(res, res + sizeof(res)/sizeof(res[0])));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user