grammar nlu

This commit is contained in:
Łukasz Jędyk 2021-05-16 23:11:55 +02:00
parent 79fed3fbdc
commit 8628e68e79
6 changed files with 24 additions and 14 deletions

View File

@ -15,13 +15,11 @@ class DP:
def chooseTactic(self, frameList=None) -> SystemAct:
userAct = frameList[-1]
if userAct.getActType() == UserActType.WELCOME_MSG:
if userAct.getActType() == UserActType.HELLO:
return SystemAct(SystemActType.WELCOME_MSG)
if userAct.getActType() == UserActType.REQUEST:
if "name" in userAct.getActParams():
return SystemAct(SystemActType.INFORM,['name'])
if userAct.getActType() == UserActType.BYE:
elif userAct.getActType() == UserActType.BYE:
return SystemAct(SystemActType.BYE)
if userAct.getActType() == UserActType.INVALID:
elif userAct.getActType() == UserActType.INVALID:
return SystemAct(SystemActType.NOT_UNDERSTOOD)
raise Exception("UserAct:{} not recognized".format(userAct))
else:
return SystemAct(SystemActType.INFORM,['name'])

View File

@ -10,8 +10,6 @@ class NLU:
def get_dialog_act(self, rule):
slots = []
self.get_slots(rule.expansion, slots)
print(rule)
print(slots)
return UserAct(UserActType[rule.name.upper()], slots)
def get_slots(self, expansion, slots):
@ -29,4 +27,4 @@ class NLU:
matched_rules = self.book_grammar.find_matching_rules(text)
if matched_rules:
return self.get_dialog_act(matched_rules[0])
return UserAct(UserActType.INVALID)
return UserAct(UserActType.INVALID, [])

View File

@ -6,4 +6,10 @@ class UserAct(ActFrame):
if actType != None and type(actType) is not UserActType:
raise Exception('actParams has wrong type: expected type {}, got {}'.format(type(UserActType.WELCOME_MSG), type(actType)))
super(UserAct, self).__init__(actType, actParams)
super(UserAct, self).__init__(actType, actParams)
def __str__(self):
params = []
for param in self.getActParams():
params.append('{}=\'{}\''.format(param[0], param[1]))
return '{}({})'.format(self.getActType().name.lower(), ','.join(params))

View File

@ -3,11 +3,12 @@ from enum import Enum, unique
@unique
class UserActType(Enum):
WELCOME_MSG = 0
HELLO = 0
BYE = 1
CREATE_MEETING = 2
CANCEL_MEETING = 3
CHANGE_MEETING = 4
MEETING_LIST = 5
CONFIRM = 6
THANKYOU = 7
INVALID = -1

View File

@ -2,7 +2,7 @@
grammar book;
public <create_meeting> = chciałbym (zapisać | wpisać | dodać | utworzyć | umówić) nowe* spotkanie;
public <create_meeting> = chciałbym (zapisać | wpisać | dodać | utworzyć | umówić) (nowe)* spotkanie;
public <cancel_meeting> = chciałbym (anulować | odwołać | usunąć) spotkanie;
@ -18,4 +18,10 @@ public <meeting_list> = jakie spotkania mam <meeting_date> {date};
<week_day> = w (poniedziałek | środę | czwartek | piątek | sobotę | niedzielę) | we wtorek;
public <confirm> = potwierdzam | tak
public <confirm> = potwierdzam | tak | zgadza się;
public <hello> = witam | dzień dobry | cześć | siemka | dobry wieczór | hej | hejka;
public <thankyou> = dziękuję (bardzo)*;
public <bye> = do widzenia | miłego dnia | to by było wszystko na teraz | <thankyou> to wszystko;

View File

@ -14,6 +14,7 @@ if __name__ == "__main__":
user_input = input("Wpisz tekst: ")
user_frame = nlu.parse_user_input(user_input)
print(str(user_frame))
dst.addFrame(user_frame)
system_act = dp.chooseTactic(dst.getFrames())
text = nlg.toText(system_act)