From 0bae6f8d37698cdc7b29acc6f507a6e978cf6b63 Mon Sep 17 00:00:00 2001 From: Patryk Date: Sat, 23 Mar 2024 11:37:11 +0100 Subject: [PATCH] Dodanie chatbota Eliza z podstawowym zbiorem danych MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skrypt jest spolonizowaną wersją https://github.com/nltk/nltk/blob/develop/nltk/chat/eliza.py. --- eliza.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 48 insertions(+) create mode 100644 eliza.py create mode 100644 requirements.txt diff --git a/eliza.py b/eliza.py new file mode 100644 index 0000000..c9a13d8 --- /dev/null +++ b/eliza.py @@ -0,0 +1,47 @@ +from nltk.chat.util import Chat, reflections + +pairs = ( + ( + r"Potrzebuję (.*)", + ( + "Dlaczego potrzebujesz %1?", + "Jesteś pewien, że potrzebujesz %1?", + ), + ), + ( + r"koniec", + ( + "Do widzenia", + ), + ), + ( + r"(.*)", + ( + "Możesz rozwinąć?", + "Rozumiem.", + "Ciekawe.", + "%1.", + ), + ), +) + +eliza_chatbot = Chat(pairs, reflections) + + +def eliza_chat(): + print("Terapeuta\n---------") + print("Rozmawiaj po Polsku.") + print('Używaj zarówno wielkich, jak i małych lister; używaj interpunkcji.') + print('Aby zakończyć, napisz "koniec".') + print("=" * 72) + print("Witaj, jak się czujesz?") + + eliza_chatbot.converse(quit="koniec") + + +def demo(): + eliza_chat() + + +if __name__ == "__main__": + eliza_chat() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34e7188 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +nltk==3.8.1