Skip to content

Commit 912c085

Browse files
Limit text in annotations tab (#16) and fix tree highlighting bug
1 parent 9b2be34 commit 912c085

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

templates/interactive.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<li data-jstree='{"type":"view"}'>{{view.metadata.app}} ({{view.id}})
7676
<ul>
7777
{% for annotation in view.annotations %}
78-
<li data-jstree='{"type": "{{"annotation-highlighted" if cluster.highlighted and is_aligned else "annotation"}}"}'>{{annotation.at_type}}
78+
<li data-jstree='{"type": "{{"annotation-highlighted" if cluster.highlighted and view.id in aligned_views else "annotation"}}"}'>{{annotation.at_type}}
7979
<ul>
8080
<li data-jstree='{"type":"properties"}'>{{annotation.properties}}</li>
8181
</ul>

utils.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,16 @@ def create_annotation_tables(mmif):
194194
% (view.id, view.metadata.app, status, len(view.annotations)))
195195
s.write("<blockquote>\n")
196196
s.write("<table cellspacing=0 cellpadding=5 border=1>\n")
197+
limit_len = lambda str : str[:500] + " . . . }" if len(str) > 500 else str
197198
for annotation in view.annotations:
198199
s.write(' <tr>\n')
199200
s.write(' <td>%s</td>\n' % annotation.id)
200201
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)))
202203
s.write(' </tr>\n')
203204
s.write("</table>\n")
204205
s.write("</blockquote>\n")
205206
return s.getvalue()
206-
return '<pre>%s</pre>\n' % s.getvalue()
207-
208207

209208

210209
def get_document_ids(view, annotation_type):
@@ -291,15 +290,17 @@ def url2posix(path):
291290
# Interactive MMIF Tab -----------
292291

293292
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))
295294

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 = []
298299
for view in mmif.views:
299300
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
303304

304305
def check_view_alignment(annotations):
305306
anno_stack = []
@@ -310,6 +311,7 @@ def check_view_alignment(annotations):
310311
anno_stack.append(annotation.id)
311312
if len(anno_stack) == 3:
312313
if not (anno_stack[0]["source"] in anno_stack and anno_stack[0]["target"] in anno_stack):
314+
print(anno_stack)
313315
return False
314316
anno_stack = []
315317
return True

0 commit comments

Comments
 (0)