Text handler module - AdrianC2000/InvoiceScannerApp GitHub Wiki
Text handler module consists of classes that are used for text processing:
- CellsCreator - class for aligning read text to the cells from the table
- TextReader - class for extracting text from image
- WordsConverter - class for merging cells content into whole phrases
CellsCreator
Given a list of TextPositions
(so the extracted words with their positions) and a list of Columns
(so the calculated cells positions separated into columns) class matches each read word with the cells it should be in. For every TextPosition
correct column and row are calculated using the check_percentage_inclusion
method from common_utils
. WordsConverter class is required for the correct order of the words.
The output of this process is list[list[list[TextPosition]]]
- so the list[TextPosition] stands for the cell content, second list stands for all cells in a single column, and the last list is a list of every column. Then, this list of lists of lists is parsed into Table
object.
Table
object is a list of Row
objects, Row
object is a list of Cell
objects, and a Cell
object is a list of TextPosition
objects, so basically a cell content with its position.
TextReader
Using get_ocr_response
from common_utils
class is responsible for extracting words from a given image. It returns a list of TextPosition
objects, so a list of read words with its positions.
WordsConverter
This class is used for merging words into phrases - Table
object is passed, and in every Cell
there are words that are included in that cell, but not in the correct order. Returns list of RowContent
, which is simply a list of strings - every string is a single cell content.