feat(Go-StudyExample):2020/12/17:新增yanyiwu中文分词工具使用示例
This commit is contained in:
@@ -7,13 +7,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Go-StudyExample/example/originGoLanguage"
|
"fmt"
|
||||||
_ "Go-StudyExample/example/originGoLanguage/init"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
x := 0
|
||||||
//go原生语言测试
|
for i := 1; i < 31; i++ {
|
||||||
originGoLanguage.TestOriginLang()
|
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需要加载系统变量上面,不是用户系统变量
|
||||||
@@ -23,6 +23,8 @@ json与struct之间转换处理工具使用示例
|
|||||||
|
|
||||||
2020/12/16: 新增gjson的使用示例
|
2020/12/16: 新增gjson的使用示例
|
||||||
|
|
||||||
|
2020/12/17:新增yanyiwu中文分词工具使用示例
|
||||||
|
|
||||||
# mod vendor模式加载包
|
# mod vendor模式加载包
|
||||||
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user