Skip to content

Commit 9b5ac32

Browse files
Update ocr.py
1 parent 8000d53 commit 9b5ac32

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ocr.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
import cache
1515

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+
"""
1623

1724
class OCRFrame():
1825
"""
@@ -62,10 +69,10 @@ def add_bounding_box(self, anno, mmif: Mmif):
6269
else:
6370
for alignment_anns in mmif.get_alignments(AnnotationTypes.BoundingBox, AnnotationTypes.TimePoint).values():
6471
for alignment_ann in alignment_anns:
65-
if alignment_ann.get('source') == anno.id:
72+
if alignment_ann.get('source') == anno.long_id:
6673
timepoint_anno = mmif[alignment_ann.get('target')]
6774
break
68-
elif alignment_ann.get('target') == anno.id:
75+
elif alignment_ann.get('target') == anno.long_id:
6976
timepoint_anno = mmif[alignment_ann.get('source')]
7077
break
7178
if timepoint_anno:
@@ -90,7 +97,7 @@ def add_timeframe(self, anno, mmif):
9097
if "targets" in anno.properties:
9198
start_id, end_id = anno.properties.get("targets")[0], anno.properties.get("targets")[-1]
9299
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)
94101
start = convert_timepoint(mmif, start_anno, "frames")
95102
end = convert_timepoint(mmif, end_anno, "frames")
96103
start_secs = convert_timepoint(mmif, start_anno, "seconds")
@@ -121,10 +128,9 @@ def add_timepoint(self, anno, mmif, skip_if_view_has_frames=True):
121128
self.frametype = anno.properties.get("label")
122129

123130
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
128134

129135

130136
def get_ocr_frames(view, mmif):
@@ -139,6 +145,8 @@ def get_ocr_frames(view, mmif):
139145

140146
# Account for alignment in either direction
141147
frame = OCRFrame(source, mmif)
148+
if target.at_type == DocumentTypes.TextDocument:
149+
frame.add_timepoint(source, mmif, skip_if_view_has_frames=False)
142150
frame.update(target, mmif)
143151

144152
i = frame.frame_num if frame.frame_num is not None else frame.range

0 commit comments

Comments
 (0)