architecture_v1

This commit is contained in:
Mikołaj Mrożewski 2023-04-14 12:59:04 +02:00
parent 90e87e62dd
commit e1d9e9944e

126
data/architektura.ipynb Normal file
View File

@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "556dde9c-0423-407f-b811-a084455fc723",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import re"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8a7292e7-a5b5-41c3-bd3f-11b619ed3f12",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"name = 'Marek Suski'\n",
"\n",
"def system(text):\n",
" akt_usera = nlu(text)\n",
" stan = dst(akt_usera)\n",
" akt_systemu = dialogue_policy(stan)\n",
" 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",
" if akt == 'request(name)':\n",
" need = 'name'\n",
" return need\n",
" \n",
" \n",
"def dialogue_policy(state):\n",
" state = state.split('(')\n",
" if state[0] == 'request':\n",
" system_act = 'inform' + '(' + state[1] + ')'\n",
" return system_act\n",
" \n",
"def nlg(act):\n",
" if act == 'request(imie)':\n",
" print('nazywam się ' + name)\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "52dc2673-0590-4b9f-87bc-f19a41e00746",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Ty: jak się nazywasz?\n"
]
},
{
"ename": "AttributeError",
"evalue": "'NoneType' object has no attribute 'split'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[10], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m 2\u001b[0m user_input \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTy:\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 3\u001b[0m \u001b[43msystem\u001b[49m\u001b[43m(\u001b[49m\u001b[43muser_input\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[1;32mIn[9], line 6\u001b[0m, in \u001b[0;36msystem\u001b[1;34m(text)\u001b[0m\n\u001b[0;32m 4\u001b[0m akt_usera \u001b[38;5;241m=\u001b[39m nlu(text)\n\u001b[0;32m 5\u001b[0m stan \u001b[38;5;241m=\u001b[39m dst(akt_usera)\n\u001b[1;32m----> 6\u001b[0m akt_systemu \u001b[38;5;241m=\u001b[39m \u001b[43mdialogue_policy\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstan\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 7\u001b[0m system_msg \u001b[38;5;241m=\u001b[39m nlg(akt_systemu)\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSystem: \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m system_msg)\n",
"Cell \u001b[1;32mIn[9], line 27\u001b[0m, in \u001b[0;36mdialogue_policy\u001b[1;34m(state)\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdialogue_policy\u001b[39m(state):\n\u001b[1;32m---> 27\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[43mstate\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m(\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 28\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m state[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrequest\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m 29\u001b[0m system_act \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minform\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m(\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m state[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'split'"
]
}
],
"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
}