Generic_DialogSystem/template_nlg.ipynb

257 lines
6.7 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
2023-06-01 13:28:39 +02:00
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"\n",
"def nlg(system_act):\n",
" domain, intent, slot, value = system_act\n",
"\n",
" if intent == 'Affirm':\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return 'Tak'\n",
" elif r == 2:\n",
" return 'Zgadza się'\n",
" else:\n",
" return 'Potwierdzam'\n",
2023-06-01 13:27:55 +02:00
" \n",
" if intent == 'Deny':\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return 'Nie'\n",
" elif r == 2:\n",
" return 'Nie zgadza się'\n",
" else:\n",
" return 'Nie potwierdzam'\n",
" \n",
" if intent == 'Canthelp':\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return 'Przepraszam, ale obawiam się, że nie mogę tego zrobić'\n",
" elif r == 2:\n",
" return 'Wystąpił błąd, proszę się skontaktować z obsługą'\n",
" else:\n",
" return 'ERR://23¤Y%/'\n",
" \n",
2023-06-01 13:27:55 +02:00
" if intent == 'Hellomsg':\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return 'Witaj'\n",
" elif r == 2:\n",
" return 'Cześć'\n",
" else:\n",
" return 'Dzień dobry'\n",
" \n",
" if intent == 'Bye':\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return 'Do zobaczenia'\n",
" elif r == 2:\n",
" return 'Żegnaj'\n",
" else:\n",
" return 'Buk zapłać'\n",
" \n",
" \n",
"\n",
" if domain == 'Product':\n",
" if intent == 'Inform':\n",
" if slot == 'Quantity':\n",
" if value == 0:\n",
" return f'Nie znalazłem produktów spełniających podane kryteria.'\n",
" elif value == 1:\n",
" return f'Znalazłem jeden produkt spełniającą podane kryteria.'\n",
" elif value <= 4:\n",
" return f'Znalazłem {value} produkty spełniające podane kryteria.'\n",
" elif value <= 9:\n",
" return f'Znalazłem {value} produktów spełniających podane kryteria.'\n",
" else:\n",
" return f'Znalazłem wiele produktów spełniających podane kryteria.'\n",
" elif slot == 'Quality':\n",
" return f'Znalazłem produkt(y) jakości {value}'\n",
" elif slot == 'Price_range':\n",
" return f'Znalazłem produkt(y) w przedziale cenowym {value}'\n",
" elif slot == 'Type':\n",
" return f'Znalazłem produkt(y) typu {value}'\n",
" elif slot == 'Brand':\n",
" return f'Znalazłem produkt(y) marki {value}'\n",
" elif slot == 'Price':\n",
" return f'Znalazlem produkt(y) w cenie {value}'\n",
" if intent == 'Request':\n",
" if slot == 'CreditCardNo':\n",
" return 'Podaj nuber karty płatniczej'\n",
" if slot == 'Quantity':\n",
" return 'Podaj liczbę artykułów'\n",
" #if slot == 'Quality':\n",
" # return 'Podaj jakość produktów'\n",
" if slot == 'Type':\n",
" return 'Podaj typ produktu'\n",
" if intent == 'Recommend':\n",
" if slot == \"Name\":\n",
" r = random.randint(1, 3)\n",
"\n",
" if r == 1:\n",
" return f'Kochany użytkowniku, z całego serduszka polecam Ci {value}'\n",
" elif r == 2:\n",
" return f'Polecam {value}'\n",
" else:\n",
" return f'Mogę polecić {value}'\n",
"\n",
2023-06-01 13:27:55 +02:00
" "
]
2023-06-01 13:27:55 +02:00
},
{
"cell_type": "code",
2023-06-01 13:28:39 +02:00
"execution_count": 21,
2023-06-01 13:27:55 +02:00
"metadata": {},
2023-06-01 13:28:39 +02:00
"outputs": [
{
"data": {
"text/plain": [
"'Witaj'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['', 'Hellomsg', '', ''])"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Znalazłem produkt(y) marki RedBull'"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['Product', 'Inform', 'Brand', 'RedBull'])"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Polecam RedBull'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['Product', 'Recommend', 'Name', 'RedBull'])"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Podaj liczbę artykułów'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['Product', 'Request', 'Quantity', '?'])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Przepraszam, ale obawiam się, że nie mogę tego zrobić'"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['', 'Canthelp', '', ''])"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Do zobaczenia'"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nlg(['', 'Bye', '', ''])"
]
}
],
"metadata": {
2023-06-01 13:28:39 +02:00
"kernelspec": {
"display_name": "DialogSystems",
"language": "python",
"name": "python3"
},
"language_info": {
2023-06-01 13:28:39 +02:00
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}