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

0
Test_nlu.py Normal file
View File