MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _should_try_ocr

Function _should_try_ocr

skills/pdf-parser/scripts/parse_pdf.py:222–243  ·  view source on GitHub ↗
(text: str, pdf_path: str)

Source from the content-addressed store, hash-verified

220
221
222def _should_try_ocr(text: str, pdf_path: str) -> bool:
223 if not PDF_PARSER_ENABLE_OCR or not HAS_PYMUPDF:
224 return False
225
226 normalized = clean_extracted_text(text)
227 if len(normalized) < PDF_PARSER_OCR_MIN_TEXT_CHARS:
228 return True
229
230 try:
231 doc = fitz.open(pdf_path)
232 try:
233 page_count = max(1, len(doc))
234 finally:
235 doc.close()
236 except Exception:
237 page_count = 1
238
239 avg_chars_per_page = len(normalized) / max(page_count, 1)
240 if avg_chars_per_page < max(40, PDF_PARSER_OCR_MIN_TEXT_CHARS // 2):
241 return True
242
243 return False
244
245
246def _render_page_to_numpy(page: Any):

Callers 1

extract_text_from_pdfFunction · 0.85

Calls 2

clean_extracted_textFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected