KOMORAN (KOrean MORphological ANalyzer)

repository·master·Indexed 43 days ago

https://github.com/shineware/komoran

A lightweight, pure-Java Korean morphological analyzer designed for high performance and ease of integration. It features zero external dependencies, whitespace-aware analysis, and a small memory footprint (approx. 50MB). The library includes the Komoran core API for POS tagging, CorpusBuilder for model generation, and a dedicated Admin Tool for managing custom user dictionaries and models.

Tokens
12.8K
Snippets
35
Records
56
Agent score
53%

What's inside KOMORAN

  1. Overview of KOMORAN Korean Morphological Analyzer

    master

    KOMORAN (KOrean MORphical ANalyzer) is a morphological analyzer for the Korean language developed in Java. It is designed to be lightweight, easy to use, and highly portable.

    Key Features

    • Pure Java: Since it is 100% Java, it can be used in any environment where Java is installed.
    • Zero External Dependencies: It uses only internally developed libraries, avoiding dependency conflicts with other external libraries.
    • Lightweight: It can operate with approximately 50MB of memory thanks to its use of TRIE dictionaries and character-unit processing.
    • Easy to Use: Once the library is integrated, the analyzer can be invoked with a single line of code.
    • Easy Dictionary Management: Dictionaries are composed of plain text files, making them highly readable and easy to edit.
    • Advanced Analysis Results: Unlike other morphological analyzers, KOMORAN can perform analysis on morpheme units that include whitespace.
  2. Overview of KOMORAN Admin Tool

    master

    The KOMORAN Admin Tool is a management utility designed to assist users of the KOMORAN Korean Morphological Analyzer. It provides a graphical interface to manage the dictionaries required to build custom user models and provides guidance on how to apply those models to the analyzer.

    Key functional areas include:

    • Analyze (분석): Perform morphological analysis using the default KOMORAN model (STABLE).
    • Correction (보정): Manage the dictionaries necessary for creating custom user models.
    • Compare (비교): Generate user models and compare the morphological analysis results between two selected models (e.g., the default model vs. a custom model).
    • Deploy (배포): Create, delete, and receive instructions on how to deploy custom user models.
  3. Overview of KOMORAN

    master

    KOMORAN is a Korean Morphological Analyzer implemented in pure Java. It is designed to be lightweight (requiring approximately 50MB of memory) and dependency-free, making it easy to integrate into any Java-based environment.

    Key capabilities include:

    • Pure Java & Dependency Free: Uses self-made libraries to avoid external dependency issues.
    • Lightweight: Uses a custom TRIE dictionary to maintain a low memory footprint.
    • Easy Dictionary Management: Dictionaries can be edited as human-readable plain text files.
    • Advanced Analysis: Supports analyzing morpheme units that contain spaces, which distinguishes it from other analyzers.
  4. Overview of KOMORAN 3.0

    master

    KOMORAN (KOrean MORphological ANalyzer) is a Korean morphological analyzer implemented entirely in Java. It is designed to be lightweight, easy to use, and independent of external libraries.

    Key Features:

    • Pure Java Implementation: Works in any environment with a Java Runtime Environment (JRE).
    • Zero External Dependencies: Uses only internally developed libraries to avoid dependency conflicts.
    • Lightweight: Capable of operating with approximately 50MB of memory using Trie dictionaries and character-unit processing.
    • Ease of Use: Can be integrated into source code with minimal effort (typically a single line of code after library application).
    • Easy Dictionary Management: Dictionaries are stored as highly readable plain text files for easy editing.
    • Advanced Analysis: Supports morphological analysis that includes whitespace-separated units, distinguishing it from other analyzers.
  5. Use CorpusBuilder to generate Komoran models

    master

    The CorpusBuilder class is used to generate the necessary data components for creating a Komoran model from a corpus. The generated data includes:

    • Word dictionary (dic.word)
    • Grammar (grammar.in)
    • Full word-phrase dictionary
    • Irregular dictionary (dic.irregular)

    You can use this class to incorporate user dictionaries and build the model files into a specified directory.

  6. Choose between STABLE and EXP morphological analysis models

    master

    KOMORAN provides two pre-trained Part-of-Speech (POS) tagging models. Starting from version 3.4, the previous FULL and LIGHT models have been renamed to STABLE and EXP respectively.

    STABLE Model

    • Training Data: Trained on a subset of the Sejong Corpus and additional collected data.
    • Best Use Case: General-purpose use for everyday sentences across various domains.
    • Recommendation: Use this model for most applications, especially if the morphological analysis results are exposed directly to end-users in a service.
    • Maintenance: This model is continuously managed by SHINEWARE.

    EXP Model

    • Training Data: Built upon the STABLE model's training data, with additional nouns extracted from Wikipedia titles.
    • Best Use Case: Domains where neologisms (newly coined words) and proper nouns are critical, such as news classification or SNS (social media) data analysis.
    • Caution: Nouns extracted from Wikipedia titles have not been verified and may contain inaccuracies.
  7. Understand KOMORAN Model Directory Structure

    master

    Models are stored in the models/ directory under the project root. Each subdirectory represents a single model, named after its creation timestamp. A model directory contains the following structure:

    • corpus_build/: Base data used to generate user models.
      • dic.irregular: Irregular dictionary.
      • dic.word: Word frequency dictionary.
      • grammar.in: PoS frequency dictionary.
    • dic.user: User word dictionary.
    • fwd.user: Pre-analyzed dictionary.
    • model/: The generated user model containing:
      • irregular.model
      • observation.model
      • pos.table
      • transition.model
    .
    ├── corpus_build        # 사용자 모델을 생성하기 위한 기초 데이터
    │   ├── dic.irregular   # 불규칙 사전
    │   ├── dic.word        # 단어 빈도 사전
    │   └── grammar.in      # 품사 빈도 사전
    ├── dic.user            # 사용자 단어 사전
    ├── fwd.user            # 기분석 사전
    └── model               # 위 corpus_build/ 디렉토리 내의 데이터로 생성한 사용자 모델
        ├── irregular.model
        ├── observation.model
        ├── pos.table
        └── transition.model
  8. Build the KOMORAN documentation static site

    master

    The KOMORAN documentation is managed as a static site using Sphinx and reStructuredText (reST). To build the documentation locally after making changes to the .rst files, use the following commands based on your operating system.

    Prerequisites:

    • Python 3.x or higher
    • pip
    • Dependencies installed via pip install -r requirements.txt

    Build Commands:

    • Unix/Linux/macOS: Use make html.
    • Windows: Use sphinx-build . _build.

    The generated HTML files will be located in the _build/html directory.

    # Unix/Linux/macOS
    make html
    
    # Windows
    sphinx-build . _build
  9. Perform morphological analysis in Java without Gradle or Maven

    master

    If you are not using a build tool like Gradle or Maven, you can use KOMORAN by manually adding the JAR file to your classpath.

    Project Structure

    Ensure your project is organized as follows:

    .
    ├── App.java
    └── libs
        └── KOMORAN-3.3.9.jar

    1. Add Dependency

    Create a libs directory and place the KOMORAN-3.3.9.jar file inside it.

    2. Implement Analysis

    Use the Komoran class to perform analysis. You must initialize it with a model type (e.g., DEFAULT_MODEL.EXPERIMENT). The analyze() method returns a KomoranResult object, which provides access to the tagged plain text and a list of Token objects.

    3. Compile and Run

    To compile App.java with the KOMORAN JAR in the classpath:

    javac -cp "./libs/KOMORAN-3.3.9.jar:" App.java

    To run the compiled class:

    java -cp ".:./libs/KOMORAN-3.3.9.jar:" App
    import kr.co.shineware.nlp.komoran.constant.DEFAULT_MODEL;
    import kr.co.shineware.nlp.komoran.core.Komoran;
    import kr.co.shineware.nlp.komoran.model.KomoranResult;
    import kr.co.shineware.nlp.komoran.model.Token;
    
    import java.util.List;
    
    public class App {
      public static void main(String[] args){
        Komoran komoran = new Komoran(DEFAULT_MODEL.EXPERIMENT);
        String strToAnalyze = "대한민국은 민주공화국이다.";
    
        KomoranResult analyzeResultList = komoran.analyze(strToAnalyze);
    
        System.out.println(analyzeResultList.getPlainText());
    
        List<Token> tokenList = analyzeResultList.getTokenList();
        for (Token token : tokenList) {
            System.out.format("(%2d, %2d) %s/%s\n", token.getBeginIndex(), token.getEndIndex(), token.getMorph(), token.getPos());
        }
      }
    }
  10. Add KOMORAN dependency using Gradle

    master

    To use KOMORAN in a Gradle project, add the JitPack repository and the KOMORAN implementation dependency to your build.gradle file.

    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    
    dependencies {
        implementation 'com.github.shin285:KOMORAN:3.3.9'
    }
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    
    dependencies {
        implementation 'com.github.shin285:KOMORAN:3.3.9'
    }