leaf_focus/report/item/page.py
def load(cls, document_dir: Path, document: "Document") -> Iterable["Page"]:
        """Load pages of a document."""
        text_path = document_dir / "pdf-text.txt"
        if not text_path.exists():
            return []

        # load ocr text
        pattern = ImageItem._pattern
        item_pages = {}
        for item_path in document_dir.glob("pdf-page-*text*.csv"):
            match = pattern.match(item_path.stem)
            if not match:
                continue
            item_page = int(match.group("page") or 0, 10)
            if item_page < 1:
                continue
            item_pages[item_page] = OcrItem.load(item_path)

        # load embedded text lines
        for index, raw_lines in enumerate(Component.read(text_path)):
            page = Page(index=index, document=document)
            lines = Line.load(raw_lines, page)
            page.lines = list(lines)

            page_num = index + 1
            if page_num in item_pages:
                page.items = list(item_pages[page_num])
            yield page
Load pages of a document.
Load pages of a document.
Load pages of a document .
def load(cls, document_dir: Path, document: "Document") -> Iterable["Page"]:
        text_path = document_dir / "pdf-text.txt"
        if not text_path.exists():
            return []
        pattern = ImageItem._pattern
        item_pages = {}
        for item_path in document_dir.glob("pdf-page-*text*.csv"):
            match = pattern.match(item_path.stem)
            if not match:
                continue
            item_page = int(match.group("page") or 0, 10)
            if item_page < 1:
                continue
            item_pages[item_page] = OcrItem.load(item_path)
        for index, raw_lines in enumerate(Component.read(text_path)):
            page = Page(index=index, document=document)
            lines = Line.load(raw_lines, page)
            page.lines = list(lines)
            page_num = index + 1
            if page_num in item_pages:
                page.items = list(item_pages[page_num])
            yield page
def load ( cls , document_dir : Path , document : "Document" ) -> Iterable [ "Page" ] : text_path = document_dir / "pdf-text.txt" if not text_path . exists ( ) : return [ ] pattern = ImageItem . _pattern item_pages = { } for item_path in document_dir . glob ( "pdf-page-*text*.csv" ) : match = pattern . match ( item_path . stem ) if not match : continue item_page = int ( match . group ( "page" ) or 0 , 10 ) if item_page < 1 : continue item_pages [ item_page ] = OcrItem . load ( item_path ) for index , raw_lines in enumerate ( Component . read ( text_path ) ) : page = Page ( index = index , document = document ) lines = Line . load ( raw_lines , page ) page . lines = list ( lines ) page_num = index + 1 if page_num in item_pages : page . items = list ( item_pages [ page_num ] ) yield page
Load pages of a document.
Load pages of a document .
"""Load pages of a document.""" # load ocr text # load embedded text lines
cls
document_dir
Path
document
"Document"