Skip to content

Commit b6506c5

Browse files
authored
⬆️ update test data (#148)
1 parent ada770f commit b6506c5

File tree

15 files changed

+204
-194
lines changed

15 files changed

+204
-194
lines changed

docs/predictions/standard/documents/passport_v1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Passport V1
77
:language: Python
88

99
.. autoclass:: mindee.documents.PassportV1
10-
:members:
10+
:members:

docs/predictions/standard/international.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ International
1111
.. include:: ./documents/invoice_splitter_v1.rst
1212
.. include:: ./documents/proof_of_address_v1.rst
1313
.. include:: ./documents/cropper_v1.rst
14-
.. include:: ./documents/material_certificate.rst
14+
.. include:: ./documents/material_certificate_v1.rst

mindee/documents/fr/id_card/id_card_v1.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
from typing import List, Optional, TypeVar
22

33
from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
4+
from mindee.fields.classification import ClassificationField
45
from mindee.fields.date import DateField
56
from mindee.fields.text import TextField
67

78

89
class IdCardV1(Document):
910
"""Carte Nationale d'Identité v1 prediction results."""
1011

11-
document_side: TextField
12-
"""The side of the document which is visible."""
13-
id_number: TextField
14-
"""The identification card number."""
15-
given_names: List[TextField]
16-
"""The given name(s) of the card holder."""
17-
surname: TextField
18-
"""The surname of the card holder."""
12+
authority: TextField
13+
"""The name of the issuing authority."""
1914
birth_date: DateField
2015
"""The date of birth of the card holder."""
2116
birth_place: TextField
2217
"""The place of birth of the card holder."""
18+
document_side: ClassificationField
19+
"""The side of the document which is visible."""
2320
expiry_date: DateField
2421
"""The expiry date of the identification card."""
25-
authority: TextField
26-
"""The name of the issuing authority."""
2722
gender: TextField
2823
"""The gender of the card holder."""
24+
given_names: List[TextField]
25+
"""The given name(s) of the card holder."""
26+
id_number: TextField
27+
"""The identification card number."""
2928
mrz1: TextField
3029
"""Machine Readable Zone, first line"""
3130
mrz2: TextField
3231
"""Machine Readable Zone, second line"""
32+
surname: TextField
33+
"""The surname of the card holder."""
3334

3435
def __init__(
3536
self,
@@ -61,20 +62,8 @@ def _build_from_api_prediction(
6162
:param api_prediction: Raw prediction from HTTP response
6263
:param page_n: Page number
6364
"""
64-
self.document_side = TextField(
65-
api_prediction.get("document_side", {}),
66-
page_id=page_n,
67-
)
68-
self.id_number = TextField(
69-
api_prediction["id_number"],
70-
page_id=page_n,
71-
)
72-
self.given_names = [
73-
TextField(prediction, page_id=page_n)
74-
for prediction in api_prediction["given_names"]
75-
]
76-
self.surname = TextField(
77-
api_prediction["surname"],
65+
self.authority = TextField(
66+
api_prediction["authority"],
7867
page_id=page_n,
7968
)
8069
self.birth_date = DateField(
@@ -85,18 +74,26 @@ def _build_from_api_prediction(
8574
api_prediction["birth_place"],
8675
page_id=page_n,
8776
)
88-
self.expiry_date = DateField(
89-
api_prediction["expiry_date"],
77+
self.document_side = ClassificationField(
78+
api_prediction.get("document_side", {}),
9079
page_id=page_n,
9180
)
92-
self.authority = TextField(
93-
api_prediction["authority"],
81+
self.expiry_date = DateField(
82+
api_prediction["expiry_date"],
9483
page_id=page_n,
9584
)
9685
self.gender = TextField(
9786
api_prediction["gender"],
9887
page_id=page_n,
9988
)
89+
self.given_names = [
90+
TextField(prediction, page_id=page_n)
91+
for prediction in api_prediction["given_names"]
92+
]
93+
self.id_number = TextField(
94+
api_prediction["id_number"],
95+
page_id=page_n,
96+
)
10097
self.mrz1 = TextField(
10198
api_prediction["mrz1"],
10299
page_id=page_n,
@@ -105,6 +102,10 @@ def _build_from_api_prediction(
105102
api_prediction["mrz2"],
106103
page_id=page_n,
107104
)
105+
self.surname = TextField(
106+
api_prediction["surname"],
107+
page_id=page_n,
108+
)
108109

109110
def __str__(self) -> str:
110111
given_names = "\n".join([str(item) for item in self.given_names])

mindee/documents/passport/passport_v1.py

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,37 @@
88

99

1010
class PassportV1(Document):
11-
"""Cropper v1 prediction results."""
11+
"""Passport v1 prediction results."""
1212

13+
birth_date: DateField
14+
"""The date of birth of the passport holder."""
15+
birth_place: TextField
16+
"""The place of birth of the passport holder."""
1317
country: TextField
14-
"""Country of issue"""
15-
id_number: TextField
16-
"""Passport number"""
18+
"""The country's 3 letter code (ISO 3166-1 alpha-3)."""
1719
expiry_date: DateField
18-
"""Date the passport expires"""
19-
issuance_date: DateField
20-
"""Date the passport was issued"""
21-
surname: TextField
22-
"""Holder's last name (surname)"""
23-
given_names: List[TextField]
24-
"""Holder's list of first (given) names"""
20+
"""The expiry date of the passport."""
2521
full_name: TextField
2622
"""
2723
Holder's full name.
2824
The combination of `given_names` and `surname` fields.
2925
"""
30-
birth_date: DateField
31-
"""Holder's date of birth"""
32-
birth_place: TextField
33-
"""Holder's place of birth"""
3426
gender: TextField
35-
"""Holder's gender or sex"""
36-
mrz1: TextField
37-
"""First line of the Machine-Readable Zone"""
38-
mrz2: TextField
39-
"""Second line of the Machine-Readable Zone"""
27+
"""The gender of the passport holder."""
28+
given_names: List[TextField]
29+
"""The given name(s) of the passport holder."""
30+
id_number: TextField
31+
"""The passport's identification number."""
32+
issuance_date: DateField
33+
"""The date the passport was issued."""
4034
mrz: TextField
4135
"""Combination of both MRZ fields."""
36+
mrz1: TextField
37+
"""Machine Readable Zone, first line"""
38+
mrz2: TextField
39+
"""Machine Readable Zone, second line"""
40+
surname: TextField
41+
"""The surname of the passport holder."""
4242

4343
def __init__(
4444
self,
@@ -47,7 +47,7 @@ def __init__(
4747
page_n: Optional[int] = None,
4848
):
4949
"""
50-
Passport document.
50+
Passport v1 prediction results.
5151
5252
:param api_prediction: Raw prediction from HTTP response
5353
:param input_source: Input object
@@ -67,25 +67,55 @@ def _build_from_api_prediction(
6767
self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None
6868
) -> None:
6969
"""
70-
Build the document from an API response JSON.
70+
Build the object from the prediction API JSON.
7171
7272
:param api_prediction: Raw prediction from HTTP response
7373
:param page_n: Page number for multi pages pdf input
7474
"""
75-
self.country = TextField(api_prediction["country"], page_id=page_n)
76-
self.id_number = TextField(api_prediction["id_number"], page_id=page_n)
77-
self.birth_date = DateField(api_prediction["birth_date"], page_id=page_n)
78-
self.expiry_date = DateField(api_prediction["expiry_date"], page_id=page_n)
79-
self.issuance_date = DateField(api_prediction["issuance_date"], page_id=page_n)
80-
self.birth_place = TextField(api_prediction["birth_place"], page_id=page_n)
81-
self.gender = TextField(api_prediction["gender"], page_id=page_n)
82-
self.surname = TextField(api_prediction["surname"], page_id=page_n)
83-
self.mrz1 = TextField(api_prediction["mrz1"], page_id=page_n)
84-
self.mrz2 = TextField(api_prediction["mrz2"], page_id=page_n)
75+
self.birth_date = DateField(
76+
api_prediction["birth_date"],
77+
page_id=page_n,
78+
)
79+
self.birth_place = TextField(
80+
api_prediction["birth_place"],
81+
page_id=page_n,
82+
)
83+
self.country = TextField(
84+
api_prediction["country"],
85+
page_id=page_n,
86+
)
87+
self.expiry_date = DateField(
88+
api_prediction["expiry_date"],
89+
page_id=page_n,
90+
)
91+
self.gender = TextField(
92+
api_prediction["gender"],
93+
page_id=page_n,
94+
)
8595
self.given_names = [
86-
TextField(given_name, page_id=page_n)
87-
for given_name in api_prediction["given_names"]
96+
TextField(prediction, page_id=page_n)
97+
for prediction in api_prediction["given_names"]
8898
]
99+
self.id_number = TextField(
100+
api_prediction["id_number"],
101+
page_id=page_n,
102+
)
103+
self.issuance_date = DateField(
104+
api_prediction["issuance_date"],
105+
page_id=page_n,
106+
)
107+
self.mrz1 = TextField(
108+
api_prediction["mrz1"],
109+
page_id=page_n,
110+
)
111+
self.mrz2 = TextField(
112+
api_prediction["mrz2"],
113+
page_id=page_n,
114+
)
115+
self.surname = TextField(
116+
api_prediction["surname"],
117+
page_id=page_n,
118+
)
89119
self.mrz = TextField({"value": None, "confidence": 0.0}, page_id=page_n)
90120
self.full_name = TextField({"value": None, "confidence": 0.0}, page_id=page_n)
91121

mindee/documents/receipt/receipt_v5.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ class ReceiptV5(Document):
1616
"""Receipt v5 prediction results."""
1717

1818
category: ClassificationField
19-
"""The receipt category among predefined classes."""
19+
"""The purchase category among predefined classes."""
2020
date: DateField
2121
"""The date the purchase was made."""
2222
document_type: ClassificationField
23-
"""Whether the document is an expense receipt or a credit card receipt."""
23+
"""One of: 'CREDIT CARD RECEIPT', 'EXPENSE RECEIPT'."""
2424
line_items: List[ReceiptV5LineItem]
25-
"""Full extraction of lines, including: description, quantity, unit price and total."""
25+
"""List of line item details."""
2626
locale: LocaleField
27-
"""The locale identifier in BCP 47 (RFC 5646) format: ISO language code, '-', ISO country code."""
27+
"""The locale detected on the document."""
2828
subcategory: ClassificationField
29-
"""The receipt sub category among predefined classes for transport and food."""
29+
"""The purchase subcategory among predefined classes for transport and food."""
3030
supplier_address: TextField
31-
"""The address of the supplier or merchant returned as a single string."""
31+
"""The address of the supplier or merchant."""
3232
supplier_company_registrations: List[CompanyRegistrationField]
33-
"""List of supplier company registrations or identifiers."""
33+
"""List of company registrations associated to the supplier."""
3434
supplier_name: TextField
3535
"""The name of the supplier or merchant."""
3636
supplier_phone_number: TextField
37-
"""The Phone number of the supplier or merchant returned as a single string."""
37+
"""The phone number of the supplier or merchant."""
3838
taxes: Taxes
39-
"""List of tax lines information including: Amount, tax rate, tax base amount and tax code."""
39+
"""List of tax lines information."""
4040
time: TextField
41-
"""Time of purchase with 24 hours formatting (HH:MM)."""
41+
"""The time the purchase was made."""
4242
tip: AmountField
4343
"""The total amount of tip and gratuity."""
4444
total_amount: AmountField
45-
"""The total amount paid including taxes, discounts, fees, tips, and gratuity."""
45+
"""The total amount paid: includes taxes, discounts, fees, tips, and gratuity."""
4646
total_net: AmountField
47-
"""The total amount excluding taxes."""
47+
"""The net amount paid: does not include taxes, fees, and discounts."""
4848
total_tax: AmountField
4949
"""The total amount of taxes."""
5050

@@ -176,13 +176,13 @@ def __str__(self) -> str:
176176
"=====================\n"
177177
f":Filename: {self.filename or ''}\n"
178178
f":Expense Locale: {self.locale}\n"
179-
f":Expense Category: {self.category}\n"
180-
f":Expense Sub Category: {self.subcategory}\n"
179+
f":Purchase Category: {self.category}\n"
180+
f":Purchase Subcategory: {self.subcategory}\n"
181181
f":Document Type: {self.document_type}\n"
182182
f":Purchase Date: {self.date}\n"
183183
f":Purchase Time: {self.time}\n"
184184
f":Total Amount: {self.total_amount}\n"
185-
f":Total Excluding Taxes: {self.total_net}\n"
185+
f":Total Net: {self.total_net}\n"
186186
f":Total Tax: {self.total_tax}\n"
187187
f":Tip and Gratuity: {self.tip}\n"
188188
f":Taxes: {self.taxes}\n"

mindee/documents/receipt/receipt_v5_line_item.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class ReceiptV5LineItem(FieldPositionMixin, FieldConfidenceMixin):
13-
"""Full extraction of lines, including: description, quantity, unit price and total."""
13+
"""List of line item details."""
1414

1515
description: Optional[str]
1616
"""The item description."""
@@ -20,8 +20,6 @@ class ReceiptV5LineItem(FieldPositionMixin, FieldConfidenceMixin):
2020
"""The item total amount."""
2121
unit_price: Optional[float]
2222
"""The item unit price."""
23-
confidence: float = 0.0
24-
"""Confidence score"""
2523
page_n: int
2624
"""The document page on which the information was found."""
2725

tests/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
RECEIPT_DATA_DIR = "./tests/data/receipt"
22
INVOICE_DATA_DIR = "./tests/data/invoice"
3-
FINANCIAL_DOC_DATA_DIR = "./tests/data/financial_document"
4-
PASSPORT_DATA_DIR = "./tests/data/passport"
5-
PROOF_OF_ADDRESS_DATA_DIR = "./tests/data/proof_of_address"
63
US_BANK_CHECK_DATA_DIR = "./tests/data/us/bank_check"
4+
PASSPORT_DATA_DIR = "./tests/data/passport"
75
FR_CARTE_GRISE_DATA_DIR = "./tests/data/fr/carte_grise"
86
CUSTOM_DATA_DIR = "./tests/data/custom"
97
CROPPER_DATA_DIR = "./tests/data/cropper"

tests/documents/fr/test_id_card_v1.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from mindee.documents.fr import IdCardV1
66

77
FR_ID_CARD_DATA_DIR = "./tests/data/fr/id_card"
8-
98
FILE_PATH_FR_ID_CARD_V1_COMPLETE = f"{ FR_ID_CARD_DATA_DIR }/response_v1/complete.json"
109
FILE_PATH_FR_ID_CARD_V1_EMPTY = f"{ FR_ID_CARD_DATA_DIR }/response_v1/empty.json"
1110

@@ -28,6 +27,19 @@ def id_card_v1_page0():
2827
return IdCardV1(json_data["document"]["inference"]["pages"][0], page_n=0)
2928

3029

30+
def test_empty_doc_constructor(id_card_v1_doc_empty):
31+
assert id_card_v1_doc_empty.id_number.value is None
32+
assert len(id_card_v1_doc_empty.given_names) == 0
33+
assert id_card_v1_doc_empty.surname.value is None
34+
assert id_card_v1_doc_empty.birth_date.value is None
35+
assert id_card_v1_doc_empty.birth_place.value is None
36+
assert id_card_v1_doc_empty.expiry_date.value is None
37+
assert id_card_v1_doc_empty.authority.value is None
38+
assert id_card_v1_doc_empty.gender.value is None
39+
assert id_card_v1_doc_empty.mrz1.value is None
40+
assert id_card_v1_doc_empty.mrz2.value is None
41+
42+
3143
def test_doc_constructor(id_card_v1_doc):
3244
file_path = f"{ FR_ID_CARD_DATA_DIR }/response_v1/doc_to_string.txt"
3345
reference_str = open(file_path, "r", encoding="utf-8").read().strip()

tests/documents/test_financial_document_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import pytest
44

55
from mindee.documents import FinancialDocumentV1
6-
from tests import FINANCIAL_DOC_DATA_DIR
76

7+
FINANCIAL_DOC_DATA_DIR = "./tests/data/financial_document"
88
FILE_PATH_FINANCIAL_DOC_V1_INVOICE = (
99
f"{FINANCIAL_DOC_DATA_DIR}/response_v1/complete_invoice.json"
1010
)

0 commit comments

Comments
 (0)