seen_values = set()
        for entity_type, values in new_mapping.items():
            count = len(self.mapping[entity_type]) + 1
            for key, value in values.items():
                if (
                    value not in seen_values
                    and value not in self.mapping[entity_type].values()
                ):
                    new_key = (
                        format_duplicated_operator(key, count)
                        if key in self.mapping[entity_type]
                        else key
                    )
                    self.mapping[entity_type][new_key] = value
                    seen_values.add(value)
                    count += 1
[docs]def create_anonymizer_mapping(
    original_text: str,
    analyzer_results: List["RecognizerResult"],
    anonymizer_results: "EngineResult",
    is_reversed: bool = False,
) -> MappingDataType:
    """Creates or updates the mapping used to anonymize and/or deanonymize text.
    This method exploits the results returned by the
    analysis and anonymization processes.
    If is_reversed is True, it constructs a mapping from each original
    entity to its anonymized value.
    If is_reversed is False, it constructs a mapping from each
    anonymized entity back to its original text value.
    If there are multiple entities of the same type, the mapping will
    include a count to differentiate them. For example, if there are
    two names in the input text, the mapping will include NAME_1 and NAME_2.
    Example of mapping:
    {
        "PERSON": {
            "<original>": "<anonymized>",
            "John Doe": "Slim Shady"
        },
        "PHONE_NUMBER": {
            "111-111-1111": "555-555-5555"
        }
        ...
    }