44
55from flask import Flask , url_for
66from lapps .discriminators import Uri
7- from mmif import DocumentTypes
87from mmif .serialize .annotation import Text , Document
9- from mmif .vocabulary import AnnotationTypes
8+ from mmif .utils . timeunit_helper import UNIT_NORMALIZATION
109
1110import displacy
1211import iiif_utils
1918app .secret_key = 'your_secret_key_here'
2019
2120
21+ def normalize_timeunit (tu_str ):
22+ if tu_str in UNIT_NORMALIZATION :
23+ return UNIT_NORMALIZATION [tu_str ]
24+ else :
25+ return tu_str
26+
27+
2228def asr_alignments_to_vtt (alignment_view , viz_id ):
2329 vtt_filename = cache .get_cache_root () / viz_id / f"{ alignment_view .id .replace (':' , '-' )} .vtt"
2430 if vtt_filename .exists ():
@@ -27,7 +33,10 @@ def asr_alignments_to_vtt(alignment_view, viz_id):
2733 vtt_file .write ("WEBVTT\n \n " )
2834 annotations = alignment_view .annotations
2935 timeframe_at_type = [at_type for at_type in alignment_view .metadata .contains if at_type .shortname == "TimeFrame" ][0 ]
30- timeunit = alignment_view .metadata .contains [timeframe_at_type ]["timeUnit" ]
36+ timeunit = normalize_timeunit (alignment_view .metadata .contains [timeframe_at_type ]["timeUnit" ])
37+ # make plural so that this key can be used in timedelta init
38+ if timeunit [- 1 ] != 's' :
39+ timeunit += 's'
3140 # TODO: wanted to use "mmif.get_alignments(AnnotationTypes.TimeFrame, Uri.TOKEN)"
3241 # but that gave errors so I gave up on it
3342 token_idx = {a .id : a for a in annotations if a .at_type .shortname == "Token" }
0 commit comments