mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
去除 PosTagger 构造函数里一些暂时无用的参数,和增加 PosTagger 的单元测试。
This commit is contained in:
parent
da1b9e0c1c
commit
28246fba5d
@ -17,13 +17,16 @@ namespace CppJieba
|
||||
|
||||
public:
|
||||
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(){};
|
||||
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(_segment.init(dictPath, hmmFilePath));
|
||||
|
@ -3,7 +3,7 @@ using namespace CppJieba;
|
||||
|
||||
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,迎娶白富美,走上人生巅峰。");
|
||||
vector<pair<string, string> > res;
|
||||
tagger.tag(s, res);
|
||||
|
@ -16,7 +16,13 @@ ADD_LIBRARY(gtest STATIC ${GTEST_ROOT_DIR}/src/gtest-all.cc)
|
||||
#ADD_EXECUTABLE(keyword.test gtest_main.cpp TKeywordExtractor.cpp)
|
||||
#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(test.run gtest pthread)
|
||||
|
||||
|
17
test/unittest/TPosTagger.cpp
Normal file
17
test/unittest/TPosTagger.cpp
Normal 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user