-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathannotator.py
More file actions
26 lines (22 loc) · 972 Bytes
/
annotator.py
File metadata and controls
26 lines (22 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# SPDX-FileCopyrightText: 2026 Stanford University, ETH Zurich, and the project authors (see CONTRIBUTORS.md)
# SPDX-FileCopyrightText: 2026 This source file is part of the SensorTSLM open-source project.
#
# SPDX-License-Identifier: MIT
#
from __future__ import annotations
from extractors import CaptionExtractor
from timef.schema import Annotation, Recording
class Annotator:
def __init__(self, extractors: list[CaptionExtractor]):
self.extractors = list(extractors)
seen = set()
for extractor in self.extractors:
if extractor.caption_type in seen:
raise ValueError(f"Duplicate extractor for caption_type={extractor.caption_type!r}.")
seen.add(extractor.caption_type)
def annotate(self, row: Recording) -> list[Annotation]:
annotations: list[Annotation] = []
for extractor in self.extractors:
annotations.extend(extractor.extract(row))
return annotations