-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.go
More file actions
34 lines (28 loc) · 667 Bytes
/
utils.go
File metadata and controls
34 lines (28 loc) · 667 Bytes
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
package gotokenizer
import "errors"
// CheckDictIsLoaded that checks dict is Loaded
func CheckDictIsLoaded(dict *Dict) error {
if dict == nil {
return errors.New("please load dictionary")
}
return nil
}
// Reverse returns reversed of string slice
func Reverse(s []string) []string {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return s
}
// GetFrequency returns frequency of tokens
func GetFrequency(result []string) map[string]int {
resultMap := make(map[string]int, len(result))
for _, v := range result {
if _, ok := resultMap[v]; ok {
resultMap[v]++
} else {
resultMap[v] = 1
}
}
return resultMap
}