def form_table_cell(bounding_box, form_word): model = _models.FormTableCell( text="Cell", row_index=3, column_index=4, row_span=2, column_span=3, bounding_box=bounding_box[0], confidence=0.7, is_header=True, is_footer=False, page_number=3, field_elements=[form_word[0]] ) model_repr = "FormTableCell(text=Cell, row_index=3, column_index=4, row_span=2, column_span=3, bounding_box={}, confidence=0.7, " \ "is_header=True, is_footer=False, page_number=3, field_elements=[{}])".format(bounding_box[1], form_word[1])[:1024] assert repr(model) == model_repr return model, model_repr
def test_form_table_to_dict(self): table = _models.FormTable( page_number=2, cells=[ _models.FormTableCell( text="info", row_index=1, column_index=3, row_span=1, column_span=2, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], confidence=0.87, is_header=False, is_footer=True, page_number=1, field_elements=[ _models.FormWord( text="word", confidence=0.92, page_number=1, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), ] ) ], row_count=10, column_count=5, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ) d = table.to_dict() final = { "cells": [ { "text": "info", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "row_index": 1, "column_index": 3, "row_span": 1, "column_span": 2, "confidence": 0.87, "is_header": False, "is_footer": True, "page_number": 1, "field_elements": [ { "text": "word", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "confidence": 0.92, "page_number": 1, "kind": "word", } ], }, ], "page_number": 2, "row_count": 10, "column_count": 5, "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], } assert d == final
def test_form_page_to_dict(self): form_page = _models.FormPage( page_number=1, text_angle=180.0, width=5.5, height=8.0, unit="pixel", tables= [ _models.FormTable( page_number=2, cells=[ _models.FormTableCell( text="info", row_index=1, column_index=3, row_span=1, column_span=2, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], confidence=0.87, is_header=False, is_footer=True, page_number=1, field_elements=[ _models.FormWord( text="word", confidence=0.92, page_number=1, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), ] ) ], row_count=10, column_count=5, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), ], lines=[_models.FormLine( text="sample line", bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], words=[ _models.FormWord( text="sample", confidence=0.92, page_number=1, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), _models.FormWord( text="line", confidence=0.92, page_number=1, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), ], page_number=2, appearance=_models.TextAppearance( style_name="other", style_confidence=0.90 ), ), ], selection_marks=[_models.FormSelectionMark( text="checkbox", state="selected", confidence=0.92, page_number=1, bounding_box=[ _models.Point(1427.0, 1669.0), _models.Point(1527.0, 1669.0), _models.Point(1527.0, 1698.0), _models.Point(1427.0, 1698.0), ], ), ], ) d = form_page.to_dict() final = { "page_number": 1, "text_angle": 180.0, "width": 5.5, "height": 8.0, "unit": "pixel", "tables": [ {"cells": [ { "text": "info", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "row_index": 1, "column_index": 3, "row_span": 1, "column_span": 2, "confidence": 0.87, "is_header": False, "is_footer": True, "page_number": 1, "field_elements": [ { "text": "word", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "confidence": 0.92, "page_number": 1, "kind": "word", } ], }, ], "page_number": 2, "row_count": 10, "column_count": 5, "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], }, ], "lines": [{ "text": "sample line", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "words": [ { "text": "sample", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "confidence": 0.92, "page_number": 1, "kind": "word", }, { "text": "line", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "confidence": 0.92, "page_number": 1, "kind": "word", }, ], "page_number": 2, "kind": "line", "appearance": {"style_name": "other", "style_confidence": 0.90}, }], "selection_marks": [{ "text": "checkbox", "state": "selected", "bounding_box": [ {"x": 1427.0, "y": 1669.0}, {"x": 1527.0, "y": 1669.0}, {"x": 1527.0, "y": 1698.0}, {"x": 1427.0, "y": 1698.0}, ], "confidence": 0.92, "page_number": 1, "kind": "selectionMark", }], } assert d == final