Skip to content

Entities

Nagyfi Richárd edited this page Jun 14, 2018 · 33 revisions

Some intents and entities are used regularly. Lara offers built in Intents to make Chatbot development and named-entity recognition easier. The functions in this library all return a dictionary of intents, that can be used for initializing a lara.parser.Intents() class copy. You can think of this feature as a way to get built-in intents.

from lara import parser, entities

match_common	= parser.Intents( entities.common() ).match_set("Köszönöm szépen a finom ebédet!")
print(match_common)
	
>>> {"thx"}

Synonyms of certain expressions will be matched as a single intent, so you only have to check for their existence when developing a Chatbot. For instance, "szia", "helló" and "jó napot" will all be matched as {"hi"} with the lara.entities.common() Intents dictionary.

Collection Matches the following Possible intents returned
lara.entities.common() Common entities for Chatbot conversations yes, no, hi, bye, thx, pls, welks, sorry, lol, nvm, help, again, command, question, conditional, profanity, welldone, dontknow, dontunderstand
lara.entities.commands() Common menu commands for Chatbot conversations ok, cancel, next, back, save, open, delete, exit, options, menu, login, logout, error, search, undo, redo, restart, play, stop, pause, resume, skip, snooze, volume_up, volume_down, mute, unmute, order, install
lara.entities.counties() Hungarian counties and county seats bacs-kiskun, baranya, bekes, borsod-abauj-zemplen, csongrad, fejer, gyor-moson-sopron, hajdu-bihar, heves, jasz-nagykun-szolnok, komarom-esztergom, nograd, pest, somogy, szabolcs-szatmar-bereg, tolna, vas, veszprem, zala
lara.entities.dow() Days of the week. Will also match hetvege or hetkoznap when matching a day. ma, holnap, holnaputan, tegnap, tegnapelott, hetfo, kedd, szerda, csutortok, pentek, szombat, vasarnap, hetkoznap, hetvege
lara.entities.smalltalk() Common small talk topics user_love, user_flirting, user_bored, user_happy, user_sad, user_angry_at_you, user_forgiving_you, user_sorry, user_friend, user_back, user_hungry, user_thirsty, how_are_you, about_name, about_you, about_creator, about_look, about_age, about_zodiac, about_location, about_family, about_software, about_skills, about_topics, about_thoughts, about_favorite, are_you_conscious, are_you_a_robot, are_you_hungry, are_you_thirsty, are_you_busy, are_you_lying, are_you_serious, can_you_hear_me, can_you_learn, can_you_understand_me, contact, no_answer, shame
lara.entities.emoji() Matches common smileys and emojis and returns the type of feelings they represent like, dislike, happiness, sadness, laughter, love, surprise, anger, discomfort, confusion, tiredness, seduction
lara.entities.disallow() Words you wouldn't ever want your ChatBot to accidentally say, have them pop up in retrieved search results or allow as usernames, etc. obscene, racist, erotic, unpleasant
lara.entities.tone() Detects whether user sends his or her questions in a formal or informal way formal, informal

Some named entities (commands and smalltalk) might give false positive if used out of context. It is recommended that you build your Chatbot in a way, that responding to more important intents has a higher priority.

You can also remove matched entities and process the remaining parts of the text:

from lara import parser, entities

user_text	= 'Szia, köszönöm szépen a pizzát!'

match_common	= parser.Intents(entities.common()).match_set(user_text)
print(match_common)
	
if match_common:
	# vegyük ki a már megtalált részeket
	clean_user_text	= parser.Intents(entities.common()).clean(user_text)
	remainder	= parser.Extract(clean_user_text)
	print(' '.join(remainder.tokenizer())) # maradék szöveg
else:
	print(user_text) # nem fogja kiírni

>>> {'hi', 'thx'}
>>> a pizzát

It is recommended that you check and allow similar entities as valid answers based on the current context.

For instance: users might use either commands.pause, commands.stop, commands.mute or commands.exit when trying to pause a media playback. Answers like common.yes and common.no are also commonly used instead of commands.ok or commands.cancel. Make sure you handle them all accordingly.

Clone this wiki locally