From d436e7ae37f07e5e8a724911068e14046d218368 Mon Sep 17 00:00:00 2001 From: emkarcinos Date: Wed, 9 Mar 2022 13:00:05 +0100 Subject: [PATCH 1/4] Initial file --- elisa_pl.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 elisa_pl.py diff --git a/elisa_pl.py b/elisa_pl.py new file mode 100644 index 0000000..4648e70 --- /dev/null +++ b/elisa_pl.py @@ -0,0 +1 @@ +print("Hello, World!") \ No newline at end of file -- 2.20.1 From eabfa933d2de900f50f6a7e5471e43cff67f58aa Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 13 Mar 2022 22:04:59 +0100 Subject: [PATCH 2/4] Initial implementation --- elisa_pl.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/elisa_pl.py b/elisa_pl.py index 4648e70..82cb250 100644 --- a/elisa_pl.py +++ b/elisa_pl.py @@ -1 +1,49 @@ -print("Hello, World!") \ No newline at end of file +import re +import random + +ARG_LITERAL = '%' +GOODBYES =["Do zobaczenia", "Elo"] +QUIT = "wyjscie" + +pairs = ( ('test (.*)', ('%1',)), ('test2 (.*)', ('%1 2',)) ) + + +def main(): + is_running = True + while is_running: + user_input = input().lower() + + if should_quit(user_input): + is_running = False + continue + + for pair in pairs: + search = re.search(pair[0].lower(), user_input) + + if not search: + continue + + ans = pick_answer(pair) + print(substitute_arg(ans, search.groups())) + + print(random.choice(GOODBYES)) + + +def should_quit(input): + return QUIT in input + + +def substitute_arg(pattern, sub): + # TODO: More than one argument support + arg = ARG_LITERAL + '1' + return pattern.replace(arg, sub[0]) + + +def pick_answer(pair): + assert len(pair) == 2 + idx = random.randint(0, len(pair[1]) - 1) + return pair[1][idx] + + +if __name__ == "__main__": + main() \ No newline at end of file -- 2.20.1 From 70b370e64d125247ac708ea827c0a2a05cb51e54 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 14 Mar 2022 22:14:08 +0100 Subject: [PATCH 3/4] Added multiple arg support --- elisa_pl.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/elisa_pl.py b/elisa_pl.py index 82cb250..c2cbde9 100644 --- a/elisa_pl.py +++ b/elisa_pl.py @@ -1,11 +1,14 @@ +from ast import arg +from dataclasses import replace import re import random ARG_LITERAL = '%' +MAX_ARGS = 5 GOODBYES =["Do zobaczenia", "Elo"] QUIT = "wyjscie" -pairs = ( ('test (.*)', ('%1',)), ('test2 (.*)', ('%1 2',)) ) +pairs = ( ('test (.*)', ('%1',)), ('(.*) test2 (.*)', ('%1 2 %2',)), ('test2 (.*)', ('%1 2',)) ) def main(): @@ -24,7 +27,8 @@ def main(): continue ans = pick_answer(pair) - print(substitute_arg(ans, search.groups())) + print(replace_args(ans, search)) + break; print(random.choice(GOODBYES)) @@ -33,10 +37,24 @@ def should_quit(input): return QUIT in input -def substitute_arg(pattern, sub): - # TODO: More than one argument support - arg = ARG_LITERAL + '1' - return pattern.replace(arg, sub[0]) +def get_full_arg_str(arg_number): + return ARG_LITERAL + str(arg_number) + + +def replace_args(pattern, match): + arg_number = 1 + result = pattern + while arg_number <= MAX_ARGS: + if get_full_arg_str(arg_number) in result: + result = substitute_arg(result, match.group(arg_number), arg_number) + arg_number += 1 + + return result + + +def substitute_arg(pattern, sub, group_number): + arg = get_full_arg_str(group_number) + return pattern.replace(arg, sub) def pick_answer(pair): -- 2.20.1 From c17dc9e86d4d9b5678d92c85aef3c6fb65e9995d Mon Sep 17 00:00:00 2001 From: Karol Idaszak Date: Tue, 15 Mar 2022 23:07:59 +0100 Subject: [PATCH 4/4] add dialog pairs --- elisa_pl.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/elisa_pl.py b/elisa_pl.py index c2cbde9..db0873c 100644 --- a/elisa_pl.py +++ b/elisa_pl.py @@ -5,10 +5,21 @@ import random ARG_LITERAL = '%' MAX_ARGS = 5 -GOODBYES =["Do zobaczenia", "Elo"] +GOODBYES = ["Do zobaczenia", "Elo"] QUIT = "wyjscie" -pairs = ( ('test (.*)', ('%1',)), ('(.*) test2 (.*)', ('%1 2 %2',)), ('test2 (.*)', ('%1 2',)) ) +pairs = ( + ('test (.*)', ('%1',)), + ('(.*) test2 (.*)', ('%1 2 %2',)), + ('test2 (.*)', ('%1 2',)), + ('dobrze|świetnie|swietnie|super', ('To świetnie! Opowiedz mi dlaczego', 'To bardzo dobrze! Z jakiego powodu?')), + ('źle|zle|do bani|słabo|slabo', ('Przykro mi. Czhesz o tym porozmawiać?', 'To bardzo dobrze! Z jakiego powodu?')), + ('tak|nie', ('ok', ':)', 'mhm', 'okej')), + ('lubi[eę] (.*)', ('Ja też! :D Co Ci się w tym najbardziej podoba?', 'Powiedz mi więcej o %1')), + ('marz[eę] o (.*)', ('Nie przejmój się, kiedyś się uda!', 'Hmm... A dlaczego akurat o %1?')), + ('powiedz (.*)', ('%1', '%1, nie jestem botem :/')), + ('(.*)', ('Hmm... Interesujące... Opowiedz mi więcej o %1', 'Powiedz mi więcej o %1')), # '(.*)' to jest odpowiedź na "wszystko", musi być na końcu listy! + ) def main(): @@ -64,4 +75,5 @@ def pick_answer(pair): if __name__ == "__main__": - main() \ No newline at end of file + print("Hej jestem Elize! Jak się czujesz?") + main() -- 2.20.1