@@ -656,14 +656,15 @@ def _is_in_time_range(self, ann: Annotation, range_s: Union[int, float], range_e
656
656
ann_s , ann_e = self .get_start (ann ), self .get_end (ann )
657
657
return (ann_s < range_s < ann_e ) or (ann_s < range_e < ann_e ) or (ann_s > range_s and ann_e < range_e )
658
658
659
- def get_annotations_between_time (self , start : Union [int , float ], end : Union [int , float ],
660
- time_unit : str = "ms" ) -> Iterator [Annotation ]:
659
+ def get_annotations_between_time (self , start : Union [int , float ], end : Union [int , float ], time_unit : str = "ms" ,
660
+ at_types : List [ Union [ ThingTypesBase , str ]] = [] ) -> Iterator [Annotation ]:
661
661
"""
662
662
Finds annotations that are anchored between the given time points.
663
663
664
664
:param start: the start time point in the unit of `input_unit`
665
665
:param end: the end time point in the unit of `input_unit`
666
666
:param time_unit: the unit of the input time points. Default is `ms`.
667
+ :param at_types: a list of annotation types to filter with. Any type in this list will be included in the return.
667
668
:return: an iterator of Annotation objects that are anchored between the given time points
668
669
"""
669
670
assert start < end , f"Start time point must be smaller than the end time point, given { start } and { end } "
@@ -673,6 +674,7 @@ def get_annotations_between_time(self, start: Union[int, float], end: Union[int,
673
674
from mmif .utils .timeunit_helper import convert
674
675
675
676
time_anchors_in_range = []
677
+ at_types = set (at_types )
676
678
677
679
for view in self .get_all_views_contain (AnnotationTypes .TimeFrame ) + self .get_all_views_contain (AnnotationTypes .TimePoint ):
678
680
time_unit_in_view = view .metadata .contains .get (AnnotationTypes .TimeFrame )["timeUnit" ]
@@ -684,9 +686,11 @@ def get_annotations_between_time(self, start: Union[int, float], end: Union[int,
684
686
time_anchors_in_range .append (ann )
685
687
time_anchors_in_range .sort (key = lambda x : self .get_start (x ))
686
688
for time_anchor in time_anchors_in_range :
687
- yield time_anchor
689
+ if not at_types or time_anchor .at_type in at_types :
690
+ yield time_anchor
688
691
for aligned in time_anchor .get_all_aligned ():
689
- yield aligned
692
+ if not at_types or aligned .at_type in at_types :
693
+ yield aligned
690
694
691
695
def _get_linear_anchor_point (self , ann : Annotation , targets_sorted = False , start : bool = True ) -> Union [int , float ]:
692
696
# 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