You've already forked ui-cviko1
zložitejšie otázky
This commit is contained in:
@@ -2,17 +2,17 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"< I go by AI-BOT\n",
|
"we have to wait for the lake will be frozen\n",
|
||||||
"< it's sunny today\n",
|
"How long have you been felting happy today?\n",
|
||||||
"< we have to wait for the lake to be frozen\n",
|
"Can you elaborate on that?\n",
|
||||||
"< it's sunny today\n",
|
"What makes you think you like hockey, don't yoourself?\n",
|
||||||
"< Bye\n"
|
"< Bye\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -29,23 +29,70 @@
|
|||||||
"]\n",
|
"]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"responses = {\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",
|
" \"my name is AI-BOT\",\n",
|
||||||
" \"they call me AI-BOT\",\n",
|
" \"they call me AI-BOT\",\n",
|
||||||
" \"I go by AI-BOT\"\n",
|
" \"I go by AI-BOT\",\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
" \"weather\": [\n",
|
" \"(.*) weather(.*)\": [\"the weather is sunny\", \"it's sunny today\"],\n",
|
||||||
" \"the weather is sunny\",\n",
|
" \"(.*) hockey(.*)\": [\n",
|
||||||
" \"it's sunny today\"\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",
|
||||||
" \"hockey\": [\n",
|
|
||||||
" \"good winter time!\",\n",
|
|
||||||
" \"we have to wait for the lake to be frozen\"\n",
|
|
||||||
" ]\n",
|
|
||||||
"}\n",
|
"}\n",
|
||||||
"\n",
|
"\n",
|
||||||
"communication_stack = []\n",
|
"def match_response(message):\n",
|
||||||
"intent_database = [key for key in responses.keys()]\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",
|
"\n",
|
||||||
"while True:\n",
|
"while True:\n",
|
||||||
" message = input(\"> \")\n",
|
" message = input(\"> \")\n",
|
||||||
@@ -54,17 +101,7 @@
|
|||||||
" print(\"< Bye\")\n",
|
" print(\"< Bye\")\n",
|
||||||
" break\n",
|
" break\n",
|
||||||
" \n",
|
" \n",
|
||||||
" message = re.sub(\"[ ,.?!:;]\", \" \", message)\n",
|
" print(match_response(message))"
|
||||||
" 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))"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user