systemy_dialogowe/data/architektura.ipynb

129 lines
2.8 KiB
Plaintext
Raw Normal View History

2023-04-14 12:59:04 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "556dde9c-0423-407f-b811-a084455fc723",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import re"
]
},
{
"cell_type": "code",
2023-04-14 13:11:32 +02:00
"execution_count": 13,
2023-04-14 12:59:04 +02:00
"id": "8a7292e7-a5b5-41c3-bd3f-11b619ed3f12",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"name = 'Marek Suski'\n",
"\n",
"def system(text):\n",
" akt_usera = nlu(text)\n",
2023-04-14 13:11:32 +02:00
" print(akt_usera)\n",
2023-04-14 12:59:04 +02:00
" stan = dst(akt_usera)\n",
2023-04-14 13:11:32 +02:00
" print(stan)\n",
2023-04-14 12:59:04 +02:00
" akt_systemu = dialogue_policy(stan)\n",
2023-04-14 13:11:32 +02:00
" print(akt_systemu)\n",
2023-04-14 12:59:04 +02:00
" system_msg = nlg(akt_systemu)\n",
" print('System: ' + system_msg)\n",
" \n",
"def nlu(text):\n",
" text = text.lower()\n",
" \n",
" x = re.search(\"[a-z]+ masz na imię?\", text)\n",
" y = re.search(\"[a-z]+ się nazywasz?\", text)\n",
" \n",
" if x != None or y != None:\n",
" akt = 'request(imie)'\n",
" return akt\n",
"\n",
"def dst(akt):\n",
2023-04-14 13:11:32 +02:00
" if akt == 'request(imie)':\n",
" state = 'need imie'\n",
" return state\n",
2023-04-14 12:59:04 +02:00
" \n",
" \n",
"def dialogue_policy(state):\n",
2023-04-14 13:11:32 +02:00
" state = state.split()\n",
" print('state: ', state)\n",
" if state[0] == 'need':\n",
2023-04-14 12:59:04 +02:00
" system_act = 'inform' + '(' + state[1] + ')'\n",
" return system_act\n",
" \n",
"def nlg(act):\n",
2023-04-14 13:11:32 +02:00
" if act == 'inform(imie)':\n",
" return name\n",
2023-04-14 12:59:04 +02:00
" \n"
]
},
{
"cell_type": "code",
2023-04-14 13:11:32 +02:00
"execution_count": null,
2023-04-14 12:59:04 +02:00
"id": "52dc2673-0590-4b9f-87bc-f19a41e00746",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Ty: jak się nazywasz?\n"
]
},
{
2023-04-14 13:11:32 +02:00
"name": "stdout",
"output_type": "stream",
"text": [
"request(imie)\n",
"need imie\n",
"state: ['need', 'imie']\n",
"inform(imie)\n",
"System: Marek Suski\n"
2023-04-14 12:59:04 +02:00
]
}
],
"source": [
"while True:\n",
" user_input = input('Ty:')\n",
" system(user_input)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c38739d4-de59-448e-b805-8e61a84c087a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}