rasa/core/domain.py
def check_domain_sanity(domain):
    """Make sure the domain is properly configured.

    Checks the settings and checks if there are duplicate actions,
    intents, slots and entities."""

    def get_duplicates(my_items):
        """Returns a list of duplicate items in my_items."""

        return [item
                for item, count in collections.Counter(my_items).items()
                if count > 1]

    def check_mappings(intent_properties):
        """Check whether intent-action mappings use proper action names."""

        incorrect = list()
        for intent, properties in intent_properties.items():
            if 'triggers' in properties:
                if properties.get('triggers') not in domain.action_names:
                    incorrect.append((intent, properties['triggers']))
        return incorrect

    def get_exception_message(
            duplicates: Optional[List[Tuple[List[Text], Text]]] = None,
            mappings: List[Tuple[Text, Text]] = None):
        """Return a message given a list of error locations."""

        message = ""
        if duplicates:
            message += get_duplicate_exception_message(duplicates)
        if mappings:
            if message:
                message += "\n"
            message += get_mapping_exception_message(mappings)
        return message

    def get_mapping_exception_message(mappings: List[Tuple[Text, Text]]):
        """Return a message given a list of duplicates."""

        message = ""
        for name, action_name in mappings:
            if message:
                message += "\n"
            message += ("Intent '{}' is set to trigger action '{}', which is "
                        "not defined in the domain.".format(name, action_name))
        return message

    def get_duplicate_exception_message(
        duplicates: List[Tuple[List[Text], Text]]
    ) -> Text:
        """Return a message given a list of duplicates."""

        message = ""
        for d, name in duplicates:
            if d:
                if message:
                    message += "\n"
                message += ("Duplicate {0} in domain. "
                            "These {0} occur more than once in "
                            "the domain: {1}".format(name, ", ".join(d)))
        return message

    duplicate_actions = get_duplicates(domain.action_names)
    duplicate_intents = get_duplicates(domain.intents)
    duplicate_slots = get_duplicates([s.name for s in domain.slots])
    duplicate_entities = get_duplicates(domain.entities)
    incorrect_mappings = check_mappings(domain.intent_properties)

    if (duplicate_actions or duplicate_intents or duplicate_slots or
            duplicate_entities or incorrect_mappings):
        raise InvalidDomain(get_exception_message([
            (duplicate_actions, "actions"),
            (duplicate_intents, "intents"),
            (duplicate_slots, "slots"),
            (duplicate_entities, "entities")], incorrect_mappings))
Make sure the domain is properly configured.

    Checks the settings and checks if there are duplicate actions,
    intents, slots and entities.
Make sure the domain is properly configured.
Checks the settings and checks if there are duplicate actions,
intents, slots and entities.
Make sure the domain is properly configured . Checks the settings and checks if there are duplicate actions intents slots and entities .
def check_domain_sanity(domain):
    def get_duplicates(my_items):
        return [item
                for item, count in collections.Counter(my_items).items()
                if count > 1]
    def check_mappings(intent_properties):
        incorrect = list()
        for intent, properties in intent_properties.items():
            if 'triggers' in properties:
                if properties.get('triggers') not in domain.action_names:
                    incorrect.append((intent, properties['triggers']))
        return incorrect
    def get_exception_message(
            duplicates: Optional[List[Tuple[List[Text], Text]]] = None,
            mappings: List[Tuple[Text, Text]] = None):
        message = ""
        if duplicates:
            message += get_duplicate_exception_message(duplicates)
        if mappings:
            if message:
                message += "\n"
            message += get_mapping_exception_message(mappings)
        return message
    def get_mapping_exception_message(mappings: List[Tuple[Text, Text]]):
        message = ""
        for name, action_name in mappings:
            if message:
                message += "\n"
            message += ("Intent '{}' is set to trigger action '{}', which is "
                        "not defined in the domain.".format(name, action_name))
        return message
    def get_duplicate_exception_message(
        duplicates: List[Tuple[List[Text], Text]]
    ) -> Text:
        message = ""
        for d, name in duplicates:
            if d:
                if message:
                    message += "\n"
                message += ("Duplicate {0} in domain. "
                            "These {0} occur more than once in "
                            "the domain: {1}".format(name, ", ".join(d)))
        return message
    duplicate_actions = get_duplicates(domain.action_names)
    duplicate_intents = get_duplicates(domain.intents)
    duplicate_slots = get_duplicates([s.name for s in domain.slots])
    duplicate_entities = get_duplicates(domain.entities)
    incorrect_mappings = check_mappings(domain.intent_properties)
    if (duplicate_actions or duplicate_intents or duplicate_slots or
            duplicate_entities or incorrect_mappings):
        raise InvalidDomain(get_exception_message([
            (duplicate_actions, "actions"),
            (duplicate_intents, "intents"),
            (duplicate_slots, "slots"),
            (duplicate_entities, "entities")], incorrect_mappings))
def check_domain_sanity ( domain ) : def get_duplicates ( my_items ) : """Returns a list of duplicate items in my_items.""" return [ item for item , count in collections . Counter ( my_items ) . items ( ) if count > 1 ] def check_mappings ( intent_properties ) : """Check whether intent-action mappings use proper action names.""" incorrect = list ( ) for intent , properties in intent_properties . items ( ) : if 'triggers' in properties : if properties . get ( 'triggers' ) not in domain . action_names : incorrect . append ( ( intent , properties [ 'triggers' ] ) ) return incorrect def get_exception_message ( duplicates : Optional [ List [ Tuple [ List [ Text ] , Text ] ] ] = None , mappings : List [ Tuple [ Text , Text ] ] = None ) : """Return a message given a list of error locations.""" message = "" if duplicates : message += get_duplicate_exception_message ( duplicates ) if mappings : if message : message += "\n" message += get_mapping_exception_message ( mappings ) return message def get_mapping_exception_message ( mappings : List [ Tuple [ Text , Text ] ] ) : """Return a message given a list of duplicates.""" message = "" for name , action_name in mappings : if message : message += "\n" message += ( "Intent '{}' is set to trigger action '{}', which is " "not defined in the domain." . format ( name , action_name ) ) return message def get_duplicate_exception_message ( duplicates : List [ Tuple [ List [ Text ] , Text ] ] ) -> Text : """Return a message given a list of duplicates.""" message = "" for d , name in duplicates : if d : if message : message += "\n" message += ( "Duplicate {0} in domain. " "These {0} occur more than once in " "the domain: {1}" . format ( name , ", " . join ( d ) ) ) return message duplicate_actions = get_duplicates ( domain . action_names ) duplicate_intents = get_duplicates ( domain . intents ) duplicate_slots = get_duplicates ( [ s . name for s in domain . slots ] ) duplicate_entities = get_duplicates ( domain . entities ) incorrect_mappings = check_mappings ( domain . intent_properties ) if ( duplicate_actions or duplicate_intents or duplicate_slots or duplicate_entities or incorrect_mappings ) : raise InvalidDomain ( get_exception_message ( [ ( duplicate_actions , "actions" ) , ( duplicate_intents , "intents" ) , ( duplicate_slots , "slots" ) , ( duplicate_entities , "entities" ) ] , incorrect_mappings ) )
Make sure the domain is properly configured.
Make sure the domain is properly configured .
"""Make sure the domain is properly configured.

    Checks the settings and checks if there are duplicate actions,
    intents, slots and entities.""" """Returns a list of duplicate items in my_items.""" """Check whether intent-action mappings use proper action names.""" """Return a message given a list of error locations.""" """Return a message given a list of duplicates.""" """Return a message given a list of duplicates."""
domain