feat(Go-StudyExample):2020/12/17:新增yanyiwu中文分词工具使用示例
This commit is contained in:
@@ -7,13 +7,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Go-StudyExample/example/originGoLanguage"
|
||||
_ "Go-StudyExample/example/originGoLanguage/init"
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
//go原生语言测试
|
||||
originGoLanguage.TestOriginLang()
|
||||
|
||||
x := 0
|
||||
for i := 1; i < 31; i++ {
|
||||
x = x + 1<<i
|
||||
}
|
||||
fmt.Println(math.MaxInt32)
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* @Author : huangzj
|
||||
* @Time : 2020/12/16 14:27
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package participle
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yanyiwu/gojieba"
|
||||
)
|
||||
|
||||
const (
|
||||
separator = "|" //字符串拼接,和该工具无关
|
||||
)
|
||||
|
||||
func TestParticipleUseHMM(t *testing.T) {
|
||||
var seg = gojieba.NewJieba()
|
||||
defer seg.Free()
|
||||
|
||||
var resWords []string
|
||||
var sentence = "万里长城万里长"
|
||||
|
||||
resWords = seg.CutAll(sentence)
|
||||
fmt.Printf("%s\t全模式:%s \n", sentence, strings.Join(resWords, separator))
|
||||
|
||||
resWords = seg.Cut(sentence, true)
|
||||
fmt.Printf("%s\t精确模式:%s \n", sentence, strings.Join(resWords, separator))
|
||||
var addWord = "万里长"
|
||||
seg.AddWord(addWord)
|
||||
fmt.Printf("添加新词:%s\n", addWord)
|
||||
|
||||
resWords = seg.Cut(sentence, true)
|
||||
fmt.Printf("%s\t精确模式:%s \n", sentence, strings.Join(resWords, separator))
|
||||
|
||||
sentence = "北京鲜花速递"
|
||||
resWords = seg.Cut(sentence, true)
|
||||
fmt.Printf("%s\t新词识别:%s \n", sentence, strings.Join(resWords, separator))
|
||||
|
||||
sentence = "北京鲜花速递"
|
||||
resWords = seg.CutForSearch(sentence, true)
|
||||
fmt.Println(sentence, "\t搜索引擎模式:", strings.Join(resWords, separator))
|
||||
|
||||
sentence = "北京市朝阳公园"
|
||||
resWords = seg.Tag(sentence)
|
||||
fmt.Println(sentence, "\t词性标注:", strings.Join(resWords, separator))
|
||||
|
||||
sentence = "鲁迅先生"
|
||||
resWords = seg.CutForSearch(sentence, false)
|
||||
fmt.Println(sentence, "\t搜索引擎模式:", strings.Join(resWords, separator))
|
||||
|
||||
words := seg.Tokenize(sentence, gojieba.SearchMode, false)
|
||||
fmt.Println(sentence, "\tTokenize Search Mode 搜索引擎模式:", words)
|
||||
|
||||
words = seg.Tokenize(sentence, gojieba.DefaultMode, false)
|
||||
fmt.Println(sentence, "\tTokenize Default Mode搜索引擎模式:", words)
|
||||
|
||||
word2 := seg.ExtractWithWeight(sentence, 5)
|
||||
fmt.Println(sentence, "\tExtract:", word2)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
参考地址:http://www.topgoer.com/%E5%85%B6%E4%BB%96/%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D.html
|
||||
|
||||
包获取方法:go get github.com/yanyiwu/gojieba
|
||||
|
||||
我的想法
|
||||
|
||||
分词如果跟前缀树一起使用是不是可以实现关键词典的模糊搜索:
|
||||
前缀树代码参考我的另一个工程Go-Tool
|
||||
|
||||
|
||||
问题
|
||||
因为这个库是通过C++实现的,所以需要下载gcc并设置环境变量,可参考:https://blog.csdn.net/benben_2015/article/details/80565676
|
||||
|
||||
gcc环境下载地址:https://www.cnblogs.com/LUA123/p/11446185.html
|
||||
|
||||
注意这边的path需要加载系统变量上面,不是用户系统变量
|
||||
Reference in New Issue
Block a user