phrase

package
v0.40.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: Apache-2.0 Imports: 5 Imported by: 4

README

Usage

package main

import (
	"fmt"

	"github.com/go-ego/gse"
	"github.com/go-ego/gpy"
	"github.com/go-ego/gpy/phrase"
)

var test = `那里湖面总是澄清, 那里空气充满宁静; 西雅图都会区`

func main() {
	args := gpy.Args{
		Style:     gpy.Tone,
		Heteronym: true}

	py := gpy.Pinyin(test, args)
	fmt.Println("gpy:", py)

	s := gpy.ToString(py)
	fmt.Println("gpy string:", s)

	phrase.LoadGseDict()
	
	seg := gse.New("zh, dict.txt")
	phrase.AddDict("都会区", "dū huì qū")

	fmt.Println("gpy phrase:", phrase.Paragraph(test, seg))
	fmt.Println("pinyin: ", phrase.Pinyin(test))
	fmt.Println("Initial: ", phrase.Initial("都会区"))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Cut set pinyinPhrase cut
	Cut = true
)
View Source
var DictAdd = map[string]string{
	"宿舍": "sù shè",
	"不薄": "bù báo",
	"打折": "dǎ zhé",
	"着手": "zhuó shǒu",
	"着眼": "zhuó yǎn",
	"着重": "zhuó zhòng",
}

DictAdd phrase dict addition

View Source
var (

	// Option set pinyin style args option
	Option = gpy.Args{
		Style:     gpy.Normal,
		Heteronym: true,
	}
)

Functions

func AddDict added in v0.30.2

func AddDict(text, py string)

AddDict adds a token into phrase dictionary.

func CutWord

func CutWord(s string) []string

CutWord cut the string word

func Initial added in v0.30.2

func Initial(p string, segs ...gse.Segmenter) (s string)

Initial return pinyin initial

func Join added in v0.32.0

func Join(a []string) (s string)

Join []string to string

func LoadGseDict

func LoadGseDict(files ...string) error

LoadGseDict load the user's gse dict

func Match added in v0.32.0

func Match(word string) string

Match match word pinyin

func Paragraph

func Paragraph(p string, segs ...gse.Segmenter) (s string)

Paragraph convert a Chinese string paragraph to pinyin, including letters, numbers, symbols

func Pinyin added in v0.30.2

func Pinyin(p string, segs ...gse.Segmenter) []string

Pinyin return paragraph []string

func WithGse added in v0.30.2

func WithGse(segs gse.Segmenter)

WithGse register gse segmenter

Types

This section is empty.

Jump to

Keyboard shortcuts

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