Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing the log by adding an entity_text and creating a new line for every case #1369

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion presidio-analyzer/presidio_analyzer/analyzer_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def analyze(
if self.log_decision_process:
self.app_tracer.trace(
correlation_id,
json.dumps([str(result.to_dict()) for result in results]),
json.dumps([str(result.to_dict()) for result in results],indent=4),
)

# Remove duplicates or low score results
Expand Down
1 change: 1 addition & 0 deletions presidio-analyzer/presidio_analyzer/pattern_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def __analyze_patterns(
)
pattern_result = RecognizerResult(
entity_type=self.supported_entities[0],
entity_text=text[start:end],
start=start,
end=end,
score=score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def analyze(
recognizer_results.append(
RecognizerResult(
entity_type=entity.category,
entity_text=text[entity.offset:entity.offset + entity.length],
start=entity.offset,
end=entity.offset + entity.length,
score=entity.confidence_score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def __analyze_patterns(self, text: str, flags: int = None):
)
pattern_result = RecognizerResult(
entity_type=self.supported_entities[0],
entity_text=text[start:end],
start=start,
end=end,
score=score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def analyze(
def _get_recognizer_result(self, match, text, region, nlp_artifacts):
result = RecognizerResult(
entity_type="PHONE_NUMBER",
entity_text = text[match.start:match.end],
start=match.start,
end=match.end,
score=self.SCORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def analyze(self, text: str, entities, nlp_artifacts=None): # noqa D102
explanation = self.build_explanation(ner_score, textual_explanation)
spacy_result = RecognizerResult(
entity_type=ner_entity.label_,
entity_text=text[ner_entity.start_char: ner_entity.end_char],
start=ner_entity.start_char,
end=ner_entity.end_char,
score=ner_score,
Expand Down
2 changes: 2 additions & 0 deletions presidio-analyzer/presidio_analyzer/recognizer_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RecognizerResult:
def __init__(
self,
entity_type: str,
entity_text:str,
start: int,
end: int,
score: float,
Expand All @@ -42,6 +43,7 @@ def __init__(
):

self.entity_type = entity_type
self.entity_text = entity_text
self.start = start
self.end = end
self.score = score
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ImageRecognizerResult(RecognizerResult):
def __init__(
self,
entity_type: str,
entity_text: str,
start: int,
end: int,
score: float,
Expand All @@ -27,7 +28,7 @@ def __init__(
height: int,
):

super().__init__(entity_type, start, end, score)
super().__init__(entity_type,entity_text, start, end, score)
self.left = left
self.top = top
self.width = width
Expand All @@ -52,6 +53,7 @@ def __str__(self) -> str:
"""Return a string representation of the instance."""
return (
f"type: {self.entity_type}, "
f"type: {self.entity_text}, "
f"start: {self.start}, "
f"end: {self.end}, "
f"score: {self.score}, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def map_analyzer_results_to_bounding_boxes(
bboxes.append(
ImageRecognizerResult(
element.entity_type,
text_element,
element.start,
element.end,
element.score,
Expand All @@ -204,6 +205,7 @@ def map_analyzer_results_to_bounding_boxes(
bboxes.append(
ImageRecognizerResult(
element.entity_type,
text_element,
element.start,
element.end,
element.score,
Expand Down