4
4
5
5
from flask import Flask , url_for
6
6
from lapps .discriminators import Uri
7
- from mmif import DocumentTypes
8
7
from mmif .serialize .annotation import Text , Document
9
- from mmif .vocabulary import AnnotationTypes
8
+ from mmif .utils . timeunit_helper import UNIT_NORMALIZATION
10
9
11
10
import displacy
12
11
import iiif_utils
19
18
app .secret_key = 'your_secret_key_here'
20
19
21
20
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
+
22
28
def asr_alignments_to_vtt (alignment_view , viz_id ):
23
29
vtt_filename = cache .get_cache_root () / viz_id / f"{ alignment_view .id .replace (':' , '-' )} .vtt"
24
30
if vtt_filename .exists ():
@@ -27,7 +33,10 @@ def asr_alignments_to_vtt(alignment_view, viz_id):
27
33
vtt_file .write ("WEBVTT\n \n " )
28
34
annotations = alignment_view .annotations
29
35
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'
31
40
# TODO: wanted to use "mmif.get_alignments(AnnotationTypes.TimeFrame, Uri.TOKEN)"
32
41
# but that gave errors so I gave up on it
33
42
token_idx = {a .id : a for a in annotations if a .at_type .shortname == "Token" }
0 commit comments