Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,24 @@ def __repr__(self):
)[:1024]
)

def to_dict(self):
return {
"page_number": self.page_number,
"text_angle": self.text_angle,
"width": self.width,
"height": self.height,
"unit": self.unit,
"tables": [
table.to_dict() for table in self.tables
] if self.tables else None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like this, I'll do something similar in mine.

"lines": [
line.to_dict() for line in self.lines
] if self.lines else None,
"selection_marks": [
mark.to_dict() for mark in self.selection_marks
] if self.selection_marks else None
}


class FormLine(FormElement):
"""An object representing an extracted line of text.
Expand Down Expand Up @@ -633,8 +651,8 @@ def _from_generated(cls, mark, page):
)

def __repr__(self):
return "FormSelectionMark(text={}, bounding_box={}, confidence={}, page_number={}, state={})".format(
self.text, self.bounding_box, self.confidence, self.page_number, self.state
return "FormSelectionMark(text={}, bounding_box={}, confidence={}, page_number={}, state={}, kind={})".format(
self.text, self.bounding_box, self.confidence, self.page_number, self.state, self.kind
)[
:1024
]
Expand Down Expand Up @@ -689,6 +707,15 @@ def __repr__(self):
:1024
]

def to_dict(self):
return {
"page_number": self.page_number,
"row_count": self.row_count,
"column_count": self.column_count,
"cells": [cell.to_dict() for cell in self.cells],
"bounding_box": [box.to_dict() for box in self.bounding_box]
}


class FormTableCell(object): # pylint:disable=too-many-instance-attributes
"""Represents a cell contained in a table recognized from the input document.
Expand Down Expand Up @@ -774,6 +801,22 @@ def __repr__(self):
]
)

def to_dict(self):
return {
"text": self.text,
"row_index": self.row_index,
"column_index": self.column_index,
"row_span": self.row_span,
"column_span": self.column_span,
"confidence": self.confidence,
"is_header": self.is_header,
"is_footer": self.is_footer,
"page_number": self.page_number,
"bounding_box": [box.to_dict() for box in self.bounding_box],
"field_elements": [element.to_dict() for element in self.field_elements]
if self.field_elements else None
}


class CustomFormModel(object):
"""Represents a model trained from custom forms.
Expand Down Expand Up @@ -876,6 +919,19 @@ def __repr__(self):
]
)

def to_dict(self):
return {
"model_id": self.model_id,
"status": self.status,
"training_started_on": self.training_started_on,
"training_completed_on": self.training_completed_on,
"submodels": [submodel.to_dict() for submodel in self.submodels],
"errors": [err.to_dict() for err in self.errors],
"training_documents": [doc.to_dict() for doc in self.training_documents],
"model_name": self.model_name,
"properties": self.properties.to_dict()
}


class CustomFormSubmodel(object):
"""Represents a submodel that extracts fields from a specific type of form.
Expand Down Expand Up @@ -970,6 +1026,14 @@ def __repr__(self):
:1024
]

def to_dict(self):
return {
"model_id": self.model_id,
"accuracy": self.accuracy,
"fields": {k: v.to_dict() for k, v in self.fields.items()},
"form_type": self.form_type
}


class CustomFormModelField(object):
"""A field that the model will extract from forms it analyzes.
Expand Down Expand Up @@ -1003,6 +1067,13 @@ def __repr__(self):
self.label, self.name, self.accuracy
)[:1024]

def to_dict(self):
return {
"label": self.label,
"accuracy": self.accuracy,
"name": self.name
}


class TrainingDocumentInfo(object):
"""Report for an individual document used for training
Expand Down Expand Up @@ -1074,6 +1145,15 @@ def __repr__(self):
:1024
]

def to_dict(self):
return {
"name": self.name,
"status": self.status,
"page_count": self.page_count,
"errors": [err.to_dict() for err in self.errors],
"model_id": self.model_id
}


class FormRecognizerError(object):
"""Represents an error that occurred while training.
Expand All @@ -1099,6 +1179,12 @@ def __repr__(self):
self.code, self.message
)[:1024]

def to_dict(self):
return {
"code": self.code,
"message": self.message
}


class CustomFormModelInfo(object):
"""Custom model information.
Expand Down Expand Up @@ -1164,6 +1250,16 @@ def __repr__(self):
)[:1024]
)

def to_dict(self):
return {
"model_id": self.model_id,
"status": self.status,
"training_started_on": self.training_started_on,
"training_completed_on": self.training_completed_on,
"model_name": self.model_name,
"properties": self.properties.to_dict()
}


class AccountProperties(object):
"""Summary of all the custom models on the account.
Expand All @@ -1188,6 +1284,12 @@ def __repr__(self):
self.custom_model_count, self.custom_model_limit
)[:1024]

def to_dict(self):
return {
"custom_model_count": self.custom_model_count,
"custom_model_limit": self.custom_model_limit
}


class CustomFormModelProperties(object):
"""Optional model properties.
Expand All @@ -1209,6 +1311,11 @@ def __repr__(self):
self.is_composed_model
)

def to_dict(self):
return {
"is_composed_model": self.is_composed_model
}


class TextAppearance(object):
"""An object representing the appearance of the text line.
Expand Down