@@ -31,9 +31,9 @@ def get_alignments(alignment_view):
31
31
annotations = alignment_view .annotations
32
32
# TODO: wanted to use "mmif.get_alignments(AnnotationTypes.TimeFrame, Uri.TOKEN)"
33
33
# but that gave errors so I gave up on it
34
- token_idx = {a .id :a for a in annotations if str (a .at_type ). endswith ( 'Token' )}
35
- timeframe_idx = {a .id :a for a in annotations if str (a .at_type ). endswith ( 'TimeFrame' )}
36
- alignments = [a for a in annotations if str (a .at_type ). endswith ( 'Alignment' )]
34
+ token_idx = {a .id :a for a in annotations if "Token" in str (a .at_type )}
35
+ timeframe_idx = {a .id :a for a in annotations if "TimeFrame" in str (a .at_type )}
36
+ alignments = [a for a in annotations if "Alignment" in str (a .at_type )]
37
37
vtt_start = None
38
38
texts = []
39
39
for alignment in alignments :
@@ -212,7 +212,7 @@ def get_document_ids(view, annotation_type):
212
212
metadata = view .metadata .contains .get (annotation_type )
213
213
ids = set ([metadata ['document' ]]) if 'document' in metadata else set ()
214
214
for annotation in view .annotations :
215
- if str (annotation . at_type ). endswith ( str (annotation_type ) ):
215
+ if str (annotation_type ) in str (annotation . at_type ):
216
216
try :
217
217
ids .add (annotation .properties ["document" ])
218
218
except KeyError :
@@ -298,15 +298,15 @@ def get_aligned_views(mmif):
298
298
"""Return list of properly aligned views (for tree display)"""
299
299
aligned_views = []
300
300
for view in mmif .views :
301
- if any ([str (at_type ). endswith ( 'Alignment' ) for at_type in view .metadata .contains ]):
301
+ if any (["Alignment" in str (at_type ) for at_type in view .metadata .contains ]):
302
302
if check_view_alignment (view .annotations ) == True :
303
303
aligned_views .append (view .id )
304
304
return aligned_views
305
305
306
306
def check_view_alignment (annotations ):
307
307
anno_stack = []
308
308
for annotation in annotations :
309
- if str (annotation .at_type ). endswith ( 'Alignment' ):
309
+ if "Alignment" in str (annotation .at_type ):
310
310
anno_stack .insert (0 , annotation .properties )
311
311
else :
312
312
anno_stack .append (annotation .id )
@@ -332,7 +332,7 @@ def create_ner_visualization(mmif, view):
332
332
# all the view's named entities refer to the same text document (kaldi)
333
333
document_ids = get_document_ids (view , Uri .NE )
334
334
return displacy .visualize_ner (mmif , view , document_ids [0 ], app .root_path )
335
- except KeyError :
335
+ except KeyError as e :
336
336
# the view's entities refer to more than one text document (tessearct)
337
337
pass
338
338
def get_status (view ):
@@ -357,17 +357,17 @@ def prepare_ocr_visualization(mmif, view):
357
357
frames , text_docs , alignments = {}, {}, {}
358
358
for anno in view .annotations :
359
359
try :
360
- if str (anno .at_type ). endswith ( 'BoundingBox' ):
360
+ if "BoundingBox" in str (anno .at_type ):
361
361
frames = add_bounding_box (anno , frames )
362
362
363
- elif str (anno .at_type ). endswith ( 'TextDocument' ):
363
+ elif "TextDocument" in str (anno .at_type ):
364
364
t = anno .properties ["text_value" ]
365
365
if t :
366
366
text_id = anno .properties ["id" ]
367
367
# Format string so it is JSON-readable
368
368
text_docs [text_id ] = re .sub (r'([\\\/\|\"\'])' , r'\1 ' , t )
369
369
370
- elif str (anno .at_type ). endswith ( 'Alignment' ):
370
+ elif "Alignment" in str (anno .at_type ):
371
371
source = anno .properties ["source" ]
372
372
target = anno .properties ["target" ]
373
373
alignments [source ] = target
0 commit comments