Deduplicate overlapping entity detections#7
Merged
Conversation
When Presidio's built-in recognizers and custom German recognizers both match the same text span (e.g., IBAN_CODE + DE_IBAN), the entity appeared twice in the review panel. Add _deduplicate_overlapping() to text_handler that keeps the highest-confidence result per character range, with span length as tiebreaker for equal scores.
Contributor
Greptile SummaryThis PR introduces Key changes:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["detect_pii_in_text(engine, text)"] --> B["engine.analyze(text, language)"]
B --> C["Filter: score >= score_threshold"]
C --> D{"len(filtered) <= 1?"}
D -- Yes --> G["Return filtered as-is"]
D -- No --> E["Sort by (-score, -span_length)"]
E --> F["Greedy accept loop\nfor each candidate:\n if no overlap with accepted → accept"]
F --> H["Return accepted list\n(score-desc order)"]
G --> I["Caller: anonymize_plain_text / PDF / API"]
H --> I
Reviews (1): Last reviewed commit: "Deduplicate overlapping entity detection..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_deduplicate_overlapping()totext_handler.py— when Presidio's built-in recognizers and custom German recognizers both match the same text span (e.g.,IBAN_CODE+DE_IBAN), keeps only the highest-confidence resultdetect_pii_in_text(), so this is a single-point fixTest plan
make checkpasses (275 tests, 96.67% coverage)text_handler.pyat 100% coverage