@@ -194,17 +194,16 @@ def create_annotation_tables(mmif):
194
194
% (view .id , view .metadata .app , status , len (view .annotations )))
195
195
s .write ("<blockquote>\n " )
196
196
s .write ("<table cellspacing=0 cellpadding=5 border=1>\n " )
197
+ limit_len = lambda str : str [:500 ] + " . . . }" if len (str ) > 500 else str
197
198
for annotation in view .annotations :
198
199
s .write (' <tr>\n ' )
199
200
s .write (' <td>%s</td>\n ' % annotation .id )
200
201
s .write (' <td>%s</td>\n ' % str (annotation .at_type ).split ('/' )[- 1 ])
201
- s .write (' <td>%s</td>\n ' % get_properties (annotation ))
202
+ s .write (' <td>%s</td>\n ' % limit_len ( get_properties (annotation ) ))
202
203
s .write (' </tr>\n ' )
203
204
s .write ("</table>\n " )
204
205
s .write ("</blockquote>\n " )
205
206
return s .getvalue ()
206
- return '<pre>%s</pre>\n ' % s .getvalue ()
207
-
208
207
209
208
210
209
def get_document_ids (view , annotation_type ):
@@ -291,15 +290,17 @@ def url2posix(path):
291
290
# Interactive MMIF Tab -----------
292
291
293
292
def render_interactive_mmif (mmif ):
294
- return render_template ('interactive.html' , mmif = mmif , is_aligned = is_properly_aligned (mmif ))
293
+ return render_template ('interactive.html' , mmif = mmif , aligned_views = get_aligned_views (mmif ))
295
294
296
- def is_properly_aligned (mmif ):
297
- """Check if Alignment placement is standard (for tree display)"""
295
+ # Functions for checking if view can be rendered with alignment highlighting
296
+ def get_aligned_views (mmif ):
297
+ """Return list of properly aligned views (for tree display)"""
298
+ aligned_views = []
298
299
for view in mmif .views :
299
300
if any ([str (at_type ).endswith ('Alignment' ) for at_type in view .metadata .contains ]):
300
- if check_view_alignment (view .annotations ) == False :
301
- return False
302
- return True
301
+ if check_view_alignment (view .annotations ) == True :
302
+ aligned_views . append ( view . id )
303
+ return aligned_views
303
304
304
305
def check_view_alignment (annotations ):
305
306
anno_stack = []
@@ -310,6 +311,7 @@ def check_view_alignment(annotations):
310
311
anno_stack .append (annotation .id )
311
312
if len (anno_stack ) == 3 :
312
313
if not (anno_stack [0 ]["source" ] in anno_stack and anno_stack [0 ]["target" ] in anno_stack ):
314
+ print (anno_stack )
313
315
return False
314
316
anno_stack = []
315
317
return True
0 commit comments