Skip to content

Commit

Permalink
Use range=[] for non-geometric data
Browse files Browse the repository at this point in the history
  • Loading branch information
clinton-encord committed Jan 7, 2025
1 parent ac38461 commit df37f4c
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 16 deletions.
20 changes: 9 additions & 11 deletions encord/objects/ontology_labels_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,11 +1700,11 @@ def _to_classification_answers(self) -> Dict[str, Any]:
}

# At some point, we also want to add these to the other modalities
if self.data_type == DataType.AUDIO or self.data_type == DataType.PLAIN_TEXT:
if not is_geometric(self.data_type):
annotation = classification.get_annotations()[0]
ret[classification.classification_hash]["range"] = [
[range.start, range.end] for range in classification.range_list
]

# For non-geometric data, classifications apply to whole file
ret[classification.classification_hash]["range"] = []
ret[classification.classification_hash]["createdBy"] = annotation.created_by
ret[classification.classification_hash]["createdAt"] = annotation.created_at.strftime(
DATETIME_LONG_STRING_FORMAT
Expand Down Expand Up @@ -2417,12 +2417,8 @@ def _add_classification_instances_from_classifications_without_frames(
classification_answers: dict,
):
for classification_answer in classification_answers.values():
ranges: Ranges = []
for range_elem in classification_answer["range"]:
ranges.append(Range(range_elem[0], range_elem[1]))

classification_instance = self._create_new_classification_instance_with_ranges(
classification_answer, ranges
classification_answer
)
self.add_classification_instance(classification_instance)

Expand Down Expand Up @@ -2481,7 +2477,7 @@ def _create_new_classification_instance(

# This is only to be used by non-frame modalities (e.g. Audio)
def _create_new_classification_instance_with_ranges(
self, classification_answer: dict, ranges: Ranges
self, classification_answer: dict
) -> ClassificationInstance:
feature_hash = classification_answer["featureHash"]
classification_hash = classification_answer["classificationHash"]
Expand All @@ -2493,8 +2489,10 @@ def _create_new_classification_instance_with_ranges(
classification_instance = ClassificationInstance(
label_class, classification_hash=classification_hash, range_only=True
)

# For non-geometric data, the classification will always be treated as being on frame=0,
# which is the entire file
classification_instance.set_for_frames(
ranges,
created_at=range_view.created_at,
created_by=range_view.created_by,
confidence=range_view.confidence,
Expand Down
6 changes: 3 additions & 3 deletions tests/objects/data/audio_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"manualAnnotation": True,
},
],
"range": [[0, 0]],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
Expand Down Expand Up @@ -71,7 +71,7 @@
"manualAnnotation": True,
},
],
"range": [[0, 0]],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
Expand Down Expand Up @@ -101,7 +101,7 @@
"manualAnnotation": True,
},
],
"range": [[0, 0]],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
Expand Down
84 changes: 83 additions & 1 deletion tests/objects/data/html_text_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,89 @@
"shape": "text",
},
},
"classification_answers": {},
"classification_answers": {
"textClassificationHash": {
"classificationHash": "textClassificationHash",
"featureHash": "jPOcEsbw",
"classifications": [
{
"name": "Text classification",
"value": "text_classification",
"answers": "Text Answer",
"featureHash": "OxrtEM+v",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
"radioClassificationHash": {
"classificationHash": "radioClassificationHash",
"featureHash": "NzIxNTU1",
"classifications": [
{
"name": "Radio classification 1",
"value": "radio_classification_1",
"answers": [
{
"name": "cl 1 option 1",
"value": "cl_1_option_1",
"featureHash": "MTcwMjM5",
}
],
"featureHash": "MjI5MTA5",
"manualAnnotation": True,
},
{
"name": "cl 1 2 text",
"value": "cl_1_2_text",
"answers": "Nested Text Answer",
"featureHash": "MTg0MjIw",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
"checklistClassificationHash": {
"classificationHash": "checklistClassificationHash",
"featureHash": "3DuQbFxo",
"classifications": [
{
"name": "Checklist classification",
"value": "checklist_classification",
"answers": [
{
"name": "Checklist classification answer 1",
"value": "checklist_classification_answer_1",
"featureHash": "fvLjF0qZ",
},
{
"name": "Checklist classification answer 2",
"value": "checklist_classification_answer_2",
"featureHash": "a4r7nK9i",
},
],
"featureHash": "9mwWr3OE",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
},
"object_actions": {},
"label_status": "LABEL_IN_PROGRESS",
}
Expand Down
83 changes: 82 additions & 1 deletion tests/objects/data/plain_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,88 @@
"shape": "text",
},
},
"classification_answers": {},
"classification_answers": { "textClassificationHash": {
"classificationHash": "textClassificationHash",
"featureHash": "jPOcEsbw",
"classifications": [
{
"name": "Text classification",
"value": "text_classification",
"answers": "Text Answer",
"featureHash": "OxrtEM+v",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
"radioClassificationHash": {
"classificationHash": "radioClassificationHash",
"featureHash": "NzIxNTU1",
"classifications": [
{
"name": "Radio classification 1",
"value": "radio_classification_1",
"answers": [
{
"name": "cl 1 option 1",
"value": "cl_1_option_1",
"featureHash": "MTcwMjM5",
}
],
"featureHash": "MjI5MTA5",
"manualAnnotation": True,
},
{
"name": "cl 1 2 text",
"value": "cl_1_2_text",
"answers": "Nested Text Answer",
"featureHash": "MTg0MjIw",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
"checklistClassificationHash": {
"classificationHash": "checklistClassificationHash",
"featureHash": "3DuQbFxo",
"classifications": [
{
"name": "Checklist classification",
"value": "checklist_classification",
"answers": [
{
"name": "Checklist classification answer 1",
"value": "checklist_classification_answer_1",
"featureHash": "fvLjF0qZ",
},
{
"name": "Checklist classification answer 2",
"value": "checklist_classification_answer_2",
"featureHash": "a4r7nK9i",
},
],
"featureHash": "9mwWr3OE",
"manualAnnotation": True,
},
],
"range": [],
"createdBy": "user1Hash",
"createdAt": "Tue, 05 Nov 2024 09:41:37 ",
"lastEditedBy": "user1Hash",
"lastEditedAt": "Tue, 05 Nov 2024 09:41:37 ",
"manualAnnotation": True,
},
},
"object_actions": {},
"label_status": "LABEL_IN_PROGRESS",
}
Expand Down

0 comments on commit df37f4c

Please sign in to comment.