-
Notifications
You must be signed in to change notification settings - Fork 4
Chatbot_examples
Nagyfi Richárd edited this page Jan 10, 2018
·
1 revision
Lara provides a list of clever tools that allow for rapid Chatbot development in Hungarian language. You can detect intentions, find named entities, cleverly remove unuseful parts of a message and much more.
The Obligatory Pizza Ordering Chatbot Example:
from lara import parser, entities
user_text = 'Szia! Szeretnék rendelni egy sajtos pizzát szalámival!'
order = {
"pizza" : [{"stem":"pizza","wordclass":"noun"}],
"cheese" : [{"stem":"sajt","wordclass":"noun"}],
"pepperoni" : [{"stem":"szalámi","wordclass":"noun"}],
"pineapple" : [{"stem":"ananász","wordclass":"noun"}],
}
order_match = parser.Intents(order).match_set(user_text)
common = entities.common()
common_match = parser.Intents(common).match_set(user_text)
if 'hi' in common_match:
print('Szia!') # kiíródik a 'Szia' miatt
if 'thx' in common_match:
print('Nagyon szívesen!') # nem fog kiíródni
if 'pizza' in order_match:
print('Ha jól értem egy pizzát szeretnél rendelni:') # kiíródik a 'pizzát' miatt
if 'cheese' in order_match:
print('sajttal') # kiíródik a 'sajtos' miatt
if 'pepperoni' in order_match:
print('szalámival') # kiíródik a 'szalámival' miatt
if 'pineapple' in order_match:
print('ananásszal') # nem íródik ki, mert bűncselekmény volna
>>> Szia!
>>> Ha jól értem egy pizzát szeretnél rendelni:
>>> sajttal
>>> szalámival
There are lots of predefined Intents, that are commonly used for understanding the user input. You can read more about the subject in the Wiki article about the entities library. Here is a smarter version of the previous example, that responds to certain small talk topics as well:
from lara import parser, entities
user_text = 'Szia! Nem akarok rendelni semmit, csak érdekel, hogy hogy vagy!'
order = {
"pizza" : [{"stem":"pizza","wordclass":"noun"}],
"cheese" : [{"stem":"sajt","wordclass":"noun"}],
"pepperoni" : [{"stem":"szalámi","wordclass":"noun"}],
"pineapple" : [{"stem":"ananász","wordclass":"noun"}],
}
order_match = parser.Intents(order).match_set(user_text)
common = entities.common()
common_match = parser.Intents(common).match_set(user_text)
smalltalk = entities.smalltalk()
smalltalk_match = parser.Intents(smalltalk).match_set(user_text)
if 'hi' in common_match:
print('Szia!') # kiíródik a 'Szia' miatt
if 'thx' in common_match:
print('Nagyon szívesen!') # nem fog kiíródni
if 'pizza' in order_match:
print('Ha jól értem egy pizzát szeretnél rendelni:') # nem fog kiíródni
if 'cheese' in order_match:
print('sajttal') # nem fog kiíródni
if 'pepperoni' in order_match:
print('szalámival') # nem fog kiíródni
if 'pineapple' in order_match:
print('ananásszal') # nem fog kiíródni
elif smalltalk_match:
# nem valódi rendelés, csak beszélgetni akar az user
if 'are_you_hungry' in smalltalk_match:
print('Én éhes vagyok, ha te is az vagy, tudsz tőlem pizzát rendelni!') # nem fog kiíródni
elif 'how_are_you' in smalltalk_match:
print('Egész jól, annak ellenére, hogy egy Chatbot AI vagyok!')
>>> Szia!
>>> Egész jól, annak ellenére, hogy egy Chatbot AI vagyok!
You can find further examples and use cases in the repository's examples\
folder.