-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqualifier.go
More file actions
40 lines (32 loc) 路 784 Bytes
/
Copy pathqualifier.go
File metadata and controls
40 lines (32 loc) 路 784 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
35
36
37
38
39
40
package main
import (
"strings"
"unicode/utf8"
jsoniter "github.com/json-iterator/go"
)
// qualify provides a qualifier for the given string.
func (c *config) qualify(s string) string {
// Skip empty strings.
if s == "" {
return ""
}
// Skip strings less than min word length.
if utf8.RuneCountInString(s) < c.minWordLen {
return ""
}
// Create a new map for JSON.
qualifyWords := make(map[string][]string, 0)
// Unmarshal JSON data to the result slice.
err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(c.intentsFile, &qualifyWords)
if err != nil {
return ""
}
for intent, words := range qualifyWords {
for _, el := range words {
if strings.Contains(strings.ToLower(s), strings.ToLower(el)) {
return intent
}
}
}
return ""
}