Skip to content

Commit caac728

Browse files
author
Sean Trott
committed
Cleaned up references to JSON. Transport now hides all this, instead of double-converting into JSON each time.
1 parent aaa9cf7 commit caac728

5 files changed

Lines changed: 26 additions & 46 deletions

File tree

src/main/nluas/app/core_solver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def initialize_templates(self):
7272
self.parameter_templates = self.read_templates(self.__path__+"parameter_templates.json")
7373

7474
def request_clarification(self, ntuple, message="This ntuple requires clarification."):
75-
new = self.decoder.convert_to_JSON(ntuple)
76-
request = {'ntuple': new, 'message': message, 'type': 'clarification', 'tag': self.address}
75+
#new = self.decoder.convert_to_JSON(ntuple)
76+
request = {'ntuple': ntuple, 'message': message, 'type': 'clarification', 'tag': self.address}
7777
self.transport.send(self.ui_address, json.dumps(request))
7878

7979
def identification_failure(self, message):
@@ -88,8 +88,8 @@ def return_error_descriptor(self, message):
8888
request = {'type': 'error_descriptor', 'message': message, 'tag': self.address}
8989
self.transport.send(self.ui_address, json.dumps(request))
9090

91-
def solve(self, json_ntuple):
92-
ntuple = self.decoder.convert_JSON_to_ntuple(json_ntuple)
91+
def solve(self, ntuple):
92+
#ntuple = self.decoder.convert_JSON_to_ntuple(json_ntuple)
9393
if self.check_for_clarification(ntuple):
9494
self.request_clarification(ntuple=ntuple)
9595
else:
@@ -139,6 +139,7 @@ def solve_conditional_query(self, ntuple):
139139
print(ntuple.keys())
140140

141141
def route_event(self, eventDescription, predicate):
142+
print(eventDescription)
142143
if "complexKind" in eventDescription and eventDescription['complexKind'] == "conditional":
143144
dispatch = getattr(self, "solve_conditional_{}".format(predicate))
144145
return dispatch(eventDescription)
Binary file not shown.

src/main/nluas/language/core_specializer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def specialize_fragment(self, fs):
7474
return None
7575
elif self.analyzer.issubtype("SCHEMA", fs.m.type(), "RD"):
7676
return self.get_objectDescriptor(fs.m)
77+
elif self.analyzer.issubtype("SCHEMA", fs.m.type(), "HeadingSchema"):
78+
return self.get_headingDescriptor(fs.m)
7779
elif self.analyzer.issubtype("SCHEMA", fs.m.type(), "PropertyModifier"):
7880
return self.get_property(fs.m)
7981
#elif self.analyzer.issubtype("SCHEMA", fs.m.type(), "EventDescriptor"): # Testing...

src/main/nluas/language/text_agent.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,15 @@ def prompt(self):
4949
self.clarification = False
5050
else:
5151
ntuple = {'text': msg, 'type': "standard"}
52-
json_ntuple = json.dumps(ntuple)
53-
self.transport.send(self.ui_destination, json_ntuple)
52+
self.transport.send(self.ui_destination, ntuple)
5453

5554
def callback(self, ntuple):
5655
""" Callback for receiving information from UI-Agent. """
57-
ntuple = json.loads(ntuple)
56+
#ntuple = json.loads(ntuple)
5857
if "type" in ntuple and ntuple['type'] == "clarification":
5958
self.clarification = True
6059
self.original = ntuple['original']
6160
self.output_stream(ntuple['tag'], ntuple['message'])
62-
"""
63-
while True:
64-
print("++++++++++++++")
65-
msg = input("> ")
66-
if msg == "q":
67-
self.clarification = False
68-
69-
break
70-
elif msg != None and msg != "":
71-
self.transport.send(self.ui_destination, json.dumps({'text': msg, 'type': 'clarification', 'original': ntuple['original']}))
72-
self.clarification = False
73-
"""
7461

7562

7663

src/main/nluas/language/user_agent.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def __init__(self, args):
4747
self.transport.subscribe(self.solve_destination, self.callback)
4848
self.transport.subscribe(self.speech_address, self.speech_callback)
4949
self.transport.subscribe(self.text_address, self.text_callback)
50-
print(self.speech_address)
51-
print(self.address)
5250

5351

5452
def setup_ui_parser(self):
@@ -110,8 +108,8 @@ def process_input(self, msg):
110108
self.specializer.set_spans(matched)
111109
ntuple = self.specializer.specialize(fs)
112110

113-
json_ntuple = self.decoder.convert_to_JSON(ntuple)
114-
return json_ntuple
111+
#json_ntuple = self.decoder.convert_to_JSON(ntuple)
112+
return ntuple
115113
except Exception as e:
116114
self.output_stream(self.name, e)
117115
#traceback.print_exc()
@@ -126,20 +124,17 @@ def output_stream(self, tag, message):
126124
def speech_callback(self, ntuple):
127125
""" Processes text from a SpeechAgent. """
128126
#print(ntuple)
129-
print(ntuple)
130127
#ntuple = json.loads(ntuple)
131-
print(ntuple['text'])
132-
json_ntuple = self.process_input(ntuple['text'])
133-
134-
if json_ntuple and json_ntuple != "null" and "predicate_type" in json.loads(json_ntuple):
135-
self.transport.send(self.solve_destination, json_ntuple)
128+
new_ntuple = self.process_input(ntuple['text'])
129+
if new_ntuple and new_ntuple != "null" and "predicate_type" in new_ntuple:
130+
self.transport.send(self.solve_destination, new_ntuple)
136131

137132

138133
def text_callback(self, ntuple):
139134
""" Processes text from a SpeechAgent. """
140135
#print(ntuple)
141136
specialize = True
142-
ntuple = json.loads(ntuple)
137+
#ntuple = json.loads(ntuple)
143138
msg = ntuple['text']
144139
if ntuple['type'] == "standard":
145140
if msg == None or msg == "":
@@ -148,19 +143,14 @@ def text_callback(self, ntuple):
148143
self.specializer.set_debug()
149144
specialize = False
150145
elif specialize:
151-
json_ntuple = self.process_input(ntuple['text'])
152-
if json_ntuple and json_ntuple != "null" and "predicate_type" in json.loads(json_ntuple):
153-
self.transport.send(self.solve_destination, json_ntuple)
146+
new_ntuple = self.process_input(ntuple['text'])
147+
if new_ntuple and new_ntuple != "null" and "predicate_type" in new_ntuple:
148+
self.transport.send(self.solve_destination, new_ntuple)
154149
elif ntuple['type'] == "clarification":
155-
first = self.process_input(msg)
156-
descriptor = json.loads(first)
157-
#print(descriptor)
158-
converted = json.loads(ntuple['original'])
150+
descriptor = self.process_input(msg)
159151
self.clarification = False
160-
new_ntuple = self.clarify_ntuple(converted, descriptor)
161-
json_ntuple = self.decoder.convert_to_JSON(new_ntuple)
162-
#json_ntuple = json.dumps(new_ntuple)
163-
self.transport.send(self.solve_destination, json_ntuple)
152+
new_ntuple = self.clarify_ntuple(ntuple['original'], descriptor)
153+
self.transport.send(self.solve_destination, new_ntuple)
164154
self.clarification = False
165155

166156

@@ -206,17 +196,17 @@ def prompt(self):
206196
specialize = False
207197
elif specialize:
208198
#if self.check_spelling(msg):
209-
json_ntuple = self.process_input(msg)
210-
if json_ntuple and json_ntuple != "null" and "predicate_type" in json.loads(json_ntuple):
211-
self.transport.send(self.solve_destination, json_ntuple)
199+
ntuple = self.process_input(msg)
200+
if ntuple and ntuple != None and "predicate_type" in ntuple:
201+
self.transport.send(self.solve_destination, ntuple)
212202

213203

214204

215205
def process_clarification(self, tag, msg, ntuple):
216206
self.clarification = True
217207
#self.output_stream(tag, msg)
218-
json_ntuple = json.dumps({'tag': tag, 'message': msg, 'type': "clarification", 'original': ntuple})
219-
self.transport.send(self.text_address, json_ntuple)
208+
new_ntuple = {'tag': tag, 'message': msg, 'type': "clarification", 'original': ntuple}
209+
self.transport.send(self.text_address, new_ntuple)
220210
"""
221211
#print(ntuple)
222212
while True:

0 commit comments

Comments
 (0)