Skip to content

Commit e322198

Browse files
authored
♻️ update product string output (#156)
1 parent 9c3dba2 commit e322198

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+448
-391
lines changed

docs/extras/code_samples/bank_check_v1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mindee_client = Client(api_key="my-api-key")
66
# Load a file from disk
77
input_doc = mindee_client.doc_from_path("/path/to/the/file.ext")
88

9-
# Parse the US Bank Check Details by passing the appropriate type
9+
# Parse the Bank Check by passing the appropriate type
1010
result = input_doc.parse(documents.us.TypeBankCheckV1)
1111

1212
# Print a brief summary of the parsed data

docs/predictions/standard/documents/us/bank_check_v1.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ Bank Check V1
88

99
.. autoclass:: mindee.documents.us.BankCheckV1
1010
:members:
11-
:undoc-members:

mindee/documents/cropper/cropper_v1.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
class CropperV1(Document):
88
"""Cropper v1 prediction results."""
99

10-
cropping: List[PositionField]
11-
"""List of all detected cropped elements in the image"""
10+
cropping: List[PositionField] = []
11+
"""List of documents found in the image."""
1212

1313
def __init__(
1414
self,
15-
api_prediction: TypeApiPrediction,
15+
api_prediction=None,
1616
input_source=None,
1717
page_n: Optional[int] = None,
1818
):
1919
"""
20-
Custom document object.
20+
Cropper v1 prediction results.
2121
22-
:param document_type: Document type
2322
:param api_prediction: Raw prediction from HTTP response
2423
:param input_source: Input object
2524
:param page_n: Page number for multi pages pdf input
@@ -35,27 +34,33 @@ def __init__(
3534
def _build_from_api_prediction(
3635
self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None
3736
) -> None:
38-
"""Build the document from an API response JSON."""
39-
self.cropping = []
37+
"""
38+
Build the object from the prediction API JSON.
4039
41-
# cropping is only present on pages
40+
:param api_prediction: Raw prediction from HTTP response
41+
:param page_n: Page number
42+
"""
4243
if page_n is None:
4344
return
4445

45-
for crop in api_prediction["cropping"]:
46-
self.cropping.append(PositionField(prediction=crop))
46+
self.cropping = [
47+
PositionField(prediction, page_id=page_n)
48+
for prediction in api_prediction["cropping"]
49+
]
4750

48-
def _checklist(self) -> None:
49-
pass
50-
51-
def __str__(self):
52-
cropping = "\n ".join([str(crop) for crop in self.cropping])
51+
def __str__(self) -> str:
52+
cropping = f"\n { ' ' * 18 }".join(
53+
[str(item) for item in self.cropping],
54+
)
5355
return clean_out_string(
54-
"----- Cropper Data -----\n"
55-
f"Filename: {self.filename or ''}\n"
56-
f"Cropping: {cropping}\n"
57-
"------------------------"
56+
"Cropper V1 Prediction\n"
57+
"=====================\n"
58+
f":Filename: {self.filename or ''}\n"
59+
f":Document Cropper: {cropping}\n"
5860
)
5961

6062

61-
TypeCropperV1 = TypeVar("TypeCropperV1", bound=CropperV1)
63+
TypeCropperV1 = TypeVar(
64+
"TypeCropperV1",
65+
bound=CropperV1,
66+
)

mindee/documents/custom/custom_v1.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ def _build_from_api_prediction(
5757
self.fields[field_name] = ListField(prediction=field, page_n=page_n)
5858

5959
def __str__(self) -> str:
60-
custom_doc_str = f"----- {self.type} -----\nFilename: {self.filename or ''}\n"
60+
custom_doc_str = f"{self.type} V1 Prediction"
61+
custom_doc_str += "\n" + "=" * len(custom_doc_str)
62+
custom_doc_str += f"\n:Filename: {self.filename or ''}\n"
63+
6164
for class_name, class_info in self.classifications.items():
62-
custom_doc_str += f"{class_name}: {class_info}\n"
65+
custom_doc_str += f":{class_name}: {class_info}\n"
6366
for field_name, field_info in self.fields.items():
64-
custom_doc_str += f"{field_name}: {field_info}\n"
65-
custom_doc_str += "----------------------"
67+
custom_doc_str += f":{field_name}: {field_info}\n"
6668
return clean_out_string(custom_doc_str)
6769

6870

mindee/documents/eu/license_plate/license_plate_v1.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ def _build_from_api_prediction(
4646
]
4747

4848
def __str__(self) -> str:
49-
license_plates = f"\n { ' ' * 15 }".join(
50-
[str(item) for item in self.license_plates]
49+
license_plates = f"\n { ' ' * 16 }".join(
50+
[str(item) for item in self.license_plates],
5151
)
5252
return clean_out_string(
53-
"----- EU License Plate V1 -----\n"
54-
f"Filename: {self.filename or ''}\n"
55-
f"License Plates: { license_plates }\n"
56-
"----------------------"
53+
"EU License Plate V1 Prediction\n"
54+
"==============================\n"
55+
f":Filename: {self.filename or ''}\n"
56+
f":License Plates: {license_plates}\n"
5757
)
5858

5959

60-
TypeLicensePlateV1 = TypeVar("TypeLicensePlateV1", bound=LicensePlateV1)
60+
TypeLicensePlateV1 = TypeVar(
61+
"TypeLicensePlateV1",
62+
bound=LicensePlateV1,
63+
)

mindee/documents/financial_document/financial_document_v1.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ def _line_items_to_str(self) -> str:
217217
return out_str
218218

219219
def __str__(self) -> str:
220-
customer_company_registrations = f"\n { ' ' * 31 }".join(
220+
customer_company_registrations = f"\n { ' ' * 32 }".join(
221221
[str(item) for item in self.customer_company_registrations],
222222
)
223-
reference_numbers = f"\n { ' ' * 18 }".join(
223+
reference_numbers = f"\n { ' ' * 19 }".join(
224224
[str(item) for item in self.reference_numbers],
225225
)
226-
supplier_company_registrations = f"\n { ' ' * 31 }".join(
226+
supplier_company_registrations = f"\n { ' ' * 32 }".join(
227227
[str(item) for item in self.supplier_company_registrations],
228228
)
229-
supplier_payment_details = f"\n { ' ' * 25 }".join(
229+
supplier_payment_details = f"\n { ' ' * 26 }".join(
230230
[str(item) for item in self.supplier_payment_details],
231231
)
232232
return clean_out_string(
@@ -259,4 +259,7 @@ def __str__(self) -> str:
259259
)
260260

261261

262-
TypeFinancialDocumentV1 = TypeVar("TypeFinancialDocumentV1", bound=FinancialDocumentV1)
262+
TypeFinancialDocumentV1 = TypeVar(
263+
"TypeFinancialDocumentV1",
264+
bound=FinancialDocumentV1,
265+
)

mindee/documents/fr/bank_account_details/bank_account_details_v1.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
class BankAccountDetailsV1(Document):
88
"""Bank Account Details v1 prediction results."""
99

10-
iban: TextField
11-
"""The International Bank Account Number (IBAN)."""
1210
account_holder_name: TextField
1311
"""The name of the account holder as seen on the document."""
12+
iban: TextField
13+
"""The International Bank Account Number (IBAN)."""
1414
swift: TextField
1515
"""The bank's SWIFT Business Identifier Code (BIC)."""
1616

@@ -44,30 +44,31 @@ def _build_from_api_prediction(
4444
:param api_prediction: Raw prediction from HTTP response
4545
:param page_n: Page number
4646
"""
47-
self.iban = TextField(
48-
api_prediction["iban"],
49-
page_id=page_n,
50-
)
5147
self.account_holder_name = TextField(
5248
api_prediction["account_holder_name"],
5349
page_id=page_n,
5450
)
51+
self.iban = TextField(
52+
api_prediction["iban"],
53+
page_id=page_n,
54+
)
5555
self.swift = TextField(
5656
api_prediction["swift"],
5757
page_id=page_n,
5858
)
5959

6060
def __str__(self) -> str:
6161
return clean_out_string(
62-
"----- FR Bank Account Details V1 -----\n"
63-
f"Filename: {self.filename or ''}\n"
64-
f"IBAN: { self.iban }\n"
65-
f"Account Holder's Name: { self.account_holder_name }\n"
66-
f"SWIFT Code: { self.swift }\n"
67-
"----------------------"
62+
"FR Bank Account Details V1 Prediction\n"
63+
"=====================================\n"
64+
f":Filename: {self.filename or ''}\n"
65+
f":IBAN: {self.iban}\n"
66+
f":Account Holder's Name: {self.account_holder_name}\n"
67+
f":SWIFT Code: {self.swift}\n"
6868
)
6969

7070

7171
TypeBankAccountDetailsV1 = TypeVar(
72-
"TypeBankAccountDetailsV1", bound=BankAccountDetailsV1
72+
"TypeBankAccountDetailsV1",
73+
bound=BankAccountDetailsV1,
7374
)

mindee/documents/fr/bank_account_details/bank_account_details_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ def __str__(self) -> str:
7878

7979

8080
TypeBankAccountDetailsV2 = TypeVar(
81-
"TypeBankAccountDetailsV2", bound=BankAccountDetailsV2
81+
"TypeBankAccountDetailsV2",
82+
bound=BankAccountDetailsV2,
8283
)

mindee/documents/fr/carte_vitale/carte_vitale_v1.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class CarteVitaleV1(Document):
1010

1111
given_names: List[TextField]
1212
"""The given name(s) of the card holder."""
13-
surname: TextField
14-
"""The surname of the card holder."""
15-
social_security: TextField
16-
"""The Social Security Number (Numéro de Sécurité Sociale) of the card holder"""
1713
issuance_date: DateField
1814
"""The date the card was issued."""
15+
social_security: TextField
16+
"""The Social Security Number (Numéro de Sécurité Sociale) of the card holder"""
17+
surname: TextField
18+
"""The surname of the card holder."""
1919

2020
def __init__(
2121
self,
@@ -51,30 +51,35 @@ def _build_from_api_prediction(
5151
TextField(prediction, page_id=page_n)
5252
for prediction in api_prediction["given_names"]
5353
]
54-
self.surname = TextField(
55-
api_prediction["surname"],
54+
self.issuance_date = DateField(
55+
api_prediction["issuance_date"],
5656
page_id=page_n,
5757
)
5858
self.social_security = TextField(
5959
api_prediction["social_security"],
6060
page_id=page_n,
6161
)
62-
self.issuance_date = DateField(
63-
api_prediction["issuance_date"],
62+
self.surname = TextField(
63+
api_prediction["surname"],
6464
page_id=page_n,
6565
)
6666

6767
def __str__(self) -> str:
68-
given_names = "\n".join([str(item) for item in self.given_names])
68+
given_names = f"\n { ' ' * 15 }".join(
69+
[str(item) for item in self.given_names],
70+
)
6971
return clean_out_string(
70-
"----- FR Carte Vitale V1 -----\n"
71-
f"Filename: {self.filename or ''}\n"
72-
f"Given Name(s): { given_names }\n"
73-
f"Surname: { self.surname }\n"
74-
f"Social Security Number: { self.social_security }\n"
75-
f"Issuance Date: { self.issuance_date }\n"
76-
"----------------------"
72+
"FR Carte Vitale V1 Prediction\n"
73+
"=============================\n"
74+
f":Filename: {self.filename or ''}\n"
75+
f":Given Name(s): {given_names}\n"
76+
f":Surname: {self.surname}\n"
77+
f":Social Security Number: {self.social_security}\n"
78+
f":Issuance Date: {self.issuance_date}\n"
7779
)
7880

7981

80-
TypeCarteVitaleV1 = TypeVar("TypeCarteVitaleV1", bound=CarteVitaleV1)
82+
TypeCarteVitaleV1 = TypeVar(
83+
"TypeCarteVitaleV1",
84+
bound=CarteVitaleV1,
85+
)

mindee/documents/fr/id_card/id_card_v1.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,28 @@ def _build_from_api_prediction(
108108
)
109109

110110
def __str__(self) -> str:
111-
given_names = "\n".join([str(item) for item in self.given_names])
111+
given_names = f"\n { ' ' * 15 }".join(
112+
[str(item) for item in self.given_names],
113+
)
112114
return clean_out_string(
113-
"----- FR Carte Nationale d'Identité V1 -----\n"
114-
f"Filename: {self.filename or ''}\n"
115-
f"Document Side: { self.document_side }\n"
116-
f"Identity Number: { self.id_number }\n"
117-
f"Given Name(s): { given_names }\n"
118-
f"Surname: { self.surname }\n"
119-
f"Date of Birth: { self.birth_date }\n"
120-
f"Place of Birth: { self.birth_place }\n"
121-
f"Expiry Date: { self.expiry_date }\n"
122-
f"Issuing Authority: { self.authority }\n"
123-
f"Gender: { self.gender }\n"
124-
f"MRZ Line 1: { self.mrz1 }\n"
125-
f"MRZ Line 2: { self.mrz2 }\n"
126-
"----------------------"
115+
"FR Carte Nationale d'Identité V1 Prediction\n"
116+
"===========================================\n"
117+
f":Filename: {self.filename or ''}\n"
118+
f":Document Side: {self.document_side}\n"
119+
f":Identity Number: {self.id_number}\n"
120+
f":Given Name(s): {given_names}\n"
121+
f":Surname: {self.surname}\n"
122+
f":Date of Birth: {self.birth_date}\n"
123+
f":Place of Birth: {self.birth_place}\n"
124+
f":Expiry Date: {self.expiry_date}\n"
125+
f":Issuing Authority: {self.authority}\n"
126+
f":Gender: {self.gender}\n"
127+
f":MRZ Line 1: {self.mrz1}\n"
128+
f":MRZ Line 2: {self.mrz2}\n"
127129
)
128130

129131

130-
TypeIdCardV1 = TypeVar("TypeIdCardV1", bound=IdCardV1)
132+
TypeIdCardV1 = TypeVar(
133+
"TypeIdCardV1",
134+
bound=IdCardV1,
135+
)

0 commit comments

Comments
 (0)