forked from thunlp/THULAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include "thulac.h" | ||
#include "thulac_test.h" | ||
|
||
|
||
int main() { | ||
THULAC lac; | ||
std::string case_name; | ||
{ | ||
|
||
case_name = "检查单分词模型模型"; | ||
lac.init("/program/python/python-git/thulac/models",NULL,1); | ||
THULAC_TEST test = THULAC_TEST(&lac, case_name); | ||
test.testEqual("我爱北京天安门", "我 爱 北京 天安门"); | ||
test.testEqual("小明喜欢玩炉石传说", "小明 喜欢 玩 炉石 传说"); | ||
} | ||
|
||
{ | ||
case_name = "检查带词性标注的模型"; | ||
lac.init("/program/python/python-git/thulac/models",NULL,0); | ||
THULAC_TEST test = THULAC_TEST(&lac, case_name); | ||
test.testEqual("我爱北京天安门", "我_r 爱_v 北京_ns 天安门_ns"); | ||
test.testEqual("小明喜欢玩炉石传说", "小明_np 喜欢_v 玩_v 炉石_n 传说_n"); | ||
} | ||
|
||
{ | ||
case_name = "检查deli分隔符参数"; | ||
lac.init("/program/python/python-git/thulac/models",NULL,0, 0, 0,'#'); | ||
THULAC_TEST test = THULAC_TEST(&lac, case_name); | ||
test.testEqual("我爱北京天安门", "我#r 爱#v 北京#ns 天安门#ns"); | ||
test.testEqual("小明喜欢玩炉石传说", "小明#np 喜欢#v 玩#v 炉石#n 传说#n"); | ||
} | ||
|
||
{ | ||
case_name = "检查T2S分隔符参数"; | ||
lac.init("/program/python/python-git/thulac/models",NULL,1, 1); | ||
THULAC_TEST test = THULAC_TEST(&lac, case_name); | ||
test.testEqual("我愛北京天安門", "我 爱 北京 天安门"); | ||
test.testEqual("小明喜歡玩爐石傳說", "小明 喜欢 玩 炉石 传说"); | ||
} | ||
|
||
{ | ||
case_name = "检查ufilter参数"; | ||
lac.init("/program/python/python-git/thulac/models",NULL,1, 0, 1); | ||
THULAC_TEST test = THULAC_TEST(&lac, case_name); | ||
test.testEqual("我可以爱北京天安门", "我 爱 北京 天安门"); | ||
} | ||
|
||
|
||
THULAC_TEST::reportAll(); | ||
return 0; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <utility> | ||
#include "../include/thulac.h" | ||
class THULAC_TEST { | ||
public: | ||
void report(const std::string &s); | ||
void testEqual(const std::string &raw, const std::string &standard); | ||
THULAC_TEST(THULAC *lac); | ||
THULAC_TEST(THULAC *lac, std::string name); | ||
static void reportAll(); | ||
private: | ||
std::vector<std::string> errorMsg; | ||
THULAC *lac; | ||
std::string caseName; | ||
bool equals(const std::string &result, const std::string &standard); | ||
void report_error(const std::string &e); | ||
static std::vector<std::pair<std::string, std::string> > allErrorMsg; | ||
|
||
}; | ||
|
||
THULAC_TEST::THULAC_TEST(THULAC *lac) { | ||
this->lac = lac; | ||
|
||
|
||
} | ||
|
||
THULAC_TEST::THULAC_TEST(THULAC *lac, std::string caseName) { | ||
this->lac = lac; | ||
this->caseName = caseName; | ||
} | ||
|
||
bool THULAC_TEST::equals(const std::string &result, const std::string &standard) { | ||
return result == standard; | ||
} | ||
|
||
void THULAC_TEST::report_error(const std::string &e) { | ||
errorMsg.push_back(e); | ||
allErrorMsg.push_back(std::make_pair(caseName, e)); | ||
} | ||
|
||
void THULAC_TEST::testEqual(const std::string &raw, const std::string &standard) { | ||
THULAC_result result; | ||
lac->cut(raw, result); | ||
std::string s_result = lac->toString(result); | ||
if(equals(s_result, standard)) { | ||
std::cout << "."; | ||
return; | ||
} | ||
std::cout << "E"; | ||
std::string error = "不匹配:" + s_result + " 与 " + standard; | ||
report_error(error); | ||
return; | ||
} | ||
|
||
void THULAC_TEST::report(const std::string &s) { | ||
std::cout << std::endl << s << ":" << std::endl; | ||
if(errorMsg.size() == 0) { | ||
std::cout << "恭喜!所有case通过测试" << std::endl; | ||
} | ||
else{ | ||
for(auto i : errorMsg) { | ||
|
||
std::cout << i << std::endl; | ||
} | ||
|
||
} | ||
return; | ||
} | ||
|
||
void THULAC_TEST::reportAll() { | ||
std::cout << "\n测试结果:\n"; | ||
if(allErrorMsg.size() == 0) std::cout << "恭喜!所有case通过测试" << std::endl; | ||
else { | ||
for (auto i : allErrorMsg) { | ||
std::cout << i.first << "case中:\n" << i.second << std::endl; | ||
} | ||
} | ||
} | ||
|
||
std::vector<std::pair<std::string, std::string> > THULAC_TEST::allErrorMsg = std::vector<std::pair<std::string, std::string> >(); |