13
13
14
14
import cache
15
15
16
+ """
17
+ Helper function for showing debug information
18
+
19
+ def some_function(x):
20
+ from utils import app # import inside function
21
+ app.logger.debug(x)
22
+ """
16
23
17
24
class OCRFrame ():
18
25
"""
@@ -62,10 +69,10 @@ def add_bounding_box(self, anno, mmif: Mmif):
62
69
else :
63
70
for alignment_anns in mmif .get_alignments (AnnotationTypes .BoundingBox , AnnotationTypes .TimePoint ).values ():
64
71
for alignment_ann in alignment_anns :
65
- if alignment_ann .get ('source' ) == anno .id :
72
+ if alignment_ann .get ('source' ) == anno .long_id :
66
73
timepoint_anno = mmif [alignment_ann .get ('target' )]
67
74
break
68
- elif alignment_ann .get ('target' ) == anno .id :
75
+ elif alignment_ann .get ('target' ) == anno .long_id :
69
76
timepoint_anno = mmif [alignment_ann .get ('source' )]
70
77
break
71
78
if timepoint_anno :
@@ -90,7 +97,7 @@ def add_timeframe(self, anno, mmif):
90
97
if "targets" in anno .properties :
91
98
start_id , end_id = anno .properties .get ("targets" )[0 ], anno .properties .get ("targets" )[- 1 ]
92
99
anno_parent = mmif .get_view_by_id (anno .parent )
93
- start_anno , end_anno = mmif [ start_id ], mmif [ end_id ]
100
+ start_anno , end_anno = anno_parent . get_annotation_by_id ( start_id ), anno_parent . get_annotation_by_id ( end_id )
94
101
start = convert_timepoint (mmif , start_anno , "frames" )
95
102
end = convert_timepoint (mmif , end_anno , "frames" )
96
103
start_secs = convert_timepoint (mmif , start_anno , "seconds" )
@@ -121,10 +128,9 @@ def add_timepoint(self, anno, mmif, skip_if_view_has_frames=True):
121
128
self .frametype = anno .properties .get ("label" )
122
129
123
130
def add_text_document (self , anno ):
124
- t = anno .properties .get ("text_value" ) or anno .properties .get ("text" ).value
125
- if t :
126
- text_val = re .sub (r'([\\\/\|\"\'])' , r'\1 ' , t )
127
- self .text = self .text + [text_val ] if text_val not in self .text else self .text
131
+ t = anno .properties .get ("text_value" ) or anno .text_value
132
+ text_val = re .sub (r'([\\\/\|\"\'])' , r'\1 ' , t )
133
+ self .text = self .text + [text_val ] if text_val not in self .text else self .text
128
134
129
135
130
136
def get_ocr_frames (view , mmif ):
@@ -139,6 +145,8 @@ def get_ocr_frames(view, mmif):
139
145
140
146
# Account for alignment in either direction
141
147
frame = OCRFrame (source , mmif )
148
+ if target .at_type == DocumentTypes .TextDocument :
149
+ frame .add_timepoint (source , mmif , skip_if_view_has_frames = False )
142
150
frame .update (target , mmif )
143
151
144
152
i = frame .frame_num if frame .frame_num is not None else frame .range
0 commit comments