gohangul

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MIT Imports: 3 Imported by: 0

README

Go Reference codecov

gohangul

gohangul은 한글을 처리하는 Go 패키지입니다.

한글을 초성, 중성, 종성으로 분리하거나 초성, 중성, 종성을 합쳐 문자로 만들 수 있습니다.

구조

Jamo (자모)
  • 기본적으로 rune 타입으로 처리합니다.
type Jamo rune
Eumjeol (음절)
  • 초성, 중성, 종성을 Jamo로 하여 음절로 표현합니다.
type Eumjeol struct {
	Choseong  Jamo
	Jungseong Jamo
	Jongseong Jamo
}
Daneo (단어)
  • 음절의 집합체로 단어를 표현합니다.
type Daneo []Eumjeol

사용법

  • 테스트 코드에 모든 예시가 포함되어있습니다.
문자열 분리
package main

import (
	"fmt"

	"github.com/yms2772/gohangul"
)

func main() {
	item := gohangul.Disassemble("안녕하세요")

	fmt.Println(item.At(0).Choseong)  // ㅇ
	fmt.Println(item.At(0).Jungseong) // ㅏ
	fmt.Println(item.At(0).Jongseong) // ㄴ
	fmt.Println(item.String())        // ㅇㅏㄴㄴㅕㅇㅎㅏㅅㅓㅣㅇㅛ
	fmt.Println(item.Assemble())      // 안녕하세요
}

문자열 병합
package main

import (
	"fmt"

	"github.com/yms2772/gohangul"
)

func main() {
	item := gohangul.Assemble("ㅇㅏㄴㄴㅕㅇㅎㅏㅅㅓㅣㅇㅛ")

	fmt.Println(item) // 안녕하세요
}

조사 구분
package main

import (
	"fmt"

	"github.com/yms2772/gohangul"
)

func main() {
	item := gohangul.Josa("생각", "을/를")

	fmt.Println(item) // 생각을
}
로마자 변환
package main

import (
	"fmt"

	"github.com/yms2772/gohangul"
)

func main() {
	item := gohangul.Romanize("안녕하세요")

	fmt.Println(item) // annyeonghaseyo
}

벤치마크

BenchmarkDisassemble
BenchmarkDisassemble-10         	 8318858	       127.8 ns/op
BenchmarkAssemble
BenchmarkAssemble-10            	 7490484	       158.3 ns/op
BenchmarkRomanize
BenchmarkRomanize-10            	 3312685	       363.4 ns/op
BenchmarkCanBeChoseong
BenchmarkCanBeChoseong-10       	50878087	        23.46 ns/op
BenchmarkCanBeJungseong
BenchmarkCanBeJungseong-10      	42416503	        28.31 ns/op
BenchmarkCanBeJongseong
BenchmarkCanBeJongseong-10      	34962742	        34.45 ns/op
BenchmarkCombineCharacter
BenchmarkCombineCharacter-10    	 9039068	       133.4 ns/op
BenchmarkCombineVowels
BenchmarkCombineVowels-10       	60781804	        19.79 ns/op
BenchmarkDays
BenchmarkDays-10                	1000000000	         0.3196 ns/op
BenchmarkGetChoseong
BenchmarkGetChoseong-10         	11115223	       108.2 ns/op
BenchmarkHasBatchim
BenchmarkHasBatchim-10          	193764027	         6.183 ns/op
BenchmarkJosa
BenchmarkJosa-10                	61659937	        19.47 ns/op
BenchmarkJosaPick
BenchmarkJosaPick-10            	148084624	         8.089 ns/op
BenchmarkNumberToHangul
BenchmarkNumberToHangul-10      	 5481848	       218.8 ns/op
BenchmarkWeekday
BenchmarkWeekday-10             	1000000000	         0.3200 ns/op

라이센스

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assemble

func Assemble(str string) string

Assemble 문자열을 받아서 적절하게 합쳐서 반환합니다.

func CanBeChoseong

func CanBeChoseong(character string) bool

CanBeChoseong 문자열이 초성으로 사용될 수 있는지 판단합니다.

func CanBeJongseong

func CanBeJongseong(character string) bool

CanBeJongseong 문자열이 종성으로 사용될 수 있는지 판단합니다.

func CanBeJungseong

func CanBeJungseong(character string) bool

CanBeJungseong 문자열이 중성으로 사용될 수 있는지 판단합니다.

func CombineCharacter

func CombineCharacter(choseong, jungseong string, jongseong ...string) string

CombineCharacter 초성, 중성, 종성을 합쳐 반환합니다.

func CombineVowels

func CombineVowels(vowel1, vowel2 string) string

CombineVowels 두 모음을 합쳐 반환합니다.

func Days

func Days(day int) string

Days 일자를 한글로 변환합니다.

func GetChoseong

func GetChoseong(word string) string

GetChoseong 문자열을 받아서 초성 단위로 분리하여 반환합니다.

func HasBatchim

func HasBatchim(str string, onlyDouble ...bool) bool

HasBatchim 받침이 있는지 판단합니다.

func Josa

func Josa(word, josaType string) string

Josa 단어와 조사를 받아 적절한 조사를 붙여 반환합니다. 지원하는 조사: 이/가, 을/를, 은/는, 으로/로, 와/과, 이나/나, 이란/란, 아/야, 이랑/랑, 이에요/예요, 으로서/로서, 으로써/로써, 으로부터/로부터, 이라/라

func JosaPick

func JosaPick(word, josaType string) string

JosaPick 단어와 조사를 받아 적절한 조사를 반환합니다. 지원하는 조사: 이/가, 을/를, 은/는, 으로/로, 와/과, 이나/나, 이란/란, 아/야, 이랑/랑, 이에요/예요, 으로서/로서, 으로써/로써, 으로부터/로부터, 이라/라

func NumberToHangul

func NumberToHangul(number string) string

NumberToHangul 숫자를 한글로 변환합니다.

func Romanize

func Romanize(str string) string

Romanize 로마자로 변환합니다.

func Weekday

func Weekday(weekday time.Weekday, full ...bool) string

Weekday 요일을 한글로 변환합니다.

Types

type Daneo

type Daneo []Eumjeol

Daneo 단어: 음절의 집합

func Disassemble

func Disassemble(str string) Daneo

Disassemble 문자열을 받아서 분해하여 Daneo 로 반환합니다.

func (Daneo) Assemble

func (d Daneo) Assemble() string

Assemble 단어를 조합합니다.

func (Daneo) At

func (d Daneo) At(i int) Eumjeol

At 단어에서 i번째 음절을 가져옵니다.

func (Daneo) Each

func (d Daneo) Each(f func(int, Eumjeol))

Each 단어의 각 음절에 대해 함수를 실행합니다.

func (Daneo) Equals

func (d Daneo) Equals(target Daneo) bool

Equals 단어가 같은지 확인합니다.

func (Daneo) GetChoseong

func (d Daneo) GetChoseong() string

GetChoseong 단어에서 초성만 분리합니다.

func (Daneo) String

func (d Daneo) String() string

String 단어를 문자열로 변환합니다.

type Eumjeol

type Eumjeol struct {
	Choseong  Jamo
	Jungseong Jamo
	Jongseong Jamo
}

Eumjeol 초성, 중성, 종성으로 이루어진 음절

func (Eumjeol) Empty

func (e Eumjeol) Empty() bool

Empty 음절이 비어있는지 확인합니다.

func (Eumjeol) Equals

func (e Eumjeol) Equals(target Eumjeol) bool

Equals 음절이 같은지 확인합니다.

func (Eumjeol) String

func (e Eumjeol) String() string

String 음절을 합쳐서 한글 문자로 반환합니다.

type Jamo

type Jamo rune

Jamo 한글 자모

func (Jamo) Empty

func (j Jamo) Empty() bool

Empty 자모가 비어있는지 확인합니다.

func (Jamo) Equals

func (j Jamo) Equals(target Jamo) bool

Equals 자모가 같은지 확인합니다.

func (Jamo) IsHangul added in v1.0.2

func (j Jamo) IsHangul() bool

IsHangul 한글인지 확인합니다.

func (Jamo) String

func (j Jamo) String() string

String 자모를 문자열로 변환합니다.

Jump to

Keyboard shortcuts

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