Zaktualizuj 'nlu.py'
This commit is contained in:
parent
b6411ae7d0
commit
240ba12397
23
nlu.py
23
nlu.py
@ -12,3 +12,26 @@ def get_dialog_act(rule):
|
|||||||
slots = []
|
slots = []
|
||||||
get_slots(rule.expansion, slots)
|
get_slots(rule.expansion, slots)
|
||||||
return {'act': rule.grammar.name, 'slots': slots}
|
return {'act': rule.grammar.name, 'slots': slots}
|
||||||
|
|
||||||
|
|
||||||
|
def get_slots(expansion, slots):
|
||||||
|
if expansion.tag != '':
|
||||||
|
slots.append((expansion.tag, expansion.current_match))
|
||||||
|
return
|
||||||
|
|
||||||
|
for child in expansion.children:
|
||||||
|
get_slots(child, slots)
|
||||||
|
|
||||||
|
if not expansion.children and isinstance(expansion, jsgf.NamedRuleRef):
|
||||||
|
get_slots(expansion.referenced_rule.expansion, slots)
|
||||||
|
|
||||||
|
|
||||||
|
def nlu(_utterance):
|
||||||
|
_matched = order_grammar.find_matching_rules(_utterance)
|
||||||
|
|
||||||
|
if _matched:
|
||||||
|
return get_dialog_act(matched[0])
|
||||||
|
else:
|
||||||
|
return {'act': 'null', 'slots': []}
|
||||||
|
|
||||||
|
print(nlu('chciałbym zamowic pizze vesuvio XXL na dwie osoby'))
|
Loading…
Reference in New Issue
Block a user