forked from yanyiwu/gojieba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
59 lines (54 loc) · 1.13 KB
/
util.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
52
53
54
55
56
57
58
59
package gojieba
/*
#include "jieba.h"
*/
import "C"
import (
"os"
"unsafe"
)
func isDirExists(path string) bool {
fi, err := os.Stat(path)
if err != nil {
return os.IsExist(err)
} else {
return fi.IsDir()
}
return false
}
func cstrings(x **C.char) []string {
var s []string
eltSize := unsafe.Sizeof(*x)
for *x != nil {
s = append(s, C.GoString(*x))
x = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + eltSize))
}
return s
}
func convertWords(s string, words *C.Word) []Word {
result := make([]Word, 0)
x := words
eltSize := unsafe.Sizeof(*x)
start := 0
end := 0
for (*x).len != 0 {
start = int((*x).offset)
end = start + int((*x).len)
result = append(result, Word{s[start:end], start, end})
x = (*C.Word)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + eltSize))
}
return result
}
//func cwordweights(x unsafe.Pointer) []WordWeight {
// var s []WordWeight
// eltSize := 16
// for (*(*C.char))(x) != nil {
// ww := WordWeight{
// C.GoString((*C.char))(x)),
// (*x).weight,
// }
// s = append(s, ww)
// x = (*C.struct_CWordWeight)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + eltSize))
// }
// return s
//}