add THMMSegment.cpp and TMPSegment.cpp for fix little error in using hmmsegment and mpsegment.

This commit is contained in:
wyy 2013-12-18 22:42:46 -08:00
parent 9f35b82dd1
commit 335a7eff47
5 changed files with 40 additions and 1 deletions

View File

@ -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())

View File

@ -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());

View File

@ -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)

View 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])));
}

View 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])));
}