qfa.adapters.presidio_anonymizer#

Presidio-based anonymisation adapter.

Implements AnonymizationPort by delegating to Microsoft Presidio’s analyzer and anonymizer engines. Owns the heavy spaCy-backed pipelines so the application service layer never imports Presidio directly.

Functions

detect_language(text)

Detect the language of text and return a Presidio-compatible language code.

Classes

PresidioAnonymizer()

AnonymizationPort implementation backed by Presidio.

qfa.adapters.presidio_anonymizer.detect_language(text: str) str[source]#

Detect the language of text and return a Presidio-compatible language code.

If the detected language isn’t in our pre-defined list of SpaCy models, return “xx”.

class qfa.adapters.presidio_anonymizer.PresidioAnonymizer[source]#

Bases: AnonymizationPort

AnonymizationPort implementation backed by Presidio.

Replaces detected entities with stable placeholders of the form <ENTITY_TYPE_N> (e.g. <PERSON_0>, <LOCATION_1>) so the same value gets the same placeholder within a single anonymize call. DATE_TIME entities are preserved verbatim — they carry relevant context for analysis without identifying individuals.

anonymize(text: str) tuple[str, dict[str, str]][source]#

Replace sensitive entities in text with placeholders.

deanonymize(text: str, mapping: dict[str, str]) str[source]#

Restore original values in text using mapping.