Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more robust timedelta initiation for VTT generation #38

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from flask import Flask, url_for
from lapps.discriminators import Uri
from mmif import DocumentTypes
from mmif.serialize.annotation import Text, Document
from mmif.vocabulary import AnnotationTypes
from mmif.utils.timeunit_helper import UNIT_NORMALIZATION

import displacy
import iiif_utils
Expand All @@ -19,6 +18,13 @@
app.secret_key = 'your_secret_key_here'


def normalize_timeunit(tu_str):
if tu_str in UNIT_NORMALIZATION:
return UNIT_NORMALIZATION[tu_str]
else:
return tu_str


def asr_alignments_to_vtt(alignment_view, viz_id):
vtt_filename = cache.get_cache_root() / viz_id / f"{alignment_view.id.replace(':', '-')}.vtt"
if vtt_filename.exists():
Expand All @@ -27,7 +33,10 @@ def asr_alignments_to_vtt(alignment_view, viz_id):
vtt_file.write("WEBVTT\n\n")
annotations = alignment_view.annotations
timeframe_at_type = [at_type for at_type in alignment_view.metadata.contains if at_type.shortname == "TimeFrame"][0]
timeunit = alignment_view.metadata.contains[timeframe_at_type]["timeUnit"]
timeunit = normalize_timeunit(alignment_view.metadata.contains[timeframe_at_type]["timeUnit"])
# make plural so that this key can be used in timedelta init
if timeunit[-1] != 's':
timeunit += 's'
# TODO: wanted to use "mmif.get_alignments(AnnotationTypes.TimeFrame, Uri.TOKEN)"
# but that gave errors so I gave up on it
token_idx = {a.id: a for a in annotations if a.at_type.shortname == "Token"}
Expand Down
Loading