mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
fix bug about optional argument hmm
This commit is contained in:
parent
f517601c29
commit
8eef9a13a8
@ -34,12 +34,13 @@ class MixSegment: public SegmentBase {
|
||||
}
|
||||
|
||||
void cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res, bool hmm) const {
|
||||
if (!hmm) {
|
||||
mpSeg_.cut(begin, end, res);
|
||||
return;
|
||||
}
|
||||
vector<Unicode> words;
|
||||
words.reserve(end - begin);
|
||||
mpSeg_.cut(begin, end, words);
|
||||
if (!hmm) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<Unicode> hmmRes;
|
||||
hmmRes.reserve(end - begin);
|
||||
|
@ -12,15 +12,42 @@ using namespace CppJieba;
|
||||
|
||||
TEST(MixSegmentTest, Test1) {
|
||||
MixSegment segment("../dict/jieba.dict.utf8", "../dict/hmm_model.utf8");;
|
||||
const char* str = "我来自北京邮电大学。。。学号123456,用AK47";
|
||||
const char* res[] = {"我", "来自", "北京邮电大学", "。","。","。", "学号", "123456",",","用","AK47"};
|
||||
const char* str2 = "B超 T恤";
|
||||
const char* res2[] = {"B超"," ", "T恤"};
|
||||
string sentence;
|
||||
vector<string> words;
|
||||
segment.cut(str, words);
|
||||
ASSERT_EQ(words, vector<string>(res, res + sizeof(res)/sizeof(res[0])));
|
||||
segment.cut(str2, words);
|
||||
ASSERT_EQ(words, vector<string>(res2, res2 + sizeof(res2)/sizeof(res2[0])));
|
||||
string actual;
|
||||
string expected;
|
||||
|
||||
{
|
||||
sentence = "我来自北京邮电大学。。。学号123456,用AK47";
|
||||
expected = "我/来自/北京邮电大学/。/。/。/学号/123456/,/用/AK47";
|
||||
segment.cut(sentence, words);
|
||||
actual = join(words.begin(), words.end(), "/");
|
||||
ASSERT_EQ(actual, expected);
|
||||
}
|
||||
|
||||
{
|
||||
sentence = "B超 T恤";
|
||||
expected = "B超/ /T恤";
|
||||
segment.cut(sentence, words);
|
||||
actual = join(words.begin(), words.end(), "/");
|
||||
ASSERT_EQ(actual, expected);
|
||||
}
|
||||
|
||||
{
|
||||
sentence = "他来到了网易杭研大厦";
|
||||
expected = "他/来到/了/网易/杭/研/大厦";
|
||||
segment.cut(sentence, words, false);
|
||||
actual = join(words.begin(), words.end(), "/");
|
||||
ASSERT_EQ(actual, expected);
|
||||
}
|
||||
|
||||
{
|
||||
sentence = "他来到了网易杭研大厦";
|
||||
expected = "他/来到/了/网易/杭研/大厦";
|
||||
segment.cut(sentence, words);
|
||||
actual = join(words.begin(), words.end(), "/");
|
||||
ASSERT_EQ(actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MixSegmentTest, NoUserDict) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user