-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
69 lines (61 loc) · 1.57 KB
/
utils.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
package bayes
import (
"bytes"
"encoding/gob"
)
func NumberPositionalBinning(data string) []string {
// TODO: TEST
// it does this: Useful for classification when you cannot extrapolate data
// 1940 = 1*** 19** 194* 1945
// 1945 = 1*** 19** 194* 1945
// 1980 = 1*** 19** 198* 1980
// 2000 = 2*** 20** 200* 2000
// 2014 = 2*** 20** 201* 2014
// 2013 = 2000 2010 2013
datab := []byte(data)
result := make([][]byte, 0)
for _, fbyte := range datab {
if len(result)-1 >= 0 {
result = append(result, append(result[len(result)-1], fbyte))
} else {
last_one := make([]byte, 0)
last_one = append(last_one, fbyte)
result = append(result, last_one)
}
}
for k, v := range result {
d := make([]byte, len(v))
copy(d, v)
for i := 0; i <= (len(datab)-len(v))-1; i++ {
d = append(d, []byte("*")...)
}
result[k] = d
}
return_data := make([]string, 0)
for _, v := range result {
return_data = append(return_data, string(v))
}
return return_data
}
func ByteToAny(bytes_data []byte, feedf func(*gob.Decoder) error) error {
return feedf(gob.NewDecoder(bytes.NewReader(bytes_data)))
}
func AnyToByte(any interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(any)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
type ClassifyResultSlice []ClassifyResult
func (slice ClassifyResultSlice) Len() int {
return len(slice)
}
func (slice ClassifyResultSlice) Less(i, j int) bool {
return slice[i].Log > slice[j].Log
}
func (slice ClassifyResultSlice) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}