presidio_analyzer.predefined_recognizers import SpacyRecognizerpolish_check_label_groups = [    ({"LOCATION"}, {"placeName", "geogName"}),    ({"PERSON"}, {"persName"}),    ({"DATE_TIME"}, {"date", "time"}),]spacy_recognizer = SpacyRecognizer(    supported_language="pl",    check_label_groups=polish_check_label_groups,)anonymizer.add_recognizer(spacy_recognizer)Now everything works smoothly:print(    anonymizer.anonymize("Nazywam siƒô Wiktoria", language="pl"))  # "My name is Wiktoria" in Polish    Nazywam siƒô Morgan WaltersLet's try on more complex example:print(    anonymizer.anonymize(        "Nazywam siƒô Wiktoria. P≈Çock to moje miasto rodzinne. Urodzi≈Çam siƒô dnia 6 kwietnia 2001 roku",        language="pl",    ))  # "My name is Wiktoria. P≈Çock is my home town. I was born on 6 April 2001" in Polish    Nazywam siƒô Ernest Liu. New Taylorburgh to moje miasto rodzinne. Urodzi≈Çam siƒô 1987-01-19As you can see, thanks to class mapping, the anonymiser can cope with different types of entities. Custom language-specific operators‚ÄãIn the example above, the sentence has been anonymised correctly, but the fake data does not fit the Polish language at all. Custom operators can therefore be added, which will resolve the issue:from faker import Fakerfrom presidio_anonymizer.entities import OperatorConfigfake = Faker(locale="pl_PL")  # Setting faker to provide Polish datanew_operators = {    "PERSON": OperatorConfig("custom", {"lambda": lambda _: fake.first_name_female()}),    "LOCATION": OperatorConfig("custom", {"lambda": lambda _: fake.city()}),}anonymizer.add_operators(new_operators)print(    anonymizer.anonymize(        "Nazywam siƒô Wiktoria. P≈Çock to moje miasto rodzinne. Urodzi≈Çam siƒô dnia 6 kwietnia 2001 roku",        language="pl",    ))  # "My name is Wiktoria. P≈Çock is my home town. I was born on 6 April 2001" in Polish    Nazywam siƒô Marianna. Szczecin to moje miasto rodzinne. Urodzi≈Çam siƒô 1976-11-16Limitations‚ÄãRemember - results are as good as
Open In Colab
Open In Colab ->: presidio_analyzer.predefined_recognizers import SpacyRecognizerpolish_check_label_groups = [    ({"LOCATION"}, {"placeName", "geogName"}),    ({"PERSON"}, {"persName"}),    ({"DATE_TIME"}, {"date", "time"}),]spacy_recognizer = SpacyRecognizer(    supported_language="pl",    check_label_groups=polish_check_label_groups,)anonymizer.add_recognizer(spacy_recognizer)Now everything works smoothly:print(    anonymizer.anonymize("Nazywam siƒô Wiktoria", language="pl"))  # "My name is Wiktoria" in Polish    Nazywam siƒô Morgan WaltersLet's try on more complex example:print(    anonymizer.anonymize(        "Nazywam siƒô Wiktoria. P≈Çock to moje miasto rodzinne. Urodzi≈Çam siƒô dnia 6 kwietnia 2001 roku",        language="pl",    ))  # "My name is Wiktoria. P≈Çock is my home town. I was born on 6 April 2001" in Polish    Nazywam siƒô Ernest Liu. New Taylorburgh to moje miasto rodzinne. Urodzi≈Çam siƒô 1987-01-19As you can see, thanks to class mapping, the anonymiser can cope with different types of entities. Custom language-specific operators‚ÄãIn the example above, the sentence has been anonymised correctly, but the fake data does not fit the Polish language at all. Custom operators can therefore be added, which will resolve the issue:from faker import Fakerfrom presidio_anonymizer.entities import OperatorConfigfake = Faker(locale="pl_PL")  # Setting faker to provide Polish datanew_operators = {    "PERSON": OperatorConfig("custom", {"lambda": lambda _: fake.first_name_female()}),    "LOCATION": OperatorConfig("custom", {"lambda": lambda _: fake.city()}),}anonymizer.add_operators(new_operators)print(    anonymizer.anonymize(        "Nazywam siƒô Wiktoria. P≈Çock to moje miasto rodzinne. Urodzi≈Çam siƒô dnia 6 kwietnia 2001 roku",        language="pl",    ))  # "My name is Wiktoria. P≈Çock is my home town. I was born on 6 April 2001" in Polish    Nazywam siƒô Marianna. Szczecin to moje miasto rodzinne. Urodzi≈Çam siƒô 1976-11-16Limitations‚ÄãRemember - results are as good as