Optimized Recognizer.sort_X_firstly and Recognizer.sort_Y_firstly (#5182)

### What problem does this PR solve?

Optimized Recognizer.sort_X_firstly and Recognizer.sort_Y_firstly

### Type of change

- [x] Performance Improvement
This commit is contained in:
Zhichang Yu
2025-02-20 15:41:12 +08:00
committed by GitHub
parent 07ddb8fcff
commit c326f14fed
3 changed files with 16 additions and 26 deletions

View File

@ -957,7 +957,7 @@ class RAGFlowPdfParser:
self.page_images = [p.to_image(resolution=72 * zoomin).annotated for i, p in
enumerate(self.pdf.pages[page_from:page_to])]
try:
self.page_chars = [[{**c, 'top': c['top'], 'bottom': c['bottom']} for c in page.dedupe_chars().chars if self._has_color(c)] for page in self.pdf.pages[page_from:page_to]]
self.page_chars = [[c for c in page.dedupe_chars().chars if self._has_color(c)] for page in self.pdf.pages[page_from:page_to]]
except Exception as e:
logging.warning(f"Failed to extract characters for pages {page_from}-{page_to}: {str(e)}")
self.page_chars = [[] for _ in range(page_to - page_from)] # If failed to extract, using empty list instead.