zložitejšie otázky

This commit is contained in:
2025-02-26 10:36:06 +01:00
parent 67cea6ab93
commit d9615ed4ca

View File

@@ -2,17 +2,17 @@
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"< I go by AI-BOT\n",
"< it's sunny today\n",
"< we have to wait for the lake to be frozen\n",
"< it's sunny today\n",
"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"
]
}
@@ -29,23 +29,70 @@
"]\n",
"\n",
"responses = {\n",
" \"name\": [\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",
" \"I go by AI-BOT\",\n",
" ],\n",
" \"weather\": [\n",
" \"the weather is sunny\",\n",
" \"it's sunny today\"\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",
" \"hockey\": [\n",
" \"good winter time!\",\n",
" \"we have to wait for the lake to be frozen\"\n",
" ]\n",
"}\n",
"\n",
"communication_stack = []\n",
"intent_database = [key for key in responses.keys()]\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",
@@ -54,17 +101,7 @@
" print(\"< Bye\")\n",
" break\n",
" \n",
" message = re.sub(\"[ ,.?!:;]\", \" \", message)\n",
" words = message.split()\n",
"\n",
" for word in words:\n",
" if word in intent_database:\n",
" communication_stack.append(word)\n",
" \n",
" if communication_stack:\n",
" print(\"<\", random.choice(responses[communication_stack.pop()]))\n",
" else:\n",
" print(\"<\", random.choice(no_responses))"
" print(match_response(message))"
]
},
{