forked from yanyiwu/gojieba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jieba.go
51 lines (44 loc) · 1008 Bytes
/
jieba.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gojieba
/*
#cgo CXXFLAGS: -DLOGGING_LEVEL=WARNING -O3 -Wall
#include <stdlib.h>
#include "jieba.h"
*/
import "C"
type Jieba struct {
jieba C.Jieba
}
func New(dict_path, hmm_path, user_dict_path string) Jieba {
var x Jieba
x.jieba = C.NewJieba(C.CString(dict_path), C.CString(hmm_path), C.CString(user_dict_path))
return x
}
func (x Jieba) Free() {
C.FreeJieba(x.jieba)
}
func (x Jieba) Cut(s string, hmm bool) []string {
c_int_hmm := 0
if hmm {
c_int_hmm = 1
}
var words **C.char = C.Cut(x.jieba, C.CString(s), C.int(c_int_hmm))
res := cstrings(words)
C.FreeWords(words)
return res
}
func (x Jieba) CutAll(s string) []string {
var words **C.char = C.CutAll(x.jieba, C.CString(s))
res := cstrings(words)
C.FreeWords(words)
return res
}
func (x Jieba) CutForSearch(s string, hmm bool) []string {
c_int_hmm := 0
if hmm {
c_int_hmm = 1
}
var words **C.char = C.CutForSearch(x.jieba, C.CString(s), C.int(c_int_hmm))
res := cstrings(words)
C.FreeWords(words)
return res
}