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

Fix entity details response to return based on location order #528

Merged
Merged
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
18 changes: 17 additions & 1 deletion pebblo/entity_classifier/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@
from pebblo.utils import get_confidence_score_label


def location_key(item):
"""
To convert the location string into a tuple of integers
"""
loc = item["location"]
return tuple(map(int, loc.split("_")))


def get_entities(entities_list, response):
"""
Returns entity groups, its details such as confidence score, location and its group grouped by entity type
"""
entity_groups: dict = dict()
entity_details: dict = dict()
entity_details_response: dict = dict()

mapped_entity = None
total_count = 0
Expand All @@ -41,7 +53,11 @@ def get_entities(entities_list, response):
entity_details[mapped_entity] = [entity_data]
total_count += 1

return entity_groups, entity_details, total_count
for entity, entity_data in entity_details.items():
# Sorting entity details based on location in ascending order
entity_details_response[entity] = sorted(entity_data, key=location_key)

return entity_groups, entity_details_response, total_count


def add_custom_regex_analyzer_registry():
Expand Down