Skip to content

Commit 6eb6812

Browse files
authored
[PLA-672][external] Support for importing simple_table annotations (#781)
* Logic to import simple_table annotations in Darwin JSON * Formatting
1 parent 82bfdba commit 6eb6812

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

darwin/datatypes.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,51 @@ def make_table(
10031003
)
10041004

10051005

1006+
def make_simple_table(
1007+
class_name: str,
1008+
bounding_box: BoundingBox,
1009+
col_offsets: List[float],
1010+
row_offsets: List[float],
1011+
subs: Optional[List[SubAnnotation]] = None,
1012+
slot_names: Optional[List[str]] = None,
1013+
) -> Annotation:
1014+
"""
1015+
Creates and returns a simple table annotation.
1016+
1017+
Parameters
1018+
----------
1019+
class_name : str
1020+
The name of the class for this ``Annotation``.
1021+
1022+
bounding_box : BoundingBox
1023+
Bounding box that wraps around the table.
1024+
1025+
col_offsets : List[float]
1026+
List of floats representing the column offsets.
1027+
1028+
row_offsets : List[float]
1029+
List of floats representing the row offsets.
1030+
1031+
subs : Optional[List[SubAnnotation]], default: None
1032+
List of ``SubAnnotation``\\s for this ``Annotation``.
1033+
1034+
Returns
1035+
-------
1036+
Annotation
1037+
A simple table ``Annotation``.
1038+
"""
1039+
return Annotation(
1040+
AnnotationClass(class_name, "simple_table"),
1041+
{
1042+
"bounding_box": bounding_box,
1043+
"col_offsets": col_offsets,
1044+
"row_offsets": row_offsets,
1045+
},
1046+
subs or [],
1047+
slot_names=slot_names or [],
1048+
)
1049+
1050+
10061051
def make_string(
10071052
class_name: str,
10081053
sources: List[Dict[str, UnknownType]],

darwin/importer/importer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def build_main_annotations_lookup_table(
9292
"tag",
9393
"string",
9494
"table",
95+
"simple_table",
9596
"graph",
9697
"mask",
9798
"raster_layer",
@@ -280,7 +281,9 @@ def _get_team_properties_annotation_lookup(client):
280281
team_properties = client.get_team_properties()
281282

282283
# (property-name, annotation_class_id): FullProperty object
283-
team_properties_annotation_lookup: Dict[Tuple[str, Optional[int]], FullProperty] = {}
284+
team_properties_annotation_lookup: Dict[
285+
Tuple[str, Optional[int]], FullProperty
286+
] = {}
284287
for prop in team_properties:
285288
team_properties_annotation_lookup[(prop.name, prop.annotation_class_id)] = prop
286289

@@ -425,7 +428,6 @@ def _import_properties(
425428
a_prop.name,
426429
annotation_class_id,
427430
) not in team_properties_annotation_lookup:
428-
429431
# check if fullproperty exists in create_properties
430432
for full_property in create_properties:
431433
if (
@@ -893,9 +895,9 @@ def import_annotations( # noqa: C901
893895

894896
# Need to re parse the files since we didn't save the annotations in memory
895897
for local_path in set(local_file.path for local_file in local_files): # noqa: C401
896-
imported_files: Union[List[dt.AnnotationFile], dt.AnnotationFile, None] = (
897-
importer(local_path)
898-
)
898+
imported_files: Union[
899+
List[dt.AnnotationFile], dt.AnnotationFile, None
900+
] = importer(local_path)
899901
if imported_files is None:
900902
parsed_files = []
901903
elif not isinstance(imported_files, List):

darwin/utils/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,14 @@ def _parse_darwin_annotation(annotation: Dict[str, Any]) -> Optional[dt.Annotati
823823
annotation["table"]["cells"],
824824
slot_names=slot_names,
825825
)
826+
elif "simple_table" in annotation:
827+
main_annotation = dt.make_simple_table(
828+
name,
829+
annotation["simple_table"]["bounding_box"],
830+
annotation["simple_table"]["col_offsets"],
831+
annotation["simple_table"]["row_offsets"],
832+
slot_names=slot_names,
833+
)
826834
elif "string" in annotation:
827835
main_annotation = dt.make_string(
828836
name, annotation["string"]["sources"], slot_names=slot_names

0 commit comments

Comments
 (0)