pycognaize.document.tag.table_tag.TableTag

class TableTag(left, right, top, bottom, page, cell_data)[source]

Bases: BoxTag

Base class for all pycognaize table fields

Parameters:
  • page (Page)

  • cell_data (dict)

Methods

construct_from_raw

Build Field from pycognaize raw data

distance

Return the Euclidean distance of two tag centers

get_top_left

get_width_height

hshift

Shifts rectangle horizontally

intersects

Checks id there is an intersection between this and other rectangle

iou

Calculate Intersection over Union for given rectangles

is_in_rectangle

Check if the rectangle is in the other rectangle

letter_2_num

Convert excel style coordinates into zero index coordinate

set_class_confidence

shift

Shifts rectangle by 2 axes simultaneously

split_excel_letters_numbers

Return the letters and numbers of the Excel coordinate as a tuple.

to_dict

Converts table tag to dict

to_string

Returns a string representation of the table

vshift

Shifts rectangle vertically

Attributes

area

Area of the rectangle

bottom

cell_data

cells

center

Center point of the rectangle

confidence

df

height

Height of the rectangle

left

page

raw_df

right

top

width

Width of the rectangle

xcenter

Center of horizontal line of the rectangle

ycenter

Center of vertical line of the rectangle

__add__(other)

Merge two rectangles into one

Parameters:

other (Union[BoxTag, Cell])

Return type:

BoxTag

property area: float

Area of the rectangle

property center: Tuple[float, float]

Center point of the rectangle

classmethod construct_from_raw(raw, page)[source]

Build Field from pycognaize raw data

Parameters:
  • raw (dict) – pycognaize field’s tag info

  • page (Page) – Page to which the tag belongs

Return type:

TableTag

Returns:

distance(other)

Return the Euclidean distance of two tag centers

Parameters:

other (BoxTag)

Return type:

Union[int, float]

property height: int | float

Height of the rectangle

hshift(by)

Shifts rectangle horizontally

Parameters:

by – the amount by which the tag should be horizontally shifted

Return type:

BoxTag

Returns:

shifted rectangle

intersects(other)

Checks id there is an intersection between this and other rectangle

Parameters:

other (Union[BoxTag, Cell]) – Rectangle object

Return type:

bool

iou(other)

Calculate Intersection over Union for given rectangles

Return type:

Union[int, float]

is_in_rectangle(other, thresh)

Check if the rectangle is in the other rectangle

Parameters:
  • other (BoxTag) – Another rectangle object

  • thresh (float) – If the fraction area of the rectangle is in the other rectangle is larger or equal to thresh, it is in the other rectangle

Return type:

bool

Returns:

True if rectangle is in other rectangle, False otherwise

letter_2_num(letters)[source]

Convert excel style coordinates into zero index coordinate

Return type:

int

shift(horizontal, vertical)

Shifts rectangle by 2 axes simultaneously

Parameters:
  • horizontal

  • vertical

Return type:

BoxTag

Returns:

shifted rectangle

static split_excel_letters_numbers(str_coord)[source]

Return the letters and numbers of the Excel coordinate as a tuple. If the string is not a valid Excel coordinate, return None

Parameters:

str_coord (str)

Return type:

Optional[Tuple[str, int]]

to_dict()[source]

Converts table tag to dict

Return type:

dict

to_string()[source]

Returns a string representation of the table

Return type:

str

vshift(by)

Shifts rectangle vertically

Parameters:

by – the amount by which the tag should be vertically shifted

Return type:

BoxTag

Returns:

shifted rectangle

property width: int | float

Width of the rectangle

property xcenter: float

Center of horizontal line of the rectangle

property ycenter: float

Center of vertical line of the rectangle