@@ -532,7 +532,7 @@ def get_annotations_between_time(self, start: int, end: int, time_unit: str = "m
532
532
assert end >= 0 , "End time must be greater than or equal to zero"
533
533
# 0. Initialize container and helper method
534
534
valid_tf_anns = []
535
- idtf_to_token = {}
535
+ tf_to_anns = defaultdict ( list )
536
536
537
537
# 1. find all views that contain the type of TF
538
538
views = self .get_all_views_contain ([AnnotationTypes .TimeFrame , AnnotationTypes .Alignment ])
@@ -556,18 +556,26 @@ def get_annotations_between_time(self, start: int, end: int, time_unit: str = "m
556
556
if self ._is_in_time_between (start , end , tf ):
557
557
valid_tf_anns .append (tf )
558
558
559
- # Map 'TimeFrame' id to 'Token' annotation
560
- idtf_to_idtk = {align .get_property ('source' ): align .get_property ('target' ) for align in al_anns }
561
- for id_tf in idtf_to_idtk :
562
- token_id = idtf_to_idtk [id_tf ]
563
- idtf_to_token [id_tf ] = view .get_annotation_by_id (token_id )
559
+ # Map 'TimeFrame' annotation to its aligned annotation
560
+ for align in al_anns :
561
+ source_id , target_id = align .get_property ('source' ), align .get_property ('target' )
562
+ try :
563
+ source , target = view .get_annotation_by_id (source_id ), view .get_annotation_by_id (target_id )
564
+ if source in valid_tf_anns :
565
+ tf_to_anns [source_id ].append (target )
566
+ elif target in valid_tf_anns :
567
+ tf_to_anns [target_id ].append (source )
568
+ except KeyError :
569
+ pass
564
570
565
571
# 3. For those extracted 'TimeFrame' annotations, sort them by their start time
566
572
sort_tf_anns = sorted (valid_tf_anns , key = lambda x : self .get_start (x ))
567
573
568
- # 4. Find all 'Token' annotations aligned with sorted 'TimeFrame' annotations
569
- for ann in sort_tf_anns :
570
- yield idtf_to_token [ann .get_property ('id' )]
574
+ # 4. Yield all annotations aligned with sorted 'TimeFrame' annotations
575
+ for tf_ann in sort_tf_anns :
576
+ anns = tf_to_anns [tf_ann .get_property ("id" )]
577
+ for ann in anns :
578
+ yield ann
571
579
572
580
def _get_linear_anchor_point (self , ann : Annotation , targets_sorted = False , start : bool = True ) -> Union [int , float ]:
573
581
# TODO (krim @ 2/5/24): Update the return type once timeunits are unified to `ms` as integers (https://github.com/clamsproject/mmif/issues/192)
0 commit comments