去除 PosTagger 构造函数里一些暂时无用的参数,和增加 PosTagger 的单元测试。

This commit is contained in:
wyy 2014-09-28 11:59:30 +08:00
parent da1b9e0c1c
commit 28246fba5d
4 changed files with 31 additions and 5 deletions

View File

@ -17,13 +17,16 @@ namespace CppJieba
public: public:
PosTagger(){}; PosTagger(){};
PosTagger(const string& dictPath, const string& hmmFilePath, const string& charStatus, const string& startProb, const string& emitProb, const string& endProb, const string& transProb) PosTagger(
const string& dictPath,
const string& hmmFilePath
)
{ {
LIMONP_CHECK(init(dictPath, hmmFilePath, charStatus, startProb, emitProb, endProb, transProb)); LIMONP_CHECK(init(dictPath, hmmFilePath));
}; };
~PosTagger(){}; ~PosTagger(){};
public: public:
bool init(const string& dictPath, const string& hmmFilePath, const string& charStatus, const string& startProb, const string& emitProb, const string& endProb, const string& transProb) bool init(const string& dictPath, const string& hmmFilePath)
{ {
LIMONP_CHECK(_dictTrie.init(dictPath)); LIMONP_CHECK(_dictTrie.init(dictPath));
LIMONP_CHECK(_segment.init(dictPath, hmmFilePath)); LIMONP_CHECK(_segment.init(dictPath, hmmFilePath));

View File

@ -3,7 +3,7 @@ using namespace CppJieba;
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
PosTagger tagger("../dict/jieba.dict.utf8", "../dict/hmm_model.utf8", "", "", "", "", ""); PosTagger tagger("../dict/jieba.dict.utf8", "../dict/hmm_model.utf8");
string s("我是蓝翔技工拖拉机学院手扶拖拉机专业的。不用多久我就会升职加薪当上总经理出任CEO迎娶白富美走上人生巅峰。"); string s("我是蓝翔技工拖拉机学院手扶拖拉机专业的。不用多久我就会升职加薪当上总经理出任CEO迎娶白富美走上人生巅峰。");
vector<pair<string, string> > res; vector<pair<string, string> > res;
tagger.tag(s, res); tagger.tag(s, res);

View File

@ -16,7 +16,13 @@ ADD_LIBRARY(gtest STATIC ${GTEST_ROOT_DIR}/src/gtest-all.cc)
#ADD_EXECUTABLE(keyword.test gtest_main.cpp TKeywordExtractor.cpp) #ADD_EXECUTABLE(keyword.test gtest_main.cpp TKeywordExtractor.cpp)
#TARGET_LINK_LIBRARIES(keyword.test gtest pthread) #TARGET_LINK_LIBRARIES(keyword.test gtest pthread)
ADD_EXECUTABLE(test.run gtest_main.cpp TKeywordExtractor.cpp TTrie.cpp TSegments.cpp ) ADD_EXECUTABLE(test.run
gtest_main.cpp
TKeywordExtractor.cpp
TTrie.cpp
TSegments.cpp
TPosTagger.cpp
)
TARGET_LINK_LIBRARIES(gtest pthread) TARGET_LINK_LIBRARIES(gtest pthread)
TARGET_LINK_LIBRARIES(test.run gtest pthread) TARGET_LINK_LIBRARIES(test.run gtest pthread)

View File

@ -0,0 +1,17 @@
#include "src/PosTagger.hpp"
#include "gtest/gtest.h"
using namespace CppJieba;
const char * const QUERY_TEST1 = "我是蓝翔技工拖拉机学院手扶拖拉机专业的。不用多久我就会升职加薪当上总经理出任CEO迎娶白富美走上人生巅峰。";
const char * const ANS_TEST1 = "[\"我:r\", \"是:v\", \"蓝翔:x\", \"技工:n\", \"拖拉机:n\", \"学院:n\", \"手扶拖拉机:n\", \"专业:n\", \"的:uj\", \"。:x\", \"不用:v\", \"多久:m\", \":x\", \"我:r\", \"就:d\", \"会:v\", \"升职:v\", \"加薪:nr\", \":x\", \"当上:t\", \"总经理:n\", \":x\", \"出任:v\", \"CEO:x\", \":x\", \"迎娶:v\", \"白富:x\", \"美:ns\", \":x\", \"走上:v\", \"人生:n\", \"巅峰:n\", \"。:x\"]";
TEST(PosTaggerTest, Test1)
{
PosTagger tagger("../dict/jieba.dict.utf8", "../dict/hmm_model.utf8");
vector<pair<string, string> > res;
tagger.tag(QUERY_TEST1, res);
string s;
s << res;
ASSERT_TRUE(s == ANS_TEST1);
}