phrase

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: MIT 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 the pinyin phrase 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 map

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 add 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 LoadGseDictEmbed added in v0.42.0

func LoadGseDictEmbed(dict ...string) error

LoadGseDictEmbed load the embed dictionary

func Match added in v0.32.0

func Match(word string) string

Match match the 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 Remove added in v0.41.0

func Remove(text string)

Remove remove a token from phrase dictionary.

func WithGse added in v0.30.2

func WithGse(segs gse.Segmenter)

WithGse register the 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