/
lattice.go
105 lines (79 loc) · 2.43 KB
/
lattice.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package mecab
/*
#cgo LDFLAGS: -L/usr/local/lib -lmecab -lstdc++
#include <mecab.h>
static mecab_node_t *trans_mecab_node_t (struct mecab_node_t *node){
return node;
}
*/
import "C"
type Lattice struct {
ptr *C.mecab_lattice_t
}
// ============================================
// Getter/ Setter
func (this *Lattice) GetBosNode() *Node {
return &Node{ptr: C.mecab_lattice_get_bos_node(this.ptr)}
}
func (this *Lattice) GetEosNode() *Node {
return &Node{ptr: C.mecab_lattice_get_eos_node(this.ptr)}
}
func (this *Lattice) GetSentence() string {
return C.GoString(C.mecab_lattice_get_sentence(this.ptr))
}
func (this *Lattice) GetSize() int {
return int(C.mecab_lattice_get_size(this.ptr))
}
func (this *Lattice) GetZ() float64 {
return float64(C.mecab_lattice_get_z(this.ptr))
}
func (this *Lattice) SetZ(z float64) {
C.mecab_lattice_set_z(this.ptr, C.double(z))
}
func (this *Lattice) GetTheta() float64 {
return float64(C.mecab_lattice_get_theta(this.ptr))
}
func (this *Lattice) SetTheta(theta float64) {
C.mecab_lattice_set_theta(this.ptr, C.double(theta))
}
func (this *Lattice) GetNext() int {
return int(C.mecab_lattice_next(this.ptr))
}
func (this *Lattice) GetRequestType() int {
return int(C.mecab_lattice_get_request_type(this.ptr))
}
// ============================================
// Methods
//TODO: int --> boolean
func (this *Lattice) HasRequestType(requestType int) int {
return int(C.mecab_lattice_has_request_type(this.ptr, C.int(requestType)))
}
func (this *Lattice) SetRequestType(requestType int) {
C.mecab_lattice_set_request_type(this.ptr, C.int(requestType))
}
func (this *Lattice) AddRequestType(requestType int) {
C.mecab_lattice_add_request_type(this.ptr, C.int(requestType))
}
func (this *Lattice) RemoveRequestType(requestType int) {
C.mecab_lattice_remove_request_type(this.ptr, C.int(requestType))
}
func (this *Lattice) ToString() string {
return C.GoString(C.mecab_lattice_tostr(this.ptr))
}
func (this *Lattice) EnumNBestAsString(n int) string {
return C.GoString(C.mecab_lattice_nbest_tostr(this.ptr, C.size_t(n)))
}
//TODO: btoi need
func (this *Lattice) HasConstraint() int {
return int(C.mecab_lattice_has_constraint(this.ptr))
}
//TODO: better to fix method name as C++ style?
func (this *Lattice) Delete() {
C.mecab_lattice_destroy(this.ptr)
}
func (this *Lattice) Clear() {
C.mecab_lattice_clear(this.ptr)
}
func (this *Lattice) IsAvailable() int {
return int(C.mecab_lattice_is_available(this.ptr))
}