wersja bez błędów interpretera

This commit is contained in:
Dominik 2021-05-09 14:19:01 +02:00
parent eaad8c2020
commit 61e8891bc8
2 changed files with 11 additions and 9 deletions

View File

@ -15,21 +15,21 @@ class NLU: #Natural Language Understanding
self.arguments = arguments
self.book_grammar = book_grammar
def get_dialog_act(rule):
def get_dialog_act(self, rule):
slots = []
get_slots(rule.expansion, slots)
self.get_slots(rule.expansion, slots)
return {'act': rule.grammar.name, 'slots': slots}
def get_slots(expansion, slots):
def get_slots(self, expansion, slots):
if expansion.tag != '':
slots.append((expansion.tag, expansion.current_match))
return
for child in expansion.children:
get_slots(child, slots)
self.get_slots(child, slots)
if not expansion.children and isinstance(expansion, jsgf.NamedRuleRef):
get_slots(expansion.referenced_rule.expansion, slots)
self.get_slots(expansion.referenced_rule.expansion, slots)
def analyze(self, text):
"""
@ -44,11 +44,11 @@ class NLU: #Natural Language Understanding
print(act_vector)
return act_vector
def test_nlu(utterance):
matched = book_grammar.find_matching_rules(utterance)
def test_nlu(self, utterance):
matched = self.book_grammar.find_matching_rules(utterance)
if matched:
return get_dialog_act(matched[0])
return self.get_dialog_act(matched[0])
else:
return {'act': 'null', 'slots': []}
@ -137,7 +137,8 @@ class Janet:
self.nlu = NLU(self.acts, self.arguments, jsgf.parse_grammar_file('book.jsgf'))
def test(self, command):
nlu.test_nlu(command)
out = self.nlu.test_nlu(command)
return out
def process(self, command):
act = self.nlu.analyze(command)
@ -146,6 +147,7 @@ class Janet:
return self.nlg.change_to_text(dest_act)
janet = Janet()
janet.test('witam')
while(1):
text = input("Wpisz tekst: ")
print(janet.test(text))

0
Test_nlu.py Normal file
View File