|
@@ -0,0 +1,27 @@
|
|
|
|
+package participle
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "strings"
|
|
|
|
+
|
|
|
|
+ "github.com/yanyiwu/gojieba"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+//sw 1:全模式;2:精确模式;3:搜索引擎模式
|
|
|
|
+func Participle(sw int, word string) []string {
|
|
|
|
+ x := gojieba.NewJieba()
|
|
|
|
+ defer x.Free()
|
|
|
|
+ return func(word string) []string {
|
|
|
|
+ use_hmm := true
|
|
|
|
+ switch sw {
|
|
|
|
+ case 1:
|
|
|
|
+ return x.CutAll(word)
|
|
|
|
+ case 2:
|
|
|
|
+ return x.Cut(word, use_hmm)
|
|
|
|
+ case 3:
|
|
|
|
+ return x.CutForSearch(word, !use_hmm)
|
|
|
|
+ default:
|
|
|
|
+ return strings.Split(word, " ")
|
|
|
|
+ }
|
|
|
|
+ }(word)
|
|
|
|
+
|
|
|
|
+}
|