pamätanie kľúčových slov

This commit is contained in:
2025-02-26 10:08:49 +01:00
parent 511b708faf
commit 4dec993539

View File

@@ -2,19 +2,17 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"< I can't understand you.\n",
"< the weather is sunny\n",
"< I don't know, sorry.\n",
"< I can't answer that.\n",
"< I don't know, sorry.\n",
"< good winter time!\n",
"< 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",
"< Bye\n"
]
}
@@ -46,6 +44,7 @@
" ]\n",
"}\n",
"\n",
"communication_stack = []\n",
"intent_database = [key for key in responses.keys()]\n",
"\n",
"while True:\n",
@@ -58,9 +57,12 @@
" message = re.sub(\"[ ,.?!:;]\", \" \", message)\n",
" words = message.split()\n",
"\n",
" intent_word = next((word for word in words if word in intent_database), None)\n",
" if intent_word != None:\n",
" print(\"<\", random.choice(responses[intent_word]))\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))"
]