Skip to content

Commit 7502470

Browse files
committed
Fix #214
1 parent dcfc32b commit 7502470

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Diff for: include/kiwi/Form.h

+22
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ namespace kiwi
166166

167167
/** 분할된 형태소의 경우 원형 형태소를 반환한다. 그 외에는 자기 자신을 반환한다. */
168168
const Morpheme* getCombined() const { return this + combined; }
169+
170+
bool hasComplex() const
171+
{
172+
if (getCombined()->complex) return true;
173+
174+
for (auto c : chunks)
175+
{
176+
if (c->complex) return true;
177+
}
178+
return false;
179+
}
180+
181+
template<class Container>
182+
bool hasMorpheme(Container&& m) const
183+
{
184+
if (m.count(getCombined())) return true;
185+
for (auto c : chunks)
186+
{
187+
if (m.count(c)) return true;
188+
}
189+
return false;
190+
}
169191
};
170192

171193
/**

Diff for: src/PathEvaluator.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ namespace kiwi
871871
{
872872
for (auto& curMorph : cands)
873873
{
874-
if (splitComplex && curMorph->getCombined()->complex) continue;
875-
if (blocklist && blocklist->count(curMorph->getCombined())) continue;
874+
if (splitComplex && curMorph->hasComplex()) continue;
875+
if (blocklist && curMorph->hasMorpheme(*blocklist)) continue;
876876

877877
// 덧붙은 받침(zCoda)을 위한 지름길
878878
if (curMorph->tag == POSTag::z_coda)

Diff for: test/test_cpp.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ TEST(KiwiCpp, SplitComplex)
187187
EXPECT_EQ(res2.first[0].str, u"감사");
188188
}
189189
}
190+
191+
{
192+
auto testCases = {
193+
u"집에 갔어요",
194+
u"집에 가요",
195+
};
196+
for (auto s : testCases)
197+
{
198+
auto res1 = kiwi.analyze(s, Match::allWithNormalizing);
199+
auto res2 = kiwi.analyze(s, Match::allWithNormalizing | Match::splitComplex);
200+
EXPECT_EQ(res1.first[res1.first.size() - 1].str, u"어요");
201+
EXPECT_EQ(res2.first[res2.first.size() - 1].str, u"");
202+
}
203+
}
190204
}
191205

192206
TEST(KiwiCpp, OldHangul)

0 commit comments

Comments
 (0)