update NLU
This commit is contained in:
parent
a2a83332e4
commit
9a33831c4c
24
Main.py
24
Main.py
@ -4,21 +4,21 @@ from DialoguePolicy import DialoguePolicy
|
||||
from NaturalLanguageGeneration import NaturalLanguageGeneration
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = "Cześć, jak masz na imię?"
|
||||
text = "chciałbym zarezerwować hotel"
|
||||
nla = NaturalLanguageAnalyzer()
|
||||
user_act = nla.process(text)
|
||||
print(user_act)
|
||||
|
||||
dst = DialogueStateTracker()
|
||||
state = dst.dst(user_act)
|
||||
print(state)
|
||||
|
||||
dp = DialoguePolicy()
|
||||
system_act = dp.policy(state)
|
||||
print(system_act)
|
||||
|
||||
nlg = NaturalLanguageGeneration()
|
||||
response = nlg.nlg(system_act)
|
||||
print(response)
|
||||
# dst = DialogueStateTracker()
|
||||
# state = dst.dst(user_act)
|
||||
# print(state)
|
||||
#
|
||||
# dp = DialoguePolicy()
|
||||
# system_act = dp.policy(state)
|
||||
# print(system_act)
|
||||
#
|
||||
# nlg = NaturalLanguageGeneration()
|
||||
# response = nlg.nlg(system_act)
|
||||
# print(response)
|
||||
|
||||
|
||||
|
@ -1,6 +1,35 @@
|
||||
import jsgf
|
||||
|
||||
|
||||
class NaturalLanguageAnalyzer:
|
||||
# def process(self, text):
|
||||
# user_act = None
|
||||
# if ("imie" in text or "imię" in text) and "?" in text:
|
||||
# user_act = "request(firstname)"
|
||||
# return user_act
|
||||
|
||||
def process(self, text):
|
||||
user_act = None
|
||||
if ("imie" in text or "imię" in text) and "?" in text:
|
||||
user_act = "request(firstname)"
|
||||
return user_act
|
||||
with open('grammar.jsgf', 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
book_grammar = jsgf.parse_grammar_string(content)
|
||||
matched = book_grammar.find_matching_rules(text)
|
||||
if matched:
|
||||
return self.get_dialog_act(matched[0])
|
||||
else:
|
||||
return {'act': 'null', 'slots': []}
|
||||
|
||||
def get_slots(self, expansion, slots):
|
||||
if expansion.tag != '':
|
||||
slots.append((expansion.tag, expansion.current_match))
|
||||
return
|
||||
|
||||
for child in expansion.children:
|
||||
self.get_slots(child, slots)
|
||||
|
||||
if not expansion.children and isinstance(expansion, jsgf.NamedRuleRef):
|
||||
self.get_slots(expansion.referenced_rule.expansion, slots)
|
||||
|
||||
def get_dialog_act(self, rule):
|
||||
slots = []
|
||||
self.get_slots(rule.expansion, slots)
|
||||
return {'act': rule.grammar.name, 'slots': slots}
|
||||
|
21
grammar.jsgf
Normal file
21
grammar.jsgf
Normal file
@ -0,0 +1,21 @@
|
||||
#JSGF V1.0 UTF-8 pl;
|
||||
|
||||
grammar book;
|
||||
|
||||
public <rezerwuj> = [chciałbym] zarezerwować [hotel] [<dzien_rezerwacji>] [<godzina_rezerwacji>] [<liczba_osob>] ;
|
||||
|
||||
<dzien_rezerwacji> = na <dzien> {day};
|
||||
|
||||
<dzien> = dzisiaj | jutro | poniedziałek | wtorek | środę | czwartek | piątek | sobotę | niedzielę;
|
||||
|
||||
<godzina_rezerwacji> = na [godzinę] <godzina_z_minutami> {hour};
|
||||
|
||||
<godzina_z_minutami> = <godzina> [<minuty>];
|
||||
|
||||
<godzina> = dziewiątą | dziesiątą | jedenastą | dwunastą;
|
||||
|
||||
<minuty> = pietnaście | trzydzieści;
|
||||
|
||||
<liczba_osob> = (na | dla) <liczba> {size} (osób | osoby);
|
||||
|
||||
<liczba> = dwie | dwóch | trzy | trzech | cztery | czterech | pięć | pieciu;
|
Loading…
Reference in New Issue
Block a user