You've already forked ui-cviko1
Compare commits
2 Commits
5ea350c425
...
4dec993539
| Author | SHA1 | Date | |
|---|---|---|---|
|
4dec993539
|
|||
|
511b708faf
|
@@ -2,23 +2,24 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"< My name is AI-CHATBOT.\n",
|
"< I go by AI-BOT\n",
|
||||||
"< I can't do that.\n",
|
"< it's sunny today\n",
|
||||||
"< Nope.\n",
|
"< we have to wait for the lake to be frozen\n",
|
||||||
"< The sky is blue.\n",
|
"< it's sunny today\n",
|
||||||
"< Bye\n"
|
"< Bye\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import random\n",
|
"import random\n",
|
||||||
|
"import re\n",
|
||||||
"\n",
|
"\n",
|
||||||
"no_responses = [\n",
|
"no_responses = [\n",
|
||||||
" \"I can't answer that.\",\n",
|
" \"I can't answer that.\",\n",
|
||||||
@@ -28,30 +29,24 @@
|
|||||||
"]\n",
|
"]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"responses = {\n",
|
"responses = {\n",
|
||||||
" \"What's the weather like today?\": [\n",
|
" \"name\": [\n",
|
||||||
" \"It's sunny!\",\n",
|
" \"my name is AI-BOT\",\n",
|
||||||
" \"It seems sunny today.\",\n",
|
" \"they call me AI-BOT\",\n",
|
||||||
" \"Sunny.\"\n",
|
" \"I go by AI-BOT\"\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
" \"What is your name?\": [\n",
|
" \"weather\": [\n",
|
||||||
" \"My name is AI-CHATBOT.\",\n",
|
" \"the weather is sunny\",\n",
|
||||||
" \"It's AI-CHATBOT.\",\n",
|
" \"it's sunny today\"\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
" \"What's your favorite color?\": [\n",
|
" \"hockey\": [\n",
|
||||||
" \"It's yellow.\",\n",
|
" \"good winter time!\",\n",
|
||||||
" \"Yellow.\"\n",
|
" \"we have to wait for the lake to be frozen\"\n",
|
||||||
" ],\n",
|
|
||||||
" \"What color is the sky?\": [\n",
|
|
||||||
" \"The sky is blue.\",\n",
|
|
||||||
" \"It's blue.\"\n",
|
|
||||||
" ],\n",
|
|
||||||
" \"Can you talk?\": [\n",
|
|
||||||
" \"No.\",\n",
|
|
||||||
" \"Nope.\",\n",
|
|
||||||
" \"I can't do that.\"\n",
|
|
||||||
" ]\n",
|
" ]\n",
|
||||||
"}\n",
|
"}\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"communication_stack = []\n",
|
||||||
|
"intent_database = [key for key in responses.keys()]\n",
|
||||||
|
"\n",
|
||||||
"while True:\n",
|
"while True:\n",
|
||||||
" message = input(\"> \")\n",
|
" message = input(\"> \")\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -59,8 +54,15 @@
|
|||||||
" print(\"< Bye\")\n",
|
" print(\"< Bye\")\n",
|
||||||
" break\n",
|
" break\n",
|
||||||
" \n",
|
" \n",
|
||||||
" if message in responses.keys():\n",
|
" message = re.sub(\"[ ,.?!:;]\", \" \", message)\n",
|
||||||
" print(\"<\", random.choice(responses[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",
|
" else:\n",
|
||||||
" print(\"<\", random.choice(no_responses))"
|
" print(\"<\", random.choice(no_responses))"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user