-
Notifications
You must be signed in to change notification settings - Fork 0
/
eliza_helpers.go
74 lines (64 loc) · 1.35 KB
/
eliza_helpers.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
package eliza
import (
"bufio"
"os"
"strings"
)
func GetInput() string {
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
return input
}
func CheckForQuit(parsed []string) bool {
quits := map[string]string{
"bye": "string1",
"goodbye": "string2",
}
for _, word := range parsed {
if _, ok := quits[word]; ok {
return true
}
}
return false
}
func ParseInput(input string) []string {
parsed := strings.Split(input, " ")
for i, word := range parsed {
parsed[i] = strings.ToLower(strings.Trim(word, ".! \n"))
}
return parsed
}
func PreProcess(parsed []string) (prepd []string) {
prepd = parsed
for i, word := range parsed {
if processed_word, ok := Pre[word]; ok {
prepd[i] = processed_word
}
}
return prepd
}
func PostProcess(parsed []string) (postd []string) {
postd = parsed
for i, word := range parsed {
if processed_word, ok := Post[word]; ok {
postd[i] = processed_word
}
}
return postd
}
func Synonymize(parsed []string) (synond []string) {
// initialize map of synonyms to easily check for words
Synonyms := make(map[string]string)
for key, synonList := range SynonymMap {
for _, word := range synonList {
Synonyms[word] = key
}
}
synond = parsed
for i, word := range parsed {
if processed_word, ok := Synonyms[word]; ok {
synond[i] = processed_word
}
}
return synond
}