diff --git a/DialoguePolicy.py b/DialoguePolicy.py index da76f96..2bf7a1b 100644 --- a/DialoguePolicy.py +++ b/DialoguePolicy.py @@ -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']) diff --git a/NaturalLanguageUnderstanding.py b/NaturalLanguageUnderstanding.py index b9e95e8..9127206 100644 --- a/NaturalLanguageUnderstanding.py +++ b/NaturalLanguageUnderstanding.py @@ -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, []) diff --git a/UserAct.py b/UserAct.py index e644dd4..8c4cf82 100644 --- a/UserAct.py +++ b/UserAct.py @@ -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) \ No newline at end of file + 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)) diff --git a/UserActType.py b/UserActType.py index 2d0cc32..599f59a 100644 --- a/UserActType.py +++ b/UserActType.py @@ -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 diff --git a/book.jsgf b/book.jsgf index cb71c65..2beafdf 100644 --- a/book.jsgf +++ b/book.jsgf @@ -2,7 +2,7 @@ grammar book; -public = chciałbym (zapisać | wpisać | dodać | utworzyć | umówić) nowe* spotkanie; +public = chciałbym (zapisać | wpisać | dodać | utworzyć | umówić) (nowe)* spotkanie; public = chciałbym (anulować | odwołać | usunąć) spotkanie; @@ -18,4 +18,10 @@ public = jakie spotkania mam {date}; = w (poniedziałek | środę | czwartek | piątek | sobotę | niedzielę) | we wtorek; -public = potwierdzam | tak \ No newline at end of file +public = potwierdzam | tak | zgadza się; + +public = witam | dzień dobry | cześć | siemka | dobry wieczór | hej | hejka; + +public = dziękuję (bardzo)*; + +public = do widzenia | miłego dnia | to by było wszystko na teraz | to wszystko; \ No newline at end of file diff --git a/main.py b/main.py index 82825e0..35f5672 100644 --- a/main.py +++ b/main.py @@ -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)