glogcenter/glc/ldb/tokenizer/tokenizer.go
2022-11-22 21:30:12 +08:00

31 lines
747 B
Go

/**
* TODO 待整理
*/
package tokenizer
import (
"path/filepath"
"runtime"
"github.com/gotoeasy/glang/cmn"
)
var jiebago *cmn.TokenizerJiebago
// 初始化装载字典
func init() {
_, filename, _, _ := runtime.Caller(0) // 当前go文件所在路径
dictfile := filepath.Join(filepath.Dir(filename), "dict.txt")
jiebago = cmn.NewTokenizerJiebago(dictfile)
}
// 按搜索引擎模式进行分词后返回分词数组
func CutForSearch(text string) []string {
return jiebago.CutForSearch(text)
}
// 按搜索引擎模式进行分词后返回分词数组,可自定义添加或删除分词
func CutForSearchEx(text string, addWords []string, delWords []string) []string {
return jiebago.CutForSearchEx(text, addWords, delWords)
}