diff --git a/docs/extras/code_samples/international_id_v1_async.txt b/docs/extras/code_samples/international_id_v1_async.txt deleted file mode 100644 index 6bd07584..00000000 --- a/docs/extras/code_samples/international_id_v1_async.txt +++ /dev/null @@ -1,17 +0,0 @@ -from mindee import Client, product, AsyncPredictResponse -from time import sleep - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and enqueue it. -result: AsyncPredictResponse = mindee_client.enqueue_and_parse( - product.InternationalIdV1, - input_doc, -) - -# Print a brief summary of the parsed data -print(result.document) diff --git a/mindee/product/__init__.py b/mindee/product/__init__.py index bcb213bd..9c718f4d 100644 --- a/mindee/product/__init__.py +++ b/mindee/product/__init__.py @@ -19,12 +19,6 @@ FinancialDocumentV1LineItem, ) from mindee.product.generated import GeneratedV1, GeneratedV1Document, GeneratedV1Page -from mindee.product.international_id import ( - InternationalIdV1, - InternationalIdV1Document, - InternationalIdV2, - InternationalIdV2Document, -) from mindee.product.invoice import InvoiceV4, InvoiceV4Document, InvoiceV4LineItem from mindee.product.invoice_splitter import InvoiceSplitterV1, InvoiceSplitterV1Document from mindee.product.material_certificate import ( diff --git a/mindee/product/international_id/__init__.py b/mindee/product/international_id/__init__.py index ef36d586..a3dba05d 100644 --- a/mindee/product/international_id/__init__.py +++ b/mindee/product/international_id/__init__.py @@ -1,7 +1,3 @@ -from mindee.product.international_id.international_id_v1 import InternationalIdV1 -from mindee.product.international_id.international_id_v1_document import ( - InternationalIdV1Document, -) from mindee.product.international_id.international_id_v2 import InternationalIdV2 from mindee.product.international_id.international_id_v2_document import ( InternationalIdV2Document, diff --git a/mindee/product/international_id/international_id_v1.py b/mindee/product/international_id/international_id_v1.py deleted file mode 100644 index ccb1d7c2..00000000 --- a/mindee/product/international_id/international_id_v1.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import List - -from mindee.parsing.common.inference import Inference -from mindee.parsing.common.page import Page -from mindee.parsing.common.string_dict import StringDict -from mindee.product.international_id.international_id_v1_document import ( - InternationalIdV1Document, -) - - -class InternationalIdV1(Inference): - """Inference prediction for International ID, API version 1.""" - - prediction: InternationalIdV1Document - """Document-level prediction.""" - pages: List[Page[InternationalIdV1Document]] - """Page-level prediction(s).""" - endpoint_name = "international_id" - """Name of the endpoint.""" - endpoint_version = "1" - """Version of the endpoint.""" - - def __init__(self, raw_prediction: StringDict): - """ - International ID v1 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction) - - self.prediction = InternationalIdV1Document(raw_prediction["prediction"]) - self.pages = [] - for page in raw_prediction["pages"]: - try: - page_prediction = page["prediction"] - except KeyError: - continue - if page_prediction: - self.pages.append(Page(InternationalIdV1Document, page)) diff --git a/mindee/product/international_id/international_id_v1_document.py b/mindee/product/international_id/international_id_v1_document.py deleted file mode 100644 index 0eb2e33c..00000000 --- a/mindee/product/international_id/international_id_v1_document.py +++ /dev/null @@ -1,140 +0,0 @@ -from typing import List, Optional - -from mindee.parsing.common.prediction import Prediction -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.classification import ClassificationField -from mindee.parsing.standard.date import DateField -from mindee.parsing.standard.text import StringField - - -class InternationalIdV1Document(Prediction): - """Document data for International ID, API version 1.""" - - address: StringField - """The physical location of the document holder's residence.""" - birth_date: DateField - """The date of birth of the document holder.""" - birth_place: StringField - """The location where the document holder was born.""" - country_of_issue: StringField - """The country that issued the identification document.""" - document_number: StringField - """The unique identifier assigned to the identification document.""" - document_type: ClassificationField - """The type of identification document being used.""" - expiry_date: DateField - """The date when the document will no longer be valid for use.""" - given_names: List[StringField] - """The first names or given names of the document holder.""" - issue_date: DateField - """The date when the document was issued.""" - mrz1: StringField - """First line of information in a standardized format for easy machine reading and processing.""" - mrz2: StringField - """Second line of information in a standardized format for easy machine reading and processing.""" - mrz3: StringField - """Third line of information in a standardized format for easy machine reading and processing.""" - nationality: StringField - """Indicates the country of citizenship or nationality of the document holder.""" - sex: StringField - """The document holder's biological sex, such as male or female.""" - surnames: List[StringField] - """The surnames of the document holder.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - International ID document. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction, page_id) - self.address = StringField( - raw_prediction["address"], - page_id=page_id, - ) - self.birth_date = DateField( - raw_prediction["birth_date"], - page_id=page_id, - ) - self.birth_place = StringField( - raw_prediction["birth_place"], - page_id=page_id, - ) - self.country_of_issue = StringField( - raw_prediction["country_of_issue"], - page_id=page_id, - ) - self.document_number = StringField( - raw_prediction["document_number"], - page_id=page_id, - ) - self.document_type = ClassificationField( - raw_prediction["document_type"], - page_id=page_id, - ) - self.expiry_date = DateField( - raw_prediction["expiry_date"], - page_id=page_id, - ) - self.given_names = [ - StringField(prediction, page_id=page_id) - for prediction in raw_prediction["given_names"] - ] - self.issue_date = DateField( - raw_prediction["issue_date"], - page_id=page_id, - ) - self.mrz1 = StringField( - raw_prediction["mrz1"], - page_id=page_id, - ) - self.mrz2 = StringField( - raw_prediction["mrz2"], - page_id=page_id, - ) - self.mrz3 = StringField( - raw_prediction["mrz3"], - page_id=page_id, - ) - self.nationality = StringField( - raw_prediction["nationality"], - page_id=page_id, - ) - self.sex = StringField( - raw_prediction["sex"], - page_id=page_id, - ) - self.surnames = [ - StringField(prediction, page_id=page_id) - for prediction in raw_prediction["surnames"] - ] - - def __str__(self) -> str: - given_names = f"\n { ' ' * 13 }".join( - [str(item) for item in self.given_names], - ) - surnames = f"\n { ' ' * 10 }".join( - [str(item) for item in self.surnames], - ) - out_str: str = f":Document Type: {self.document_type}\n" - out_str += f":Document Number: {self.document_number}\n" - out_str += f":Country of Issue: {self.country_of_issue}\n" - out_str += f":Surnames: {surnames}\n" - out_str += f":Given Names: {given_names}\n" - out_str += f":Gender: {self.sex}\n" - out_str += f":Birth date: {self.birth_date}\n" - out_str += f":Birth Place: {self.birth_place}\n" - out_str += f":Nationality: {self.nationality}\n" - out_str += f":Issue Date: {self.issue_date}\n" - out_str += f":Expiry Date: {self.expiry_date}\n" - out_str += f":Address: {self.address}\n" - out_str += f":Machine Readable Zone Line 1: {self.mrz1}\n" - out_str += f":Machine Readable Zone Line 2: {self.mrz2}\n" - out_str += f":Machine Readable Zone Line 3: {self.mrz3}\n" - return clean_out_string(out_str) diff --git a/tests/product/international_id/test_international_id_v1.py b/tests/product/international_id/test_international_id_v1.py deleted file mode 100644 index 141da283..00000000 --- a/tests/product/international_id/test_international_id_v1.py +++ /dev/null @@ -1,79 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.international_id.international_id_v1 import InternationalIdV1 -from mindee.product.international_id.international_id_v1_document import ( - InternationalIdV1Document, -) -from tests.product import PRODUCT_DATA_DIR - - -@pytest.fixture -def complete_doc() -> ( - Document[InternationalIdV1Document, Page[InternationalIdV1Document]] -): - json_data = json.load( - open( - PRODUCT_DATA_DIR / "international_id" / "response_v1" / "complete.json", - encoding="utf-8", - ) - ) - return Document(InternationalIdV1, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> Document[InternationalIdV1Document, Page[InternationalIdV1Document]]: - json_data = json.load( - open( - PRODUCT_DATA_DIR / "international_id" / "response_v1" / "empty.json", - encoding="utf-8", - ) - ) - return Document(InternationalIdV1, json_data["document"]) - - -@pytest.fixture -def complete_page_0() -> Page[InternationalIdV1Document]: - json_data = json.load( - open( - PRODUCT_DATA_DIR / "international_id" / "response_v1" / "complete.json", - encoding="utf-8", - ) - ) - return Page( - InternationalIdV1Document, json_data["document"]["inference"]["pages"][0] - ) - - -def test_complete_doc( - complete_doc: Document[InternationalIdV1Document, Page[InternationalIdV1Document]] -): - reference_str = open( - PRODUCT_DATA_DIR / "international_id" / "response_v1" / "summary_full.rst", - "r", - encoding="utf-8", - ).read() - assert str(complete_doc) == reference_str - - -def test_empty_doc( - empty_doc: Document[InternationalIdV1Document, Page[InternationalIdV1Document]] -): - prediction = empty_doc.inference.prediction - assert prediction.document_number.value is None - assert prediction.country_of_issue.value is None - assert len(prediction.surnames) == 0 - assert len(prediction.given_names) == 0 - assert prediction.sex.value is None - assert prediction.birth_date.value is None - assert prediction.birth_place.value is None - assert prediction.nationality.value is None - assert prediction.issue_date.value is None - assert prediction.expiry_date.value is None - assert prediction.address.value is None - assert prediction.mrz1.value is None - assert prediction.mrz2.value is None - assert prediction.mrz3.value is None