go_khaiii

package module
v0.0.0-...-f3e3636 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

go-khaiii

What is go-khaiii?

go-khaiii is khaiii (Korean Morphological Analyzer) binding for Golang.

Sample code

  • Create Model:
    • khaiii.Model.Create(rsc_dir string, opt_str string)
      • rsc_dir: a directory of dictionary resources (default: /usr/local/share/khaiii)
      • opt_str: options (JSON format)
  • Morphological Analysis:
    • khaiii.Model.ParseV1(line string)
      • (input e.g.) 나는 회사에 간다
      • (output e.g.) [[나 NP] [는 JX] [회사 NNG] [에 JKB] [가 VV] [ㄴ다 EC]]
    • khaiii.Model.Parse(line string)
      • (input e.g.) 나는 회사에 간다
      • (output e.g.) [{나 NP} {는 JX} {회사 NNG} {에 JKB} {가 VV} {ㄴ다 EC}]
    • khaiii.Model.Nouns(line string)
      • (input e.g.) 나는 백신접종을 하였다
      • (output e.g.) [백신 접종]
    • khaiii.Model.NounsComposed(line string)
      • (input e.g.) 나는 백신접종을 하였다
      • (output e.g.) [백신접종]
    • khaiii.Model.Analyze(line string)
      • (input e.g.) 나는 회사에 간다
      • (output e.g.) [{나는 [{나 NP} {는 JX}]} {회사에 [{회사 NNG} {에 JKB}]} {간다 [{가 VV} {ㄴ다 EC}]}]
  • Destroy Model:
    • khaiii.Model.Destroy()
package main

import (
	"fmt"
	khaiii "github.com/AhaOfficial/go-khaiii"
)

func main() {
	var model khaiii.Model

	err := model.Create("", "") // "": default
	if err != nil {
		fmt.Println("Create Error!")
		panic(err)
	}
	defer model.Destroy()

	var sentence string = "나는 회사에 간다"
	
	// ParseV1
	resultParseV1, err := model.ParseV1(sentence)
	if err != nil {
		fmt.Println("Parsing Error!")
		panic(err)
	}
	fmt.Println(resultParseV1)

	// Parse
	resultParse, err := model.Parse(sentence)
	if err != nil {
		fmt.Println("Parsing Error!")
		panic(err)
	}
	for _, m := range resultParse {
		fmt.Printf("(%s/%s) ", m.Lex, m.Tag)
	}
	fmt.Println()

	// Nouns
	resultNouns, err := model.Nouns(sentence)
	if err != nil {
		fmt.Println("Parsing Error!")
		panic(err)
	}
	fmt.Println(resultNouns)

	// NounsComposed
	resultNouns, err := model.NounsComposed(sentence)
	if err != nil {
		fmt.Println("Parsing Error!")
		panic(err)
	}
	fmt.Println(resultNouns)

	// Analyze
	resultAnalyze, err := model.Analyze(sentence)
	if err != nil {
		fmt.Println("Parsing Error!")
		panic(err)
	}
	for _, r := range resultAnalyze {
		fmt.Printf("%s\t", r.Word)
		for _, m := range r.Morphs {
			fmt.Printf("(%s/%s) ", m.Lex, m.Tag)
		}
		fmt.Println()
	}
}

Install

Before using go-khaiii, need to install khaiii.

Here is how to install go-khaiii with khaiii depending on OS (MacOS, Ubuntu 20.04, and Amazon Linux).

There are also dockerfiles with go-khaiii installed (Ubuntu 20.04 and Amazon Linux).

MacOS
$ brew install git cmake go

# Download go-khaiii
$ git clone https://github.com/AhaOfficial/go-khaiii.git

# Install khaiii
$ cd go-khaiii
$ sudo bash install_khaiii.sh

# Export variables
$ go get github.com/AhaOfficial/go-khaiii
Ubuntu 20.04 (Focal Fossa)
$ sudo apt-get install -y git cmake golang-go language-pack-ko

# Download go-khaiii
$ git clone https://github.com/AhaOfficial/go-khaiii.git

# Install khaiii
$ cd go-khaiii
$ sudo bash install_khaiii.sh

# Export variables
$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
$ go get github.com/AhaOfficial/go-khaiii
Amazon Linux
$ yum install -y git golang gcc-c++ wget tar make python3 cmake3
$ ln -sf /usr/bin/cmake3 /usr/bin/cmake

# Download go-khaiii
$ git clone https://github.com/AhaOfficial/go-khaiii.git

# Install khaiii
$ cd go-khaiii
$ bash install_khaiii.sh

# Export variables
$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
$ go get github.com/AhaOfficial/go-khaiii

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

func (*Model) Analyze

func (m *Model) Analyze(sentence string) ([]Word, error)

func (*Model) Create

func (m *Model) Create(rsc_dir string, opt_str string) error

func (*Model) Destroy

func (m *Model) Destroy()

func (*Model) Nouns

func (m *Model) Nouns(sentence string) ([]string, error)

func (*Model) NounsComposed

func (m *Model) NounsComposed(sentence string) ([]string, error)

func (*Model) Parse

func (m *Model) Parse(sentence string) ([]Morph, error)

func (*Model) ParseV1

func (m *Model) ParseV1(sentence string) ([][]string, error)

type Morph

type Morph struct {
	Lex string
	Tag string
}

type Word

type Word struct {
	Word   string
	Morphs []Morph
}

type WordC

type WordC struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL