rasa/core/domain.py
def merge(self, domain: '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``."""

        domain_dict = domain.as_dict()
        combined = self.as_dict()

        def merge_dicts(d1, d2, override_existing_values=False):
            if override_existing_values:
                a, b = d1.copy(), d2.copy()
            else:
                a, b = d2.copy(), d1.copy()
            a.update(b)
            return a

        def merge_lists(l1, l2):
            return list(set(l1 + l2))

        if override:
            for key, val in domain_dict['config'].items():
                combined['config'][key] = val

        # intents is list of dicts
        intents_1 = {list(i.keys())[0]: i for i in combined["intents"]}
        intents_2 = {list(i.keys())[0]: i for i in domain_dict["intents"]}
        merged_intents = merge_dicts(intents_1, intents_2, override)
        combined['intents'] = list(merged_intents.values())

        # remove existing forms from new actions
        for form in combined['forms']:
            if form in domain_dict['actions']:
                domain_dict['actions'].remove(form)

        for key in ['entities', 'actions', 'forms']:
            combined[key] = merge_lists(combined[key],
                                        domain_dict[key])

        for key in ['templates', 'slots']:
            combined[key] = merge_dicts(combined[key],
                                        domain_dict[key],
                                        override)

        return self.__class__.from_dict(combined)
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``.
Merge this domain with another one, combining their attributes.
Merge this domain with another one combining their attributes .
def merge(self, domain: 'Domain', override: bool = False) -> 'Domain':
        domain_dict = domain.as_dict()
        combined = self.as_dict()
        def merge_dicts(d1, d2, override_existing_values=False):
            if override_existing_values:
                a, b = d1.copy(), d2.copy()
            else:
                a, b = d2.copy(), d1.copy()
            a.update(b)
            return a
        def merge_lists(l1, l2):
            return list(set(l1 + l2))
        if override:
            for key, val in domain_dict['config'].items():
                combined['config'][key] = val
        intents_1 = {list(i.keys())[0]: i for i in combined["intents"]}
        intents_2 = {list(i.keys())[0]: i for i in domain_dict["intents"]}
        merged_intents = merge_dicts(intents_1, intents_2, override)
        combined['intents'] = list(merged_intents.values())
        for form in combined['forms']:
            if form in domain_dict['actions']:
                domain_dict['actions'].remove(form)
        for key in ['entities', 'actions', 'forms']:
            combined[key] = merge_lists(combined[key],
                                        domain_dict[key])
        for key in ['templates', 'slots']:
            combined[key] = merge_dicts(combined[key],
                                        domain_dict[key],
                                        override)
        return self.__class__.from_dict(combined)
def merge ( self , domain : 'Domain' , override : bool = False ) -> 'Domain' : domain_dict = domain . as_dict ( ) combined = self . as_dict ( ) def merge_dicts ( d1 , d2 , override_existing_values = False ) : if override_existing_values : a , b = d1 . copy ( ) , d2 . copy ( ) else : a , b = d2 . copy ( ) , d1 . copy ( ) a . update ( b ) return a def merge_lists ( l1 , l2 ) : return list ( set ( l1 + l2 ) ) if override : for key , val in domain_dict [ 'config' ] . items ( ) : combined [ 'config' ] [ key ] = val intents_1 = { list ( i . keys ( ) ) [ 0 ] : i for i in combined [ "intents" ] } intents_2 = { list ( i . keys ( ) ) [ 0 ] : i for i in domain_dict [ "intents" ] } merged_intents = merge_dicts ( intents_1 , intents_2 , override ) combined [ 'intents' ] = list ( merged_intents . values ( ) ) for form in combined [ 'forms' ] : if form in domain_dict [ 'actions' ] : domain_dict [ 'actions' ] . remove ( form ) for key in [ 'entities' , 'actions' , 'forms' ] : combined [ key ] = merge_lists ( combined [ key ] , domain_dict [ key ] ) for key in [ 'templates' , 'slots' ] : combined [ key ] = merge_dicts ( combined [ key ] , domain_dict [ key ] , override ) return self . __class__ . from_dict ( combined )
Merge this domain with another one, combining their attributes.
Merge this domain with another one combining their attributes .
"""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``.""" # intents is list of dicts # remove existing forms from new actions
self
domain
'Domain'
override
bool