From d49172230ab990017675dae6224cb91db9338eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Raczy=C5=84ski?= Date: Sun, 21 Apr 2024 10:09:03 +0200 Subject: [PATCH] added DST, DP and NLG classes --- DialoguePolicy.py | 8 ++++++++ DialogueStateTracker.py | 7 +++++++ Main.py | 17 +++++++++++++++++ NaturalLanguageGeneration.py | 8 ++++++++ 4 files changed, 40 insertions(+) create mode 100644 DialoguePolicy.py create mode 100644 DialogueStateTracker.py create mode 100644 NaturalLanguageGeneration.py diff --git a/DialoguePolicy.py b/DialoguePolicy.py new file mode 100644 index 0000000..544b7fe --- /dev/null +++ b/DialoguePolicy.py @@ -0,0 +1,8 @@ +class DialoguePolicy: + + def policy(self, state): + system_act = None + name = "James" + if state == "what name": + system_act = f"inform(name={name})" + return system_act diff --git a/DialogueStateTracker.py b/DialogueStateTracker.py new file mode 100644 index 0000000..1f15dbc --- /dev/null +++ b/DialogueStateTracker.py @@ -0,0 +1,7 @@ +class DialogueStateTracker: + + def dst(self, user_act): + state = None + if user_act == "request(firstname)": + state = "what name" + return state diff --git a/Main.py b/Main.py index 37f5fe1..169e8a9 100644 --- a/Main.py +++ b/Main.py @@ -1,7 +1,24 @@ from NaturalLanguageAnalyzer import NaturalLanguageAnalyzer +from DialogueStateTracker import DialogueStateTracker +from DialoguePolicy import DialoguePolicy +from NaturalLanguageGeneration import NaturalLanguageGeneration if __name__ == "__main__": text = "Cześć, jak masz na imię?" 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) + + diff --git a/NaturalLanguageGeneration.py b/NaturalLanguageGeneration.py new file mode 100644 index 0000000..a30f266 --- /dev/null +++ b/NaturalLanguageGeneration.py @@ -0,0 +1,8 @@ +class NaturalLanguageGeneration: + + def nlg(self, system_act): + response = None + name = "James" + if system_act == f"inform(name={name})": + response = f"Witaj, nazywam się {name}" + return response