Skip to content

Commit

Permalink
fix: Change if condition typo in _get_children_of_element() (#313)
Browse files Browse the repository at this point in the history
The previous `if` condition was inefficient and should have been written with an `and` This resulted in a performance gap.

cProfile timing of `export_hocr_string()` on the same document

Before
```
143598720 function calls (129111346 primitive calls) in 44.487 seconds
```

After

```
97883150 function calls (88084552 primitive calls) in 30.235 seconds
```


Fixes #312 🦕
  • Loading branch information
holtskinner authored Jun 13, 2024
1 parent 7773ffe commit 7495e0e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions google/cloud/documentai_toolbox/wrappers/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ def _get_children_of_element(
return [
child
for child in children
if child.documentai_object.layout.text_anchor.text_segments[0].start_index
>= start_index
if child.documentai_object.layout.text_anchor.text_segments[0].end_index
if start_index
<= child.documentai_object.layout.text_anchor.text_segments[0].start_index
< end_index
and start_index
< child.documentai_object.layout.text_anchor.text_segments[0].end_index
<= end_index
]

Expand Down

0 comments on commit 7495e0e

Please sign in to comment.