-
Notifications
You must be signed in to change notification settings - Fork 131
/
context.go
79 lines (74 loc) · 2.07 KB
/
context.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
package wirepod_vosk
import (
"strings"
"github.com/kercre123/wire-pod/chipper/pkg/vars"
"github.com/kercre123/wire-pod/chipper/pkg/wirepod/localization"
)
var NumbersEN_US []string = []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred", "seconds", "minutes", "hours", "minute", "second", "hour"}
func removeDuplicates(strings []string) []string {
occurred := map[string]bool{}
var result []string
for _, str := range strings {
if !occurred[str] {
result = append(result, str)
occurred[str] = true
}
}
return result
}
func GetGrammerList(lang string) string {
var wordsList []string
var grammer string
// add words in intent json
for _, words := range vars.MatchListList {
for _, word := range words {
wors := strings.Split(word, " ")
for _, wor := range wors {
found := model.FindWord(wor)
if found != -1 {
wordsList = append(wordsList, wor)
}
}
}
}
// add words in localization
for _, str := range localization.ALL_STR {
text := localization.GetText(str)
wors := strings.Split(text, " ")
for _, wor := range wors {
found := model.FindWord(wor)
if found != -1 {
wordsList = append(wordsList, wor)
}
}
}
// add custom intent matches
for _, intent := range vars.CustomIntents {
for _, utterance := range intent.Utterances {
wors := strings.Split(utterance, " ")
for _, wor := range wors {
found := model.FindWord(wor)
if found != -1 {
wordsList = append(wordsList, wor)
}
}
}
}
// add numbers
for _, wor := range NumbersEN_US {
found := model.FindWord(wor)
if found != -1 {
wordsList = append(wordsList, wor)
}
}
wordsList = removeDuplicates(wordsList)
for i, word := range wordsList {
if i == len(wordsList)-1 {
grammer = grammer + `"` + word + `"`
} else {
grammer = grammer + `"` + word + `"` + ", "
}
}
grammer = "[" + grammer + "]"
return grammer
}