@@ -62,7 +62,9 @@ class NDLabel(BaseModel):
62
62
annotations : AnnotationType
63
63
64
64
@classmethod
65
- def from_common (cls , data : LabelCollection ) -> Generator ["NDLabel" , None , None ]:
65
+ def from_common (
66
+ cls , data : LabelCollection
67
+ ) -> Generator ["NDLabel" , None , None ]:
66
68
for label in data :
67
69
yield from cls ._create_relationship_annotations (label )
68
70
yield from cls ._create_non_video_annotations (label )
@@ -126,12 +128,16 @@ def _create_video_annotations(
126
128
if isinstance (
127
129
annot , (VideoClassificationAnnotation , VideoObjectAnnotation )
128
130
):
129
- video_annotations [annot .feature_schema_id or annot .name ].append (annot )
131
+ video_annotations [annot .feature_schema_id or annot .name ].append (
132
+ annot
133
+ )
130
134
elif isinstance (annot , VideoMaskAnnotation ):
131
135
yield NDObject .from_common (annotation = annot , data = label .data )
132
136
133
137
for annotation_group in video_annotations .values ():
134
- segment_frame_ranges = cls ._get_segment_frame_ranges (annotation_group )
138
+ segment_frame_ranges = cls ._get_segment_frame_ranges (
139
+ annotation_group
140
+ )
135
141
if isinstance (annotation_group [0 ], VideoClassificationAnnotation ):
136
142
annotation = annotation_group [0 ]
137
143
frames_data = []
@@ -197,10 +203,12 @@ def _create_relationship_annotations(
197
203
NDRelationship: Validated relationship annotations in NDJSON format
198
204
199
205
Raises:
200
- TypeError: If source/target types violate the validation rules:
201
- - Invalid source type for PDF target
202
- - Non-ObjectAnnotation source for non-PDF target
203
- - Non-ObjectAnnotation target
206
+ TypeError: If source/target types are invalid:
207
+ - Source:
208
+ - For PDF target annotations (DocumentRectangle, DocumentEntity): source must be ObjectAnnotation or ClassificationAnnotation
209
+ - For other target annotations: source must be ObjectAnnotation
210
+ - Target:
211
+ - Target must always be ObjectAnnotation
204
212
"""
205
213
for annotation in label .annotations :
206
214
if isinstance (annotation , RelationshipAnnotation ):
@@ -210,7 +218,9 @@ def _create_relationship_annotations(
210
218
target = copy .copy (annotation .value .target )
211
219
212
220
# Check if source type is valid based on target type
213
- if isinstance (target .value , (DocumentRectangle , DocumentEntity )):
221
+ if isinstance (
222
+ target .value , (DocumentRectangle , DocumentEntity )
223
+ ):
214
224
if not isinstance (
215
225
source , (ObjectAnnotation , ClassificationAnnotation )
216
226
):
0 commit comments