-
Notifications
You must be signed in to change notification settings - Fork 2
/
front_end.py
106 lines (78 loc) · 6.25 KB
/
front_end.py
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
from actions import *
from qa_shifter import *
from sensors import *
class process_mst(Procedure): pass
class process_cmd(Procedure): pass
# SIMULATING EVENTS
# Routines
# turn off the lights in the living room, when the temperature is 25 and the time is 12.00
# set the cooler in the bedroom to 25 degrees and cut the grass in the garden, when the time is 12.00
# Direct Commands
# set the cooler at 27 degrees in the bedroom
# turn off the lights in the living room
# Sensors
s1() >> [simulate_sensor("Be", "Time", "12.00")]
s2() >> [simulate_sensor("Be", "Temperature", "25")]
make_feed() / TEST(X) >> [-TEST(X), reset_ct(), parse_rules(X), parse_deps(), feed_mst(), process_mst(), log_cmd("Feed", X), show_ct(), make_feed()]
make_feed() >> [show_line("\nFeeding KBs ended.\n")]
# Feeding Clauses KB with sentences in FILE_KB_NAME (config.ini)
feed() >> [show_line("\nFeeding KBs from file....\n"), +WAKE("ON"), +LISTEN("ON"), feed_kbs(), make_feed()]
# Feeding Clauses KB with sentences X
feed(X) >> [show_line("\nFeeding KBs from file....\n"), +WAKE("ON"), +LISTEN("ON"), +TEST(X), make_feed()]
# Front-End STT
# Start agent command
go() >> [show_line("AD-Caspar started! Bot is running..."), Chatbot().start(), set_wait()]
# show higher Clauses kb
hkb() >> [show_fol_kb()]
# show lower Clauses kb
lkb() >> [show_lkb()]
# show lower Clauses kb
expt() >> [export_lkb()]
# initialize Higher Clauses Kb
chkb() >> [log_op(">>> Flushing High Clauses KB..."), clear_hkb()]
# initialize Lower Clauses Kb
clkb() >> [log_op(">>> Flushing Low Clauses KB..."), clear_lkb()]
# chatbot wake word
+message(C, "hello") / WAIT(W) >> [Reply(C, "Hello!"), +WAKE("ON"), +CHAT_ID(C), clear_hkb(), Timer(W).start()]
# chatbot kbs utilities words
+message(C, "forget") / WAIT(W) >> [Reply(C, "Okay, short term memory is gone..."), +WAKE("ON"), +CHAT_ID(C), clear_hkb(), Timer(W).start()]
+message(C, "forget all") / WAIT(W) >> [Reply(C, "Okay, short and long term memory are gone..."), +WAKE("ON"), +CHAT_ID(C), clear_hkb(), clear_lkb(), Timer(W).start()]
+message(C, X) / WAKE("ON") >> [reset_ct(), +CHAT_ID(C), +MSG(X), manage_msg(), Timer(W).start()]
# Assertion management (chatbot)
manage_msg() / (MSG(X) & CHAT_ID(C) & check_last_char(X, ".")) >> [Reply(C, "Got it."), -MSG(X), -REASON("ON"), +LISTEN("ON"), parse_rules(X), parse_deps(), feed_mst(), process_mst(), log_cmd("Feed", X), manage_msg()]
# Questions management (chatbot)
manage_msg() / (MSG(X) & CHAT_ID(C) & check_last_char(X, "?")) >> [Reply(C, "Let me think..."), -MSG(X), -LISTEN("ON"), +REASON("ON"), +STT(X), log_cmd("Query", X), qreason(), manage_msg()]
# Domotic command management (chatbot)
manage_msg() / (MSG(X) & CHAT_ID(C)) >> [Reply(C, "IoT command detected"), -MSG(X), parse_rules(X), parse_deps(), feed_mst(), process_cmd(), log_cmd("IoT", X), manage_msg()]
# Ending operation (chatbot)
manage_msg() >> [show_ct(), show_line("\n------------- End of operations.\n"), Timer(W).start()]
# Assertion management (shell)
proc(X) / check_last_char(X, ".") >> [show_line("\nGot it."), +WAKE("ON"), -REASON("ON"), +LISTEN("ON"), parse_rules(X), parse_deps(), feed_mst(), process_mst(), log_cmd("Feed", X), show_ct(), -WAKE("ON"), +LISTEN("ON"), show_line("\n------------- End of operations.\n")]
# Questions management (shell)
proc(X) / check_last_char(X, "?") >> [show_line("\nLet me think..."), +WAKE("ON"), -LISTEN("ON"), +REASON("ON"), +STT(X), log_cmd("Query", X), qreason(), show_ct(), -WAKE("ON"), -REASON("ON"), show_line("\n------------- End of operations.\n")]
# Domotic command management (shell)
proc(X) >> [show_line("\nIoT command detected"), +WAKE("ON"), parse_rules(X), parse_deps(), feed_mst(), process_cmd(), log_cmd("IoT", X), show_ct(), -WAKE("ON"), show_line("\n------------- End of operations.\n")]
# Give back X as chatbot answer
+OUT(X) / CHAT_ID(C) >> [Reply(C, X), Timer(W).start()]
# Reasoning
qreason() / (STT(X) & WAKE("ON") & REASON("ON")) >> [show_line("\nTurning question into fact shapes....\n"), -STT(X), assert_sequence(X), getcand(), tense_debt_paid(), qreason()]
qreason() / (CAND(X) & WAKE("ON") & REASON("ON") & ANSWERED('YES')) >> [-CAND(X), qreason()]
qreason() / (CAND(X) & WAKE("ON") & REASON("ON")) >> [show_line("\nProcessing candidate....", X), -CAND(X), +GEN_MASK("FULL"), parse_rules(X), parse_deps(), feed_mst(), new_def_clause("ONE", "NOMINAL"), qreason()]
qreason() / (WAKE("ON") & REASON("ON") & ANSWERED('YES') & RELATED(X)) >> [-RELATED(X), +OUT(X), qreason()]
qreason() / (WAKE("ON") & REASON("ON") & ANSWERED('YES')) >> [-ANSWERED('YES')]
qreason() / (WAKE("ON") & REASON("ON") & RELATED(X)) >> [-RELATED(X), +OUT(X), qreason()]
# Nominal clauses assertion --> single: FULL", "ONE" --- multiple: "BASE", "MORE"
process_mst() / (WAKE("ON") & LISTEN("ON")) >> [show_line("\nGot it.\n"), +GEN_MASK("BASE"), new_def_clause("MORE", "NOMINAL"), process_rule()]
# processing rules --> single: FULL", "ONE" --- multiple: "BASE", "MORE"
process_rule() / IS_RULE("TRUE") >> [show_line("\n------> rule detected!!\n"), -IS_RULE("TRUE"), +GEN_MASK("BASE"), new_def_clause("MORE", "RULE")]
# Generalization assertion
new_def_clause(M, T) / GEN_MASK("BASE") >> [-GEN_MASK("BASE"), preprocess_clause("BASE", M, T), parse(), process_clause(), new_def_clause(M, T)]
new_def_clause(M, T) / GEN_MASK(Y) >> [-GEN_MASK(Y), preprocess_clause(Y, M, T), parse(), process_clause(), new_def_clause(M, T)]
new_def_clause(M, T) / (WAIT(W) & CHAT_ID(C)) >> [show_line("\n------------- Done.\n"), Timer(W).start()]
new_def_clause(M, T) / WAIT(W) >> [show_line("\n------------- Done.\n"), Timer(W).start()]
# IoT Reasoning
process_cmd() / (WAKE("ON")) >> [show_line("\nProcessing IoT command...\n"), assert_command(), parse_command(), parse_routine()]
+TIMEOUT("ON") / (WAKE("ON") & LISTEN("ON") & REASON("ON") & CHAT_ID(C)) >> [show_line("Returning to sleep..."), Reply(C, "Returning to sleep..."), -WAKE("ON"), -LISTEN("ON"), -REASON("ON")]
+TIMEOUT("ON") / (WAKE("ON") & REASON("ON") & CHAT_ID(C)) >> [show_line("Returning to sleep..."), Reply(C, "Returning to sleep..."), -REASON("ON"), -WAKE("ON")]
+TIMEOUT("ON") / (WAKE("ON") & LISTEN("ON") & CHAT_ID(C)) >> [show_line("Returning to sleep..."), Reply(C, "Returning sleep..."), -LISTEN("ON"), -WAKE("ON")]
+TIMEOUT("ON") / (WAKE("ON") & CHAT_ID(C)) >> [show_line("Returning to sleep..."), Reply(C, "Returning to sleep..."), -WAKE("ON")]