Entity Visualization

Most features that return DocumentEntity objects are of EntityList type. It is an extension of the list data type with the intention of providing visualization features to these entities.

EntityList

The EntityList is an extension of list type with custom functions to print document entities in a well formatted manner and visualize on top of the document page with their BoundingBox information.

The two main functions within this class are pretty_print() and visualize(). Use pretty_print() to get a string formatted output of your custom list of entities. Use visualize() to get the bounding box visualization of the entities on the document page images.

class textractor.visualizers.entitylist.EntityList(objs=None)

Bases: list, Generic[T]

Creates a list type object, initially empty but extended with the list passed in objs.

Parameters

objs (list) – Custom list of objects that can be visualized with this class.

pretty_print(table_format: TableFormat = TableFormat.GITHUB, with_confidence: bool = False, with_geo: bool = False, with_page_number: bool = False, trim: bool = False) str

Returns a formatted string output for each of the entities in the list according to its entity type.

Parameters
  • table_format (TableFormat) – Choose one of the defined TableFormat types to decorate the table output string. This is a predefined set of choices by the PyPI tabulate package. It is used only if there are KeyValues or Tables in the list of textractor.entities.

  • with_confidence (bool) – Flag to add the confidence of prediction to the entity string. default= False.

  • with_geo (bool) – Flag to add the bounding box information to the entity string. default= False.

  • with_page_number (bool) – Flag to add the page number to the entity string. default= False.

  • trim (bool) – Flag to trim text in the entity string. default= False.

Returns

Returns a formatted string output for each of the entities in the list according to its entity type.

Return type

str

visualize(with_text: bool = True, with_words: bool = True, with_confidence: bool = False, font_size_ratio: float = 0.5) List

Returns list of PIL Images with bounding boxes drawn around the entities in the list.

Parameters
  • with_text (bool) – Flag to print the OCR output of Textract on top of the text bounding box.

  • with_confidence (bool) – Flag to print the confidence of prediction on top of the entity bounding box.

Returns

Returns list of PIL Images with bounding boxes drawn around the entities in the list.

Return type

list