Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

KLAY - Korean Language AnalYzer (한국어 형태소 분석기)

License

NotificationsYou must be signed in to change notification settings

ks-shim/klay

Repository files navigation

Build StatusCoverage Status

KoreanLanguageAnalYzer using KOMORAN's dictionaries.

  • korean morphology analysis
  • 한국어 형태소 분석기 입니다.
  • 목표
    • 좀 더 빠른 분석 속도
    • 좀 더 자바스럽게 ...
    • 품질 유지 (추후 품질 개선 계획)
  • 개발 시작일 : 2019. 02 ~
    • version : 0.1 (2019.02.26)
    • version : 0.3 (2019.03.18)
    • version : 0.3.2 (2022.01.18)
    • version : 0.3.6 (2022.09.07) <-- current
  • KOMORAN의 사전을 기반으로 분석하며, 사용하는 Data structure와 분석 방식은 상이합니다.
  • Data Structure : KLAY의 분석 방식에 맞게 수정한 Lucene의 Trie를 사용합니다.
  • KLAY is a thread-safe analyzer. (멀티 쓰레드 환경에서의 사용을 권장합니다.)

2. Architecture

Performance와 동시에 확장성을 고려하였으며 Readability에 많은 신경을 썼습니다. 그래서 조금 더 자바(Java)스럽게 Design하였습니다.

2-1. Tokenization

Chain of Responsibiility 패턴을 사용하여 구현하였습니다. ChainedTokenizationRule 인터페이스를 구현하여 Rule을 쉽게추가할 수 있습니다. 현재는 아래와 같은 Rule을 순차적으로 적용하고 있습니다.

  • UserDictionaryMatchRule : 사용자 사전에 매칭하는 Rule
  • CharacterTypeAndLengthLimitRule : 문자타입 및 길이 제한 Rule

tokenization_diagram

2-2. Analysis

마찬가지로 Chain of Responsibility 패턴을 사용하여 구현하였습니다. ChainedAnalysisRule 인터페이스를 구현하여 Rule을 쉽게추가할 수 있습니다. 현재는 아래와 같은 Rule을 순차적으로 적용하고 있습니다.

  • CanSkipRule : 분석없이 생략할 수 있는 Rule
  • FWDRule : 기분석 사전으로 Fully 매칭하는 Rule
  • AllPossibleCandidateRule : 미등록어 추정 Rule
  • NARule : 분석 불가 Rule

HMM(Viterbi)는 MorphSequence 클래스를 사용하여 계산되어집니다.

analysis_diagram

2-3. Dictionary

Lucene의 Trie를 변형하여 적용하였습니다.

dictionary_diagram

3. Example

//***********************************************************************// 1. configuration and creating Klay object ...//***********************************************************************Klayklay =newKlay(Paths.get("data/configuration/klay.conf"));//***********************************************************************// 2. start morphological analysis.//***********************************************************************Stringtext ="너무기대안하고갔나....................재밌게봤다";Morphsmorphs =klay.doKlay(text);//***********************************************************************// 3. print result.//***********************************************************************Iterator<Morph>iter =morphs.iterator();while(iter.hasNext()) {System.out.println(iter.next());    }

4. Performance

4-1. 사양 및 데이터

  • 프로세서 : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz, 4008Mhz, 4코어, 8 논리 프로세서
  • 메모리 : 32.0 GB
  • 분석 데이터 위치 : data/performance/test.txt
  • 분석 데이터 건수 : 199,992 건

4-2. 결과 및 코드

  • 사전 로딩 : 0.284 (s)
  • 분석 시간 : 16.815 (s)
Stringsrc ="data/performance/test.txt";Klayklay =newKlay(Paths.get("data/configuration/klay.conf"));StopWatchwatch =newStopWatch();watch.start();intcount =0;try (BufferedReaderin =newBufferedReader(newFileReader(src))) {Stringline =null;while((line =in.readLine()) !=null) {line =line.trim();if(line.isEmpty())continue;klay.doKlay(line);System.out.print("\r" + ++count);        }    }watch.stop();System.out.println("Analysis Time : " +watch.getTime(TimeUnit.MILLISECONDS) /1000.0 +" (s)");

5. Elasticsearch Plugin Download

6. Resources Download

7. KLAY for python

8. Maven

<dependency>  <groupId>io.github.ks-shim.klay</groupId>  <artifactId>klay-common</artifactId>  <version>0.3.8</version></dependency>
<dependency>  <groupId>io.github.ks-shim.klay</groupId>  <artifactId>klay-dictionary</artifactId>  <version>0.3.8</version></dependency>
<dependency>  <groupId>io.github.ks-shim.klay</groupId>  <artifactId>klay-core</artifactId>  <version>0.3.8</version></dependency>
<repositories>  <repository>      <id>oos</id>      <url>https://s01.oss.sonatype.org/content/groups/public/</url>  </repository></repositories>

9. Dictionary build

  • dictionary-build 모듈 : klay.dictionary.build.DictionaryBuilder 실행
publicstaticvoidmain(String[]args)throwsException {// 1. 사전에 환경설정 파일의 Raw 사전 정보를 변경합니다.Propertiesconfig =newProperties();config.load(Files.newInputStream(Paths.get("data/configuration/klay.conf")));// 2. 관측확률/전이확률에 사용한 pos-frequency 정보를 읽어들입니다.DictionaryTextSourceposFreqSource =newDictionaryTextSource(Paths.get(config.getProperty("dictionary.grammar.path")));// 3. 관측확률 사전의 소스/타겟 정보를 생성합니다.DictionaryTextSource[]emissionSources = {// *** must build DIC_WORD first !!newDictionaryTextSource(Paths.get(config.getProperty("dictionary.word.path")),DictionaryTextSource.DictionaryType.DIC_WORD),newDictionaryTextSource(Paths.get(config.getProperty("dictionary.irregular.path")),DictionaryTextSource.DictionaryType.DIC_IRREGULAR)    };DictionaryBinaryTargetemissionTarget =newDictionaryBinaryTarget(Paths.get(config.getProperty("dictionary.emission.path")));// 4. 전이확률 사전의 소스/타켓 정보를 생성합니다.DictionaryTextSourcetransitionSource =newDictionaryTextSource(Paths.get(config.getProperty("dictionary.grammar.path")),DictionaryTextSource.DictionaryType.GRAMMAR);DictionaryBinaryTargettransitionTarget =newDictionaryBinaryTarget(Paths.get(config.getProperty("dictionary.transition.path")));// 5. 빌더를 생성하고 빌딩을 시작합니다.DictionaryBuilderbuilder =newDictionaryBuilder.Builder()            .posFreqSource(posFreqSource)            .emissionSourcesAndTarget(emissionSources,emissionTarget)            .transitionSourceAndTarget(transitionSource,transitionTarget)            .build();builder.buildAll();}

About

KLAY - Korean Language AnalYzer (한국어 형태소 분석기)

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp