leaf_focus/report/processing/parse.py
def report_items(self, document: Document, items: Iterable[Match]):
        """Convert lines from a document into report items."""

        collected = {}
        current_table = None
        previous_line_type = None
        current_change_type = "addition"
        current_register_section = None
        for item in items:
            page = item.line.page.index
            line = item.line.index + 1
            outcome = item.outcome

            # get the current line type
            if outcome and outcome.parser:
                current_line_type = outcome.parser.line_type
            else:
                current_line_type = None

            # only interested in line type of 'line'
            # if it has extracted data
            extracted = outcome.extracted if outcome.is_match else {}
            if (
                outcome.is_match
                and not extracted
                and current_line_type == LineTypeEnum.LINE
            ):
                previous_line_type = current_line_type
                continue

            # if this line is a table header
            # and the previous line was not a table header
            # set the current line as the table header
            if (
                current_line_type == LineTypeEnum.TABLE_HEADER
                and previous_line_type != LineTypeEnum.TABLE_HEADER
            ):
                current_table = item
                previous_line_type = current_line_type

                # remove temporary entries
                for temporary in self._temporary_entries:
                    if temporary in collected:
                        del collected[temporary]

                continue

            # set the previous line type
            if outcome and outcome.parser:
                previous_line_type = current_line_type

            # if this is a multi-line header
            # don't try to use the header as a table row
            if current_line_type == LineTypeEnum.TABLE_HEADER:
                continue

            # Add the data extracted from the line
            # to the collected data
            for k, v in extracted.items():
                if not k or not v:
                    continue
                self.report_item_extract(k, v, item, collected)

            # update change_type
            if extracted.get("change_type_addition"):
                current_change_type = "addition"
            if extracted.get("change_type_deletion"):
                current_change_type = "deletion"

            # extract table row from line that is not a match
            # only if there is a currently active table header
            if not outcome.is_match and current_table:
                extracted = self.page_table(current_table, item)

                if current_table.outcome.parser.group == LineGroupEnum.ALTERATION:
                    extracted, current_register_section = self.alteration(
                        current_table, item, current_register_section, extracted
                    )
                else:
                    current_register_section = current_table.outcome.parser.group

                extracted["register_section"] = current_register_section
                extracted["pdf_page"] = page
                extracted["pdf_line"] = line
                extracted["change_type"] = current_change_type

                report_item = self.report_item(document, {**collected, **extracted})
                if report_item.is_valid:
                    yield report_item
                else:
                    self._logger.debug(f"Invalid report item {str(report_item)}.")

                # remove temporary entries
                for temporary in self._temporary_entries:
                    if temporary in collected:
                        del collected[temporary]
Convert lines from a document into report items.
Convert lines from a document into report items.
Convert lines from a document into report items .
def report_items(self, document: Document, items: Iterable[Match]):
        collected = {}
        current_table = None
        previous_line_type = None
        current_change_type = "addition"
        current_register_section = None
        for item in items:
            page = item.line.page.index
            line = item.line.index + 1
            outcome = item.outcome
            if outcome and outcome.parser:
                current_line_type = outcome.parser.line_type
            else:
                current_line_type = None
            extracted = outcome.extracted if outcome.is_match else {}
            if (
                outcome.is_match
                and not extracted
                and current_line_type == LineTypeEnum.LINE
            ):
                previous_line_type = current_line_type
                continue
            if (
                current_line_type == LineTypeEnum.TABLE_HEADER
                and previous_line_type != LineTypeEnum.TABLE_HEADER
            ):
                current_table = item
                previous_line_type = current_line_type
                for temporary in self._temporary_entries:
                    if temporary in collected:
                        del collected[temporary]
                continue
            if outcome and outcome.parser:
                previous_line_type = current_line_type
            if current_line_type == LineTypeEnum.TABLE_HEADER:
                continue
            for k, v in extracted.items():
                if not k or not v:
                    continue
                self.report_item_extract(k, v, item, collected)
            if extracted.get("change_type_addition"):
                current_change_type = "addition"
            if extracted.get("change_type_deletion"):
                current_change_type = "deletion"
            if not outcome.is_match and current_table:
                extracted = self.page_table(current_table, item)
                if current_table.outcome.parser.group == LineGroupEnum.ALTERATION:
                    extracted, current_register_section = self.alteration(
                        current_table, item, current_register_section, extracted
                    )
                else:
                    current_register_section = current_table.outcome.parser.group
                extracted["register_section"] = current_register_section
                extracted["pdf_page"] = page
                extracted["pdf_line"] = line
                extracted["change_type"] = current_change_type
                report_item = self.report_item(document, {**collected, **extracted})
                if report_item.is_valid:
                    yield report_item
                else:
                    self._logger.debug(f"Invalid report item {str(report_item)}.")
                for temporary in self._temporary_entries:
                    if temporary in collected:
                        del collected[temporary]
def report_items ( self , document : Document , items : Iterable [ Match ] ) : collected = { } current_table = None previous_line_type = None current_change_type = "addition" current_register_section = None for item in items : page = item . line . page . index line = item . line . index + 1 outcome = item . outcome if outcome and outcome . parser : current_line_type = outcome . parser . line_type else : current_line_type = None extracted = outcome . extracted if outcome . is_match else { } if ( outcome . is_match and not extracted and current_line_type == LineTypeEnum . LINE ) : previous_line_type = current_line_type continue if ( current_line_type == LineTypeEnum . TABLE_HEADER and previous_line_type != LineTypeEnum . TABLE_HEADER ) : current_table = item previous_line_type = current_line_type for temporary in self . _temporary_entries : if temporary in collected : del collected [ temporary ] continue if outcome and outcome . parser : previous_line_type = current_line_type if current_line_type == LineTypeEnum . TABLE_HEADER : continue for k , v in extracted . items ( ) : if not k or not v : continue self . report_item_extract ( k , v , item , collected ) if extracted . get ( "change_type_addition" ) : current_change_type = "addition" if extracted . get ( "change_type_deletion" ) : current_change_type = "deletion" if not outcome . is_match and current_table : extracted = self . page_table ( current_table , item ) if current_table . outcome . parser . group == LineGroupEnum . ALTERATION : extracted , current_register_section = self . alteration ( current_table , item , current_register_section , extracted ) else : current_register_section = current_table . outcome . parser . group extracted [ "register_section" ] = current_register_section extracted [ "pdf_page" ] = page extracted [ "pdf_line" ] = line extracted [ "change_type" ] = current_change_type report_item = self . report_item ( document , { ** collected , ** extracted } ) if report_item . is_valid : yield report_item else : self . _logger . debug ( f"Invalid report item {str(report_item)}." ) for temporary in self . _temporary_entries : if temporary in collected : del collected [ temporary ]
Convert lines from a document into report items.
Convert lines from a document into report items .
"""Convert lines from a document into report items.""" # get the current line type # only interested in line type of 'line' # if it has extracted data # if this line is a table header # and the previous line was not a table header # set the current line as the table header # remove temporary entries # set the previous line type # if this is a multi-line header # don't try to use the header as a table row # Add the data extracted from the line # to the collected data # update change_type # extract table row from line that is not a match # only if there is a currently active table header # remove temporary entries
self
document
Document
items
Iterable[Match]