Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이용자 사전 기능 강화 #37

Closed
bab2min opened this issue Sep 4, 2021 · 2 comments
Closed

이용자 사전 기능 강화 #37

bab2min opened this issue Sep 4, 2021 · 2 comments

Comments

@bab2min
Copy link
Owner

bab2min commented Sep 4, 2021

기능 설명

현재 이용자 사전에는 형태소 1개짜리 단어만 등록이 가능하다. 공백을 포함하는 여러 단어를 추가하거나 특정 패턴의 분석 방법을 설정해 등록할 수 있도록 하면 유용할듯.

여러 단어로 구성된 엔트리 등록

복합 명사 : 복합_명사/NNP

복합 명사 혹은 복합명사라는 표현을 만나면 복합_명사/NNP로 분석할 수 있도록 단어를 추가한다

이 기능은 형태소 Trie를 탐색시 공백으로 분리된 토큰을 한 덩어리로 묶어서 처리하는 기능이 지원되어야 개발 가능함.

기분석된 패턴 등록

튕겼 : 튕기다/VV + 었/EP

튕겼을 만나면 튕기다/VV + 었/EP으로 분석할 수 있도록 사전에 표층형-실질형을 등록한다.

이미 내부 사전에는 chunks라는 이름으로 여러 형태소를 한 덩어리로 묶고 이에 고유한 Form을 배정하는 기능이 등록되어 있음. 이 기능을 이용자 사전에서도 접근가능하도록 수정하면 될 것으로 보임.

Kiwi/include/kiwi/Form.h

Lines 10 to 20 in 844474e

template<bool baked>
struct MorphemeT
{
typename std::conditional<baked, const KString*, uint32_t>::type kform = 0;
POSTag tag = POSTag::unknown;
CondVowel vowel = CondVowel::none;
CondPolarity polar = CondPolarity::none;
uint8_t combineSocket = 0;
typename std::conditional<baked, FixedVector<const Morpheme*>, std::vector<uint32_t>>::type chunks;
int32_t combined = 0;
float userScore = 0;

@bab2min
Copy link
Owner Author

bab2min commented Mar 20, 2022

기분석 패턴을 등록하는 기능은 0.11.0 버전에서 KiwiBuilder::addPreAnalyzedWord라는 함수로 구현되었습니다.
간단한 테스트 코드는 아래와 같습니다.

Kiwi/test/test_cpp.cpp

Lines 295 to 323 in 380ccd4

TEST(KiwiCpp, AddPreAnalyzedWord)
{
Kiwi& okiwi = reuseKiwiInstance();
auto ores = okiwi.analyze("팅겼어...", Match::allWithNormalizing);
KiwiBuilder builder{ MODEL_PATH };
std::vector<std::pair<std::u16string, POSTag>> analyzed;
analyzed.emplace_back(u"팅기", POSTag::vv);
analyzed.emplace_back(u"", POSTag::ep);
analyzed.emplace_back(u"", POSTag::ef);
EXPECT_THROW(builder.addPreAnalyzedWord(u"팅겼어", analyzed), UnknownMorphemeException);
builder.addWord(u"팅기", POSTag::vv);
builder.addPreAnalyzedWord(u"팅겼어", analyzed);
Kiwi kiwi = builder.build();
auto res = kiwi.analyze("팅겼어...", Match::allWithNormalizing);
ASSERT_GE(res.first.size(), 4);
EXPECT_EQ(res.first[0].str, u"팅기");
EXPECT_EQ(res.first[0].tag, POSTag::vv);
EXPECT_EQ(res.first[1].str, u"");
EXPECT_EQ(res.first[1].tag, POSTag::ep);
EXPECT_EQ(res.first[2].str, u"");
EXPECT_EQ(res.first[2].tag, POSTag::ef);
EXPECT_EQ(res.first[3].str, u"...");
EXPECT_EQ(res.first[3].tag, POSTag::sf);
}

bab2min added a commit that referenced this issue Feb 1, 2024
@bab2min
Copy link
Owner Author

bab2min commented Mar 10, 2024

0.17.0버전부터 공백을 포함한 다어절 단어를 사전에 등록할 수 있도록 개선되었습니다.

@bab2min bab2min closed this as completed Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 완료
Development

No branches or pull requests

1 participant