Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.18.24-dev0

### Enhancement
- Optimize `OCRAgentTesseract.extract_word_from_hocr` (codeflash)

## 0.18.23

### Enhancement
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.18.23" # pragma: no cover
__version__ = "0.18.24-dev0" # pragma: no cover
10 changes: 6 additions & 4 deletions unstructured/partition/utils/ocr_models/tesseract_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from unstructured_inference.inference.elements import TextRegions
from unstructured_inference.inference.layoutelement import LayoutElements

_RE_X_CONF = re.compile(r"x_conf (\d+\.\d+)")

# -- force tesseract to be single threaded, otherwise we see major performance problems --
if "OMP_THREAD_LIMIT" not in os.environ:
os.environ["OMP_THREAD_LIMIT"] = "1"
Expand Down Expand Up @@ -152,22 +154,22 @@ def extract_word_from_hocr(
if len(character_spans) == 0:
return ""

word_text = ""
chars = []
for character_span in character_spans:
char = character_span.text

char_title = character_span.get("title", "")
conf_match = re.search(r"x_conf (\d+\.\d+)", char_title)
conf_match = _RE_X_CONF.search(char_title)

if not (char and conf_match):
continue

character_probability = float(conf_match.group(1)) / 100

if character_probability >= character_confidence_threshold:
word_text += char
chars.append(char)

return word_text
return "".join(chars)

@requires_dependencies("unstructured_inference")
def get_layout_elements_from_image(self, image: PILImage.Image) -> LayoutElements:
Expand Down