rasa.shared.core.domain
InvalidDomain Objects
Exception that can be raised when domain is not valid.
ActionNotFoundException Objects
Raised when an action name could not be found.
Domain Objects
The domain specifies the universe in which the bot's policy acts.
A Domain subclass provides the actions the bot can take, the intents and entities it can recognise.
from_directory
Loads and merges multiple domain files recursively from a directory tree.
merge
Merge this domain with another one, combining their attributes.
List attributes like intents
and actions
will be deduped
and merged. Single attributes will be taken from self
unless
override is True
, in which case they are taken from domain
.
retrieval_intents
List retrieval intents present in the domain.
collect_entity_properties
Get entity properties for a domain from what is provided by a domain file.
Arguments:
domain_entities
- The entities as provided by a domain file.
Returns:
A list of entity names. A dictionary of entity names to roles. A dictionary of entity names to groups.
collect_intent_properties
Get intent properties for a domain from what is provided by a domain file.
Arguments:
intents
- The intents as provided by a domain file.entities
- All entities as provided by a domain file.roles
- The roles of entities as provided by a domain file.groups
- The groups of entities as provided by a domain file.
Returns:
The intent properties to be stored in the domain.
__init__
Creates a Domain
.
Arguments:
intents
- Intent labels.entities
- The names of entities which might be present in user messages.slots
- Slots to store information during the conversation.templates
- Bot responses. If an action with the same name is executed, it will send the matching response to the user.action_names
- Names of custom actions.forms
- Form names and their slot mappings.action_texts
- End-to-End bot utterances from end-to-end stories.store_entities_as_slots
- IfTrue
Rasa will automatically createSlotSet
events for entities if there are slots with the same name as the entity.session_config
- Configuration for conversation sessions. Conversations are restarted at the end of a session.
__deepcopy__
Enables making a deep copy of the Domain
using copy.deepcopy
.
See https://docs.python.org/3/library/copy.html#copy.deepcopy for more implementation.
Arguments:
memo
- Optional dictionary of objects already copied during the current copying pass.
Returns:
A deep copy of the current domain.
__hash__
Returns a unique hash for the domain.
fingerprint
Returns a unique hash for the domain which is stable across python runs.
Returns:
fingerprint of the domain
user_actions_and_forms
Returns combination of user actions and forms.
action_names
Returns action names or texts.
num_actions
Returns the number of available actions.
num_states
Number of used input states for the action prediction.
retrieval_intent_templates
Return only the templates which are defined for retrieval intents
is_retrieval_intent_template
Check if the response template is for a retrieval intent.
These templates have a /
symbol in their name. Use that to filter them from the rest.
add_categorical_slot_default_value
See _add_categorical_slot_default_value
for docstring.
add_requested_slot
See _add_categorical_slot_default_value
for docstring.
add_knowledge_base_slots
See _add_categorical_slot_default_value
for docstring.
index_for_action
Looks up which action index corresponds to this action name.
raise_action_not_found_exception
Raises exception if action name or text not part of the domain or stories.
Arguments:
action_name_or_text
- Name of an action or its text in case it's an end-to-end bot utterance.
Raises:
ActionNotFoundException
- Ifaction_name_or_text
are not part of this domain.
random_template_for
Returns a random response for an action name.
Arguments:
utter_action
- The name of the utter action.
Returns:
A response for an utter action.
slot_states
Returns all available slot state strings.
entity_states
Returns all available entity state strings.
concatenate_entity_labels
Concatenates the given entity labels with their corresponding sub-labels.
If a specific entity label is given, only this entity label will be concatenated with its corresponding sub-labels.
Arguments:
entity_labels
- A map of an entity label to its sub-label list.entity
- If present, only this entity will be considered.
Returns:
A list of labels.
input_state_map
Provide a mapping from state names to indices.
input_states
Returns all available states.
get_active_states
Return a bag of active states from the tracker state.
states_for_tracker_history
Array of states for each state of the trackers history.
persist_specification
Persist the domain specification to storage.
load_specification
Load a domains specification from a dumped model directory.
compare_with_specification
Compare the domain spec of the current and the loaded domain.
Throws exception if the loaded domain specification is different to the current domain are different.
as_dict
Return serialized Domain
.
get_responses_with_multilines
Returns responses
with preserved multilines in the text
key.
Arguments:
responses
- Originalresponses
.
Returns:
responses
with preserved multilines in the text
key.
cleaned_domain
Fetch cleaned domain to display or write into a file.
The internal used_entities
property is replaced by use_entities
or
ignore_entities
and redundant keys are replaced with default values
to make the domain easier readable.
Returns:
A cleaned dictionary version of the domain.
persist
Write domain to a file.
persist_clean
Write cleaned domain to a file.
as_yaml
Dump the Domain
object as a YAML string.
This function preserves the orders of the keys in the domain.
Arguments:
clean_before_dump
- When set toTrue
, this method returns a version of the domain without internal information. Defaults toFalse
.
Returns:
A string in YAML format representing the domain.
intent_config
Return the configuration for an intent.
domain_warnings
Generate domain warnings from intents, entities, actions and slots.
Returns a dictionary with entries for intent_warnings
,
entity_warnings
, action_warnings
and slot_warnings
. Excludes domain slots
from domain warnings in case they are not featurized.
check_missing_templates
Warn user of utterance names which have no specified template.
is_empty
Check whether the domain is empty.
is_domain_file
Checks whether the given file path is a Rasa domain file.
Arguments:
filename
- Path of the file which should be checked.
Returns:
True
if it's a domain file, otherwise False
.
Raises:
YamlException
- if the file seems to be a YAML file (extension) but can not be read / parsed.
slot_mapping_for_form
Retrieve the slot mappings for a form which are defined in the domain.
Options:
- an extracted entity
- intent: value pairs
- trigger_intent: value pairs
- a whole message or a list of them, where the first match will be picked
Arguments:
form_name
- The name of the form.
Returns:
The slot mapping or an empty dictionary in case no mapping was found.
SlotMapping Objects
Defines the available slot mappings.
__str__
Returns a string representation of the object.
validate
Validates a slot mapping.
Arguments:
mapping
- The mapping which is validated.form_name
- The name of the form which uses this slot mapping.slot_name
- The name of the slot which is mapped by this mapping.
Raises:
InvalidDomain
- In case the slot mapping is not valid.