-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
47 lines (30 loc) · 1.11 KB
/
server.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
from harmony_device import HarmonyDevice, Attribute
from Action import Action
from SmallTalk import SmallTalk
actions = [SmallTalk()]
device = HarmonyDevice()
class Query(Attribute):
name = "query"
description = "Allows devices to make queries to the J.A.R.V.I.S. server"
def getter(self, params):
print(params)
#First, we get the user's raw input
user_input = params['sentence']
#Next, we tokenize it by splitting on spaces
user_words = user_input.split(' ')
#We rank the actions based on keywords
for action in actions:
action.rank = 0
for word in user_input:
for keyword in action.keywords:
if keyword == word:
action.rank += 1
#Then we find the one with the greatest rank and run it
best_action = actions[0]
for action in actions:
if action.rank > best_action.rank:
best_action = action
response = best_action.run(user_input)
return response
device.add_attribute(Query)
device.run(port=8080)