def merge(self, *others: Optional["TrainingData"]) -> "TrainingData": """Return merged instance of this data with other training data. Args: others: other training data instances to merge this one with Returns: Merged training data object. Merging is not done in place, this will be a new instance. """ training_examples = copy.deepcopy(self.training_examples) entity_synonyms = self.entity_synonyms.copy() regex_features = copy.deepcopy(self.regex_features) lookup_tables = copy.deepcopy(self.lookup_tables) responses = copy.deepcopy(self.responses) for o in others: if not o: continue training_examples.extend(copy.deepcopy(o.training_examples)) regex_features.extend(copy.deepcopy(o.regex_features)) lookup_tables.extend(copy.deepcopy(o.lookup_tables)) for text, syn in o.entity_synonyms.items(): util.check_duplicate_synonym(entity_synonyms, text, syn, "merging training data") entity_synonyms.update(o.entity_synonyms) responses.update(o.responses) return TrainingData(training_examples, entity_synonyms, regex_features, lookup_tables, responses)
def merge(self, *others: "TrainingData") -> "TrainingData": """Return merged instance of this data with other training data.""" training_examples = copy.deepcopy(self.training_examples) entity_synonyms = self.entity_synonyms.copy() regex_features = copy.deepcopy(self.regex_features) lookup_tables = copy.deepcopy(self.lookup_tables) responses = copy.deepcopy(self.responses) others = [other for other in others if other] for o in others: training_examples.extend(copy.deepcopy(o.training_examples)) regex_features.extend(copy.deepcopy(o.regex_features)) lookup_tables.extend(copy.deepcopy(o.lookup_tables)) for text, syn in o.entity_synonyms.items(): util.check_duplicate_synonym( entity_synonyms, text, syn, "merging training data" ) entity_synonyms.update(o.entity_synonyms) responses.update(o.responses) return TrainingData( training_examples, entity_synonyms, regex_features, lookup_tables, responses )
def add_synonym(synonym_value: Text, synonym_name: Text, existing_synonyms: Dict[Text, Any]) -> None: """Adds a new synonym mapping to the provided list of synonyms. Args: synonym_value: Value of the synonym. synonym_name: Name of the synonym. existing_synonyms: Dictionary will synonym mappings that will be extended. """ import rasa.shared.nlu.training_data.util as training_data_util training_data_util.check_duplicate_synonym(existing_synonyms, synonym_value, synonym_name, "reading markdown") existing_synonyms[synonym_value] = synonym_name