forked from Siminn-teiturg/embla-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channels.py
230 lines (153 loc) · 5.21 KB
/
channels.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import logging
import random
from query import Query, QueryStateDict
from tree import Result
# TODO: Channel ID dict?
_TV_CHANNEL_QTYPE = "TV-Channel"
TOPIC_LEMMAS = ["RÚV", "Sjónvarp Símans"]
def help_text(lemma: str) -> str:
"""Help text to return when query.py is unable to parse a query but
one of the above lemmas is found in it"""
return "Ég get svarað ef þú spyrð til dæmis: {0}?".format(
random.choice(
(
"RÚV",
"Sjónvarp Símans",
"Hringbraut",
"Síminn Sport",
"Alþingi",
)
)
)
# This module wants to handle parse trees for queries
HANDLE_TREE = True
# The grammar nonterminals this module wants to handle
QUERY_NONTERMINALS = {"QTVChannel"}
# The context-free grammar for the queries recognized by this plug-in module
GRAMMAR = """
Query →
QTVChannel
QTVChannel → QTVChannelQuery '?'?
QTVChannelQuery →
QTVChannelRUV | QTVChannelSS
| QTVChannelStod2 | QTVChannelStod2Fjolskylda | QTVChannelStod2Bio
| QTVChannelHringbraut | QTVChannelStod2Visir | QTVChannelRUV2
| QTVChannelSiminnSport | QTVChannelSiminnSport2 | QTVChannelSiminnSport3 | QTVChannelSiminnSport4
| QTVChannelAlthing | QTVChannelOmega
| QTVChannelStod2Sport | QTVChannelStod2Sport2 | QTVChannelStod2Sport3 | QTVChannelStod2Sport4
| QTVChannelStod2eSport | QTVChannelStod2Golf
QTVChannelRUV →
"rúv" | 'ríkisútvarp'/fall | "stöð" "eitt" | "einn"
QTVChannelSS →
"sjónvarp" "símans" | "sjónvarp" 'síminn'/fall | "sjónvarp" 'sími:no'/fall | "sjónvarp" "síminn" | "tveir"
QTVChannelStod2 →
"stöð" QTwo
| "studdu" QTwo
| "studduð" QTwo
QTVChannelStod2Fjolskylda →
QTVChannelStod2 "fjölskylda"
QTVChannelStod2Bio →
QTVChannelStod2 "bíó"
QTVChannelHringbraut →
"hringbraut"
QTVChannelStod2Visir →
QTVChannelStod2 "vísir"
QTVChannelK100 →
"ká" "hundrað"
QTVChannelRUV2 →
QTVChannelRUV QTwo
QTVChannelSiminnSport →
QSiminn QSport QOne?
QTVChannelSiminnSport2 →
QSiminn QSport QTwo
QTVChannelSiminnSport3 →
QSiminn QSport QThree
QTVChannelSiminnSport4 →
QSiminn QSport QFour
QOne →
'einn'/kyn
QTwo →
'tveir'/kyn
QThree →
'þrír'/kyn
QFour →
'fjórir'/kyn
QSiminn →
'síminn'/fall | 'sími:no'/fall | "síminn"
QSport →
"sport"
QTVChannelAlthing →
"alþingi"
QTVChannelOmega →
"omega" | "ómega" | "Omega"
QTVChannelStod2Sport →
QTVChannelStod2 QSport QOne?
QTVChannelStod2Sport2 →
QTVChannelStod2 QSport QTwo
QTVChannelStod2Sport3 →
QTVChannelStod2 QSport QThree
QTVChannelStod2Sport4 →
QTVChannelStod2 QSport QFour
QTVChannelStod2eSport →
QTVChannelStod2 "e" QSport
QTVChannelStod2Golf →
QTVChannelStod2 "golf"
"""
def QTVChannelQuery(node, params, result):
result.qtype = _TV_CHANNEL_QTYPE
def QTVChannelRUV(node, params, result):
result["command"] = 22759586
def QTVChannelSS(node, params, result):
result["command"] = 22759594
def QTVChannelStod2(node, params, result):
result["command"] = 22759599
def QTVChannelStod2Fjolskylda(node, params, result):
result["command"] = 22759572
def QTVChannelStod2Bio(node, params, result):
result["command"] = 22759610
def QTVChannelHringbraut(node, params, result):
result["command"] = 40043140
def QTVChannelStod2Visir(node, params, result):
result["command"] = 22759598
def QTVChannelRUV2(node, params, result):
result["command"] = 46888903
def QTVChannelSiminnSport(node, params, result):
result["command"] = 46888998
def QTVChannelSiminnSport2(node, params, result):
result["command"] = 46888999
def QTVChannelSiminnSport3(node, params, result):
result["command"] = 46890006
def QTVChannelSiminnSport4(node, params, result):
result["command"] = 46890007
def QTVChannelAlthing(node, params, result):
result["command"] = 22759659
def QTVChannelOmega(node, params, result):
result["command"] = 22759667
def QTVChannelStod2Sport(node, params, result):
result["command"] = 22759619
def QTVChannelStod2Sport2(node, params, result):
result["command"] = 22759656
def QTVChannelStod2Sport3(node, params, result):
result["command"] = 22759600
def QTVChannelStod2Sport4(node, params, result):
result["command"] = 22759643
def QTVChannelStod2eSport(node, params, result):
result["command"] = 46890013
def QTVChannelStod2Golf(node, params, result):
result["command"] = 40043123
def sentence(state: QueryStateDict, result: Result) -> None:
"""Called when sentence processing is complete."""
q: Query = state["query"]
if "qtype" in result and result["qtype"] == _TV_CHANNEL_QTYPE:
q.query_is_command()
try:
print("))============>", _TV_CHANNEL_QTYPE, "<============((")
q.set_qtype(_TV_CHANNEL_QTYPE)
ans = "CHANNEL;" + str(result["command"])
q.set_answer({"answer": ans}, ans)
return
except Exception as e:
logging.warning("Exception generating answer from Channels: {0}".format(e))
q.set_error("E_EXCEPTION: {0}".format(e))
else:
q.set_error("E_QUERY_NOT_UNDERSTOOD")