【Go】高性能的簡繁體轉換

Github鏈接地址

高性能的簡繁體轉換

入口

sat.go

// 實現該接口,以提供字體轉換
type Dicter interface {
	Init(opts ...Option) error //執行初始化操作
	Read(string) string //繁體轉簡體
	ReadReverse(string) string //簡體轉繁體
}

options.go

// 自定義初始化參數內容
type Option func(*Options)

type Options struct {
	Path string `json:"path"`
}

func SetPath(path string) Option {
	return func(args *Options) {
		args.Path = path
	}
}

default.go

// 實現 Dicter 接口
func (d *defaultDict) Init(opts ...Option) error
func (d *defaultDict) Read(s string) string
func (d *defaultDict) ReadReverse(s string) string

測試

測試代碼

dicter := DefaultDict()
dicter.ReadReverse("麼")

or

InitDefaultDict(SetPath("/users/go/xxxx.dict")) //使用自定義詞庫
dicter := DefaultDict()
dicter.ReadReverse("麼")

指標

goos: darwin
goarch: amd64
pkg: github.com/go-creed/sat
BenchmarkNewDict
BenchmarkNewDict-12    	14721091	        71.2 ns/op
PASS
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章