123456789101112131415161718192021222324 |
- def pseudonymize(
- self,
- original_text: str,
- presidio_response: List[RecognizerResult],
- count: int,
- ):
- """
- :param original_text: str containing the original text
- :param presidio_response: list of results from Presidio, to be used to know where entities are
- :param count: number of perturbations to return
- :return: List[str] with fake perturbations of original text
- """
- presidio_response = sorted(presidio_response, key=lambda resp: resp.start)
- anonymizer_engine = AnonymizerEngine()
- anonymized_result = anonymizer_engine.anonymize(
- text=original_text, analyzer_results=presidio_response
- )
- templated_text = anonymized_result.text
- templated_text = templated_text.replace(">", "}}").replace("<", "{{")
- fake_texts = [self.parse(templated_text, add_spans=False) for _ in range(count)]
- return fake_texts
|