You've already forked ui-cviko1
137 lines
4.5 KiB
Plaintext
137 lines
4.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"we have to wait for the lake will be frozen\n",
|
|
"How long have you been felting happy today?\n",
|
|
"Can you elaborate on that?\n",
|
|
"What makes you think you like hockey, don't yoourself?\n",
|
|
"< Bye\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import random\n",
|
|
"import re\n",
|
|
"\n",
|
|
"no_responses = [\n",
|
|
" \"I can't answer that.\",\n",
|
|
" \"I don't know, sorry.\",\n",
|
|
" \"I can't understand you.\",\n",
|
|
" \"Can you elaborate, please?\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"responses = {\n",
|
|
" \"hello\": [\"Hello, how can I help you.\"],\n",
|
|
" \"i feel (.*)\": [\"Why do you feel {}?\", \"How long have you been felting {}?\"],\n",
|
|
" \"i am (.*)\": [\"How long have you been {}?\", \"Why do you say you are {}?\"],\n",
|
|
" \"i 'm (.*)\": [\"Why are you {}?\", \"How long have you been {}?\"],\n",
|
|
" \"i (.*) you\": [\n",
|
|
" \"Why do you {} yoourself?\",\n",
|
|
" \"What makes you think you {} yoourself?\",\n",
|
|
" ],\n",
|
|
" \"i (.*) myself\": [\n",
|
|
" \"Why do you {} yoourself?\",\n",
|
|
" \"What makes you think you {} yoourself?\",\n",
|
|
" ],\n",
|
|
" \"(.*) sorry (.*)\": [\n",
|
|
" \"There is no need to apologize.\",\n",
|
|
" \"What are you apologizing for?\",\n",
|
|
" ],\n",
|
|
" \"(.*) friend (.*)\": [\n",
|
|
" \"There is no need to apologize.\",\n",
|
|
" \"What are you apologizing for?\",\n",
|
|
" ],\n",
|
|
" \"(.*) mother (.*)\": [\"Tell me more about your family.\"],\n",
|
|
" \"(.*) father (.*)\": [\"Tell me more about your family.\"],\n",
|
|
" \"yes\": [\"Why seem quite sure.\", \"OK, but can you elaborate.\"],\n",
|
|
" \"no\": [\"Why not.\", \"OK, but can you elaborate a bit?\"],\n",
|
|
" \"(.*) your name(.*)\": [\n",
|
|
" \"my name is AI-BOT\",\n",
|
|
" \"they call me AI-BOT\",\n",
|
|
" \"I go by AI-BOT\",\n",
|
|
" ],\n",
|
|
" \"(.*) weather(.*)\": [\"the weather is sunny\", \"it's sunny today\"],\n",
|
|
" \"(.*) hockey(.*)\": [\n",
|
|
" \"good winter game!\",\n",
|
|
" \"we have to wait for the lake will be frozen\",\n",
|
|
" ],\n",
|
|
" \"(.*) football (.*)\": [\n",
|
|
" \"millions of people follow their favorite team in every game\",\n",
|
|
" \"this game helps kids stay active\",\n",
|
|
" \"it is also called as “Soccer” in North America\",\n",
|
|
" \"ronaldo is the best\",\n",
|
|
" ],\n",
|
|
" \"When will our (.*) finish?\": [\n",
|
|
" \"Probably a few minutes\",\n",
|
|
" \"I dont really know, check the time maybe?\"\n",
|
|
" ],\n",
|
|
" \" (.*)\": [\n",
|
|
" \"Please tell me more.\",\n",
|
|
" \"Let's change focus a bit... tell me about your family.\",\n",
|
|
" \"Can you elaborate on that?\",\n",
|
|
" ],\n",
|
|
" \"\": [\n",
|
|
" \"Why do you think that?\",\n",
|
|
" \"Please tell me more.\",\n",
|
|
" \"Let's change focus a bit... tell me about your family.\",\n",
|
|
" \"Can you elaborate on that?\",\n",
|
|
" ],\n",
|
|
"}\n",
|
|
"\n",
|
|
"def match_response(message):\n",
|
|
" for pattern, response_list in responses.items():\n",
|
|
" matches = re.match(pattern, message.lower())\n",
|
|
" if matches:\n",
|
|
" chosen_template = random.choice(response_list)\n",
|
|
" return chosen_template.format(*matches.groups())\n",
|
|
" return \"I am sorry, I do not understand what your're saying.\"\n",
|
|
"\n",
|
|
"while True:\n",
|
|
" message = input(\"> \")\n",
|
|
"\n",
|
|
" if message == \"bye\":\n",
|
|
" print(\"< Bye\")\n",
|
|
" break\n",
|
|
" \n",
|
|
" print(match_response(message))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "ui-cviko1",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.13.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|