129 lines
2.8 KiB
Plaintext
129 lines
2.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "556dde9c-0423-407f-b811-a084455fc723",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import re"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "8a7292e7-a5b5-41c3-bd3f-11b619ed3f12",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"name = 'Marek Suski'\n",
|
|
"\n",
|
|
"def system(text):\n",
|
|
" akt_usera = nlu(text)\n",
|
|
" print(akt_usera)\n",
|
|
" stan = dst(akt_usera)\n",
|
|
" print(stan)\n",
|
|
" akt_systemu = dialogue_policy(stan)\n",
|
|
" print(akt_systemu)\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(imie)':\n",
|
|
" state = 'need imie'\n",
|
|
" return state\n",
|
|
" \n",
|
|
" \n",
|
|
"def dialogue_policy(state):\n",
|
|
" state = state.split()\n",
|
|
" print('state: ', state)\n",
|
|
" if state[0] == 'need':\n",
|
|
" system_act = 'inform' + '(' + state[1] + ')'\n",
|
|
" return system_act\n",
|
|
" \n",
|
|
"def nlg(act):\n",
|
|
" if act == 'inform(imie)':\n",
|
|
" return name\n",
|
|
" \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "52dc2673-0590-4b9f-87bc-f19a41e00746",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Ty: jak się nazywasz?\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"request(imie)\n",
|
|
"need imie\n",
|
|
"state: ['need', 'imie']\n",
|
|
"inform(imie)\n",
|
|
"System: Marek Suski\n"
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|