728x90
형태소 분석 시에 내가 원하는 단어를 모두 쪼개놓아 합성어나 외래어 같은 경우 인지를 잘 못하는 경우가 있다.
또한 사내에서 사용하는 용어등은 표준어가 아니이게 이에 대한 처리가 필요하다.
고것을 지금 해 볼 것 이다.
우선
사용자 사전을 의미하는 user_dic 텍스트 파일과
동의어를 정의하는 synonyms 텍스트 파일을 설정한다.
이는 로컬에서 텍스트 파일을 생성해주면 된당.
docker cp D:\Project\OpenSearch\synonyms.txt container_id:/usr/share/opensearch/config
docker cp D:\Project\OpenSearch\user_dic.txt container_id:/usr/share/opensearch/config
docker cp 로컬생성파일경로 container_id:(docker container 내부 경로)
위의 명령어를 사용하여 container_id를 갖는 docker에 원하는 파일을 복사한다.
해당 경로에 파일이 복사 된 것을 확인할 수 있다.
OpenSearch DashBoard의 Dev Tool에서
PUT test0
{
"settings": {
"analysis": {
"tokenizer": {
"nori_user_dict": {
"type": "nori_tokenizer",
"decompound_mode": "mixed",
"user_dictionary": "user_dic.txt"
}
},
"analyzer": {
"korean_analyzer": {
"filter": [
"synonym","lowercase","remove_duplicates"
],
"tokenizer": "nori_user_dict"
}
},
"filter": {
"synonym" : {
"type" : "synonym_graph",
"synonyms_path" : "synonyms.txt"
},
"pos_filter_speech": {
"type": "nori_part_of_speech",
"stoptags": [
"E", "J", "SC", "SE", "SF", "SP", "SSC", "SSO", "SY", "VCN", "VCP",
"VSV", "VX", "XPN", "XSA", "XSN", "XSV"
]
}
}
}
}
}
Test0라는 인덱스를 생성한다.
인덱스 생성 시 사용한 filter들은 다음 포스트에서 다루도록 하겠다.
생성된 Test0이라는 인덱스를 가지고 테스팅을 해보자
POST test1/_analyze
{
"analyzer":"korean_analyzer",
"text":"신예찬, 8살 연하 어떤데."
}
냅다 고백을 갈겨주면
{
"tokens": [
{
"token": "신",
"start_offset": 0,
"end_offset": 3,
"type": "SYNONYM",
"position": 0
},
{
"token": "신예찬",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 0,
"positionLength": 2
},
{
"token": "핑퐁",
"start_offset": 0,
"end_offset": 3,
"type": "SYNONYM",
"position": 1
},
{
"token": "8",
"start_offset": 5,
"end_offset": 6,
"type": "word",
"position": 2
},
{
"token": "살",
"start_offset": 6,
"end_offset": 7,
"type": "word",
"position": 3
},
{
"token": "연하",
"start_offset": 8,
"end_offset": 10,
"type": "word",
"position": 4
},
{
"token": "어떤데",
"start_offset": 11,
"end_offset": 14,
"type": "word",
"position": 5,
"positionLength": 2
},
{
"token": "어떻",
"start_offset": 11,
"end_offset": 14,
"type": "word",
"position": 5
},
{
"token": "ㄴ데",
"start_offset": 11,
"end_offset": 14,
"type": "word",
"position": 6
}
]
}
야무지게 결과가 도출된다.
야호
2023년 12월 5일 밴드 LUCY의 싱글 앨범 Boogie Man 많관부.
728x90