diff --git a/Makiety.py b/Makiety.py index 75a562e..77491f2 100644 --- a/Makiety.py +++ b/Makiety.py @@ -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)) \ No newline at end of file diff --git a/Test_nlu.py b/Test_nlu.py new file mode 100644 index 0000000..e69de29