mirror of
https://github.com/data-privacy-stack/presidio.git
synced 2026-10-01 02:18:04 -05:00
5.3 KiB
5.3 KiB
In [ ]:
# download presidio
!pip install presidio_analyzer presidio_anonymizer
!python -m spacy download en_core_web_lgIn [1]:
from presidio_anonymizer import AnonymizerEngine
from presidio_anonymizer.entities import RecognizerResult, OperatorConfigIn [2]:
engine = AnonymizerEngine()
# Invoke the anonymize function with the text,
# analyzer results (potentially coming from presidio-analyzer)
# and 'keep' operator on <PERSON> PIIs
anonymize_result = engine.anonymize(
text="My name is James Bond, I live in London",
analyzer_results=[
RecognizerResult(entity_type="PERSON", start=11, end=21, score=0.8),
RecognizerResult(entity_type="LOCATION", start=33, end=39, score=0.8),
],
operators={
"PERSON": OperatorConfig("keep"),
"DEFAULT": OperatorConfig("replace"),
},
)In [3]:
anonymize_resultOut [3]:
text: My name is James Bond, I live in <LOCATION>
items:
[
{'start': 33, 'end': 43, 'entity_type': 'LOCATION', 'text': '<LOCATION>', 'operator': 'replace'},
{'start': 11, 'end': 21, 'entity_type': 'PERSON', 'text': 'James Bond', 'operator': 'keep'}
]