notice

This is unreleased documentation for Rasa Open Source Documentation Master/Unreleased version.
For the latest released documentation, see the latest version (2.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.

SessionConfig Objects

class SessionConfig(NamedTuple)

The Session Configuration.

default

@staticmethod
def default() -> "SessionConfig"

Returns the SessionConfig with the default values.

are_sessions_enabled

def are_sessions_enabled() -> bool

Returns a boolean value depending on the value of session_expiration_time.

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_file

@classmethod
def from_file(cls, path: Text) -> "Domain"

Loads the Domain from a YAML file.

from_yaml

@classmethod
def from_yaml(cls, yaml: Text, original_filename: Text = "") -> "Domain"

Loads the Domain from YAML text after validating it.

from_dict

@classmethod
def from_dict(cls, data: Dict) -> "Domain"

Deserializes and creates domain.

Arguments:

  • data - The serialized domain.

Returns:

The instantiated Domain object.

from_directory

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

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

merge

def 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
def retrieval_intents() -> List[Text]

List retrieval intents present in the domain.

collect_entity_properties

@classmethod
def 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
def 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.

__init__

def __init__(intents: Union[Set[Text], List[Text], List[Dict[Text, Any]]], entities: List[Union[Text, Dict[Text, Any]]], slots: List[Slot], responses: Dict[Text, List[Dict[Text, Any]]], action_names: List[Text], forms: Union[Dict[Text, Any], List[Text]], action_texts: Optional[List[Text]] = None, store_entities_as_slots: bool = True, session_config: SessionConfig = SessionConfig.default()) -> None

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.
  • responses - 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 - If True Rasa will automatically create SlotSet 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__

def __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.

count_conditional_response_variations

def count_conditional_response_variations() -> int

Returns count of conditional response variations.

__hash__

def __hash__() -> int

Returns a unique hash for the domain.

fingerprint

def fingerprint() -> Text

Returns a unique hash for the domain which is stable across python runs.

Returns:

fingerprint of the domain

user_actions_and_forms

@rasa.shared.utils.common.lazy_property
def user_actions_and_forms() -> List[Text]

Returns combination of user actions and forms.

num_actions

@rasa.shared.utils.common.lazy_property
def num_actions() -> int

Returns the number of available actions.

num_states

@rasa.shared.utils.common.lazy_property
def num_states() -> int

Number of used input states for the action prediction.

retrieval_intent_responses

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

Return only the responses which are defined for retrieval intents.

is_retrieval_intent_response

@staticmethod
def is_retrieval_intent_response(response: Tuple[Text, List[Dict[Text, Any]]]) -> bool

Check if the response is for a retrieval intent.

These responses have a / symbol in their name. Use that to filter them from the rest.

index_for_action

def index_for_action(action_name: Text) -> int

Looks up which action index corresponds to this action name.

raise_action_not_found_exception

def raise_action_not_found_exception(action_name_or_text: Text) -> NoReturn

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 - If action_name_or_text are not part of this domain.

slot_states

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

Returns all available slot state strings.

entity_states

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

Returns all available entity state strings.

concatenate_entity_labels

@staticmethod
def 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
def input_state_map() -> Dict[Text, int]

Provide a mapping from state names to indices.

input_states

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

Returns all available states.

get_active_state

def get_active_state(tracker: "DialogueStateTracker", omit_unset_slots: bool = False) -> State

Given a dialogue tracker, makes a representation of current dialogue state.

Arguments:

  • tracker - dialog state tracker containing the dialog so far
  • omit_unset_slots - If True do not include the initial values of slots.

Returns:

A representation of the dialogue's current state.

states_for_tracker_history

def states_for_tracker_history(tracker: "DialogueStateTracker", omit_unset_slots: bool = False, ignore_rule_only_turns: bool = False, rule_only_data: Optional[Dict[Text, Any]] = None) -> List[State]

List of states for each state of the trackers history.

Arguments:

  • tracker - Dialogue state tracker containing the dialogue so far.
  • omit_unset_slots - If True do not include the initial values of slots.
  • ignore_rule_only_turns - If True ignore dialogue turns that are present only in rules.
  • rule_only_data - Slots and loops, which only occur in rules but not in stories.

Returns:

A list of states.

slots_for_entities

def slots_for_entities(entities: List[Dict[Text, Any]]) -> List[SlotSet]

Creates slot events for entities if auto-filling is enabled.

Arguments:

  • entities - The list of entities.

Returns:

A list of SlotSet events.

persist_specification

def persist_specification(model_path: Text) -> None

Persist the domain specification to storage.

load_specification

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

Load a domains specification from a dumped model directory.

compare_with_specification

def 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.

as_dict

def as_dict() -> Dict[Text, Any]

Return serialized Domain.

get_responses_with_multilines

@staticmethod
def get_responses_with_multilines(responses: Dict[Text, List[Dict[Text, Any]]]) -> Dict[Text, List[Dict[Text, Any]]]

Returns responses with preserved multilines in the text key.

Arguments:

  • responses - Original responses.

Returns:

responses with preserved multilines in the text key.

cleaned_domain

def 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

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

Write domain to a file.

persist_clean

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

Write cleaned domain to a file.

as_yaml

def as_yaml(clean_before_dump: bool = False) -> Text

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 to True, this method returns a version of the domain without internal information. Defaults to False.

Returns:

A string in YAML format representing the domain.

intent_config

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

Return the configuration for an intent.

intents

@rasa.shared.utils.common.lazy_property
def intents() -> List[Text]

Returns sorted list of intents.

domain_warnings

def 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_responses

def check_missing_responses() -> None

Warn user of utterance names which have no specified response.

is_empty

def is_empty() -> bool

Check whether the domain is empty.

is_domain_file

@staticmethod
def 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

def 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.

SlotMapping Objects

class SlotMapping(Enum)

Defines the available slot mappings.

__str__

def __str__() -> Text

Returns a string representation of the object.

validate

@staticmethod
def validate(mapping: Dict[Text, Any], form_name: Text, slot_name: Text) -> None

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.