-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimplecontrol.top
138 lines (113 loc) · 4.18 KB
/
simplecontrol.top
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# this function is executed once for every new user chatting with harry
outputmacro: anabotelho() # you get harry by default
$cs_token = #DO_INTERJECTION_SPLITTING | #DO_SUBSTITUTE_SYSTEM | #DO_NUMBER_MERGE | #DO_DATE_MERGE | #DO_PROPERNAME_MERGE | #DO_SPELLCHECK | #DO_PARSE
^addtopic(~CASE_TOPIC)
$cs_control_main = ~control
# $cs_control_post = ~XPOSTPROCESS # uncomment to enable talk
$userprompt = ^"%user: >"
$botprompt = ^"HARRY: "
$botname = ^"Ana Botelho"
$singleResponse = 1 # issue only 1 output message
table: defaultbot (^name)
^createfact(^name defaultbot defaultbot)
DATA:
anabotelho
topic: ~control system ()
# on startup, do introduction
u: ( %input<%userfirstline)
gambit(~CASE_TOPIC)
u: (< shut up >) $shutup = 1
u: (< talk >) $shutup = null
u: (\[ callback \]) Callback seen.
u: (\[ loopback \]) Loopback seen.
u: (\[ alarm \]) Alarm seen.
u: (< loopback test) \[ loopback=1000 \] Loopback requested.
u: (< callback test) \[ callback=1000 \] Callback requested.
u: (< alarm test) \[ alarm=5000 \] Alarm requested.
u: () # main per-sentence processing
$_responseCount = %response
if ($singleResponse) {$_responseCount = 0} # disable this to respond to each sentence in a volley
$$currenttopic = %topic # get the current topic at start of volley
if ( %response == $_responseCount ) {nofail(TOPIC ^rejoinder())} # try for rejoinders. might generate an answer directly from what we are looking for.
if (%length == 0 AND %response == $_responseCount )
{
nofail(TOPIC ^gambit($$currenttopic)) # gambit current topic since no input (usually start of conversation)
}
if (%response == $_responseCount) { nofail(TOPIC ^respond($$currenttopic)) } # current topic tries to respond to his input
if (%response == $_responseCount) # see if some other topic has keywords matching his input (given we have no response yet)
{
@8 = ^keywordtopics() # get topics referred in input
loop()
{
$$topic = first(@8subject)
nofail(TOPIC ^respond($$topic))
if (%response != $_responseCount) # stop when we find something to say
{
^end(RULE) # we are done, this terminates the loop (not the rule)
}
}
}
# if no topic reacts, go to the last ditch keywordless topic
if (%response == $_responseCount)
{
nofail(TOPIC ^respond(~keywordless))
}
# having no good response we know, now generate quibbles
# now we need to find fake responses
if (%response == $_responseCount AND %rand > 50)
{
nofail(TOPIC respond(~QUIBBLE_ALL))
}
# if we have rejoinders for what we said OR we asked a question, stop here
if (%outputrejoinder OR %lastquestion)
{
end(TOPIC)
}
if (%response == $_responseCount AND ^marked($$currenttopic)) { nofail(TOPIC ^gambit($$currenttopic)) } # gambit current topic since keywords match current topic
if (%response == $_responseCount) # gambit from ANY matching topic
{
@8 = ^keywordtopics() # get topics referred in input
loop()
{
$$topic = first(@8subject)
nofail(TOPIC ^Gambit($$topic)) # gambit in best matching topic
if (%response != $_responseCount) # stop when we find something
{
^end(RULE)
}
}
}
if (%response == $_responseCount){ nofail(TOPIC ^gambit($$currenttopic)) } # gambit from current topic even though no keywords matched
if (%response == $_responseCount)
{
@8 = ^GambitTopics() # all topics with gambits (excluding system topics)
loop()
{
$$topic = pick(@8subject)
nofail(TOPIC ^Gambit($$topic)) # try a topic at random
if (%response != $_responseCount)
{
^end(RULE)
}
}
}
if (%response == $_responseCount)
{
^repeat()
I don't know what to say.
}
topic: ~XPOSTPROCESS system () # gambits only - not allowed to write to output - generates speech on windows -- for Linux you'd want to install Festival (or equivalent) and call that instead.
t: (^query(direct_v ? chatoutput ? -1 ? @9 )) # get the sentences (why is the object) -- no longer has quotes around it
loop()
{
$$tmp = ^last(@9subject) # note last output which is quoted string
if (!%server AND %os == windows AND !$SHUTUP)
{
$$tmp = ^"talk \"$$tmp\" "
popen($$tmp null)
}
if (!%server AND %os == mac AND !$SHUTUP)
{
$$shellerror = system(^"say \"$$tmp\" ")
}
}