notice

This is unreleased documentation for Rasa Open Source Documentation Master/Unreleased version.
For the latest released documentation, see the latest version (2.0.x).

Version: Master/Unreleased

rasa.shared.core.domain

InvalidDomain Objects

class InvalidDomain(RasaException)

Exception that can be raised when domain is not valid.

ActionNotFoundException Objects

class ActionNotFoundException(ValueError, RasaException)

Raised when an action name could not be found.

Domain Objects

class Domain()

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

| @classmethod
| from_directory(cls, path: Text) -> "Domain"

Loads and merges multiple domain files recursively from a directory tree.

merge

| merge(domain: Optional["Domain"], override: bool = False) -> "Domain"

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

| @rasa.shared.utils.common.lazy_property
| retrieval_intents() -> List[Text]

List retrieval intents present in the domain.

collect_entity_properties

| @classmethod
| collect_entity_properties(cls, domain_entities: List[Union[Text, Dict[Text, Any]]]) -> Tuple[List[Text], Dict[Text, List[Text]], Dict[Text, List[Text]]]

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

| @classmethod
| collect_intent_properties(cls, intents: List[Union[Text, Dict[Text, Any]]], entities: List[Text], roles: Dict[Text, List[Text]], groups: Dict[Text, List[Text]]) -> Dict[Text, Dict[Text, Union[bool, List]]]

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.

__deepcopy__

| __deepcopy__(memo: Optional[Dict[int, Any]]) -> "Domain"

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.

user_actions_and_forms

| @rasa.shared.utils.common.lazy_property
| user_actions_and_forms()

Returns combination of user actions and forms.

num_actions

| @rasa.shared.utils.common.lazy_property
| num_actions()

Returns the number of available actions.

num_states

| @rasa.shared.utils.common.lazy_property
| num_states()

Number of used input states for the action prediction.

retrieval_intent_templates

| @rasa.shared.utils.common.lazy_property
| retrieval_intent_templates() -> Dict[Text, List[Dict[Text, Any]]]

Return only the templates which are defined for retrieval intents

is_retrieval_intent_template

| @staticmethod
| is_retrieval_intent_template(template: Tuple[Text, List[Dict[Text, Any]]]) -> bool

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

| add_categorical_slot_default_value() -> None

Add a default value to all categorical slots.

All unseen values found for the slot will be mapped to this default value for featurization.

add_requested_slot

| add_requested_slot() -> None

Add a slot called requested_slot to the list of slots.

The value of this slot will hold the name of the slot which the user needs to fill in next (either explicitly or implicitly) as part of a form.

add_knowledge_base_slots

| add_knowledge_base_slots() -> None

Add slots for the knowledge base action to the list of slots, if the default knowledge base action name is present.

As soon as the knowledge base action is not experimental anymore, we should consider creating a new section in the domain file dedicated to knowledge base slots.

index_for_action

| index_for_action(action_name: Text) -> Optional[int]

Look up which action index corresponds to this action name.

slot_states

| @rasa.shared.utils.common.lazy_property
| slot_states() -> List[Text]

Returns all available slot state strings.

entity_states

| @rasa.shared.utils.common.lazy_property
| entity_states() -> List[Text]

Returns all available entity state strings.

concatenate_entity_labels

| @staticmethod
| concatenate_entity_labels(entity_labels: Dict[Text, List[Text]], entity: Optional[Text] = None) -> List[Text]

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

| @rasa.shared.utils.common.lazy_property
| input_state_map() -> Dict[Text, int]

Provide a mapping from state names to indices.

input_states

| @rasa.shared.utils.common.lazy_property
| input_states() -> List[Text]

Returns all available states.

get_active_states

| get_active_states(tracker: "DialogueStateTracker") -> State

Return a bag of active states from the tracker state.

states_for_tracker_history

| states_for_tracker_history(tracker: "DialogueStateTracker") -> List[State]

Array of states for each state of the trackers history.

persist_specification

| persist_specification(model_path: Text) -> None

Persist the domain specification to storage.

load_specification

| @classmethod
| load_specification(cls, path: Text) -> Dict[Text, Any]

Load a domains specification from a dumped model directory.

compare_with_specification

| compare_with_specification(path: Text) -> bool

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.

cleaned_domain

| cleaned_domain() -> Dict[Text, Any]

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

| persist(filename: Union[Text, Path]) -> None

Write domain to a file.

persist_clean

| persist_clean(filename: Union[Text, Path]) -> None

Write cleaned domain to a file.

intent_config

| intent_config(intent_name: Text) -> Dict[Text, Any]

Return the configuration for an intent.

domain_warnings

| domain_warnings(intents: Optional[Union[List[Text], Set[Text]]] = None, entities: Optional[Union[List[Text], Set[Text]]] = None, actions: Optional[Union[List[Text], Set[Text]]] = None, slots: Optional[Union[List[Text], Set[Text]]] = None) -> Dict[Text, Dict[Text, Set[Text]]]

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

| check_missing_templates() -> None

Warn user of utterance names which have no specified template.

is_empty

| is_empty() -> bool

Check whether the domain is empty.

is_domain_file

| @staticmethod
| is_domain_file(filename: Text) -> bool

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

| slot_mapping_for_form(form_name: Text) -> Dict[Text, Any]

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.