From 7ddb74a9da60005b99f97797440abb0d56936cb9 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Fri, 6 Oct 2023 18:54:12 +0200 Subject: [PATCH] first working export: fr.CarteVitaleV1 --- docs/extras/code_samples/carte_vitale_v1.txt | 18 ++++++ mindee/product/fr/__init__.py | 1 + mindee/product/fr/carte_vitale/__init__.py | 0 .../fr/carte_vitale/carte_vitale_v1.py | 32 +++++++++++ .../carte_vitale/carte_vitale_v1_document.py | 57 +++++++++++++++++++ tests/product/eu/__init__.py | 0 6 files changed, 108 insertions(+) create mode 100644 docs/extras/code_samples/carte_vitale_v1.txt create mode 100644 mindee/product/fr/carte_vitale/__init__.py create mode 100644 mindee/product/fr/carte_vitale/carte_vitale_v1.py create mode 100644 mindee/product/fr/carte_vitale/carte_vitale_v1_document.py create mode 100644 tests/product/eu/__init__.py diff --git a/docs/extras/code_samples/carte_vitale_v1.txt b/docs/extras/code_samples/carte_vitale_v1.txt new file mode 100644 index 00000000..57b47857 --- /dev/null +++ b/docs/extras/code_samples/carte_vitale_v1.txt @@ -0,0 +1,18 @@ +from mindee import Client, PredictResponse, product + +# 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 parse it. +# The endpoint name must be specified since it cannot be determined from the class. +result: PredictResponse = mindee_client.parse(product.fr.CarteVitaleV1, input_doc) + +# Print a brief summary of the parsed data +print(result.document) + +# # Iterate over all the fields in the document +# for field_name, field_values in result.document.inference.prediction.fields.items(): +# print(field_name, "=", field_values) diff --git a/mindee/product/fr/__init__.py b/mindee/product/fr/__init__.py index e69de29b..142e0612 100644 --- a/mindee/product/fr/__init__.py +++ b/mindee/product/fr/__init__.py @@ -0,0 +1 @@ +from mindee.product.fr.carte_vitale.carte_vitale_v1 import CarteVitaleV1 diff --git a/mindee/product/fr/carte_vitale/__init__.py b/mindee/product/fr/carte_vitale/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mindee/product/fr/carte_vitale/carte_vitale_v1.py b/mindee/product/fr/carte_vitale/carte_vitale_v1.py new file mode 100644 index 00000000..141f7022 --- /dev/null +++ b/mindee/product/fr/carte_vitale/carte_vitale_v1.py @@ -0,0 +1,32 @@ +from typing import List + +from mindee.parsing.common import Inference, Page, StringDict +from mindee.product.fr.carte_vitale.carte_vitale_v1_document import ( + CarteVitaleV1Document, +) + + +class CarteVitaleV1(Inference): + """Inference prediction for Carte Vitale, API version 1.""" + + prediction: CarteVitaleV1Document + """Document-level prediction.""" + pages: List[Page[CarteVitaleV1Document]] + """Page-level prediction(s).""" + endpoint_name = "carte_vitale" + """Name of the endpoint.""" + endpoint_version = "1" + """Version of the endpoint.""" + + def __init__(self, raw_prediction: StringDict): + """ + Carte Vitale v1 inference. + + :param raw_prediction: Raw prediction from the HTTP response. + """ + super().__init__(raw_prediction) + + self.prediction = CarteVitaleV1Document(raw_prediction["prediction"]) + self.pages = [] + for page in raw_prediction["pages"]: + self.pages.append(Page(CarteVitaleV1Document, page)) diff --git a/mindee/product/fr/carte_vitale/carte_vitale_v1_document.py b/mindee/product/fr/carte_vitale/carte_vitale_v1_document.py new file mode 100644 index 00000000..e1b0e48c --- /dev/null +++ b/mindee/product/fr/carte_vitale/carte_vitale_v1_document.py @@ -0,0 +1,57 @@ +from typing import List, Optional + +from mindee.parsing.common import Prediction, StringDict, clean_out_string +from mindee.parsing.standard import DateField, StringField + + +class CarteVitaleV1Document(Prediction): + """Document data for Carte Vitale, API version 1.""" + + given_names: List[StringField] + """The given name(s) of the card holder.""" + issuance_date: DateField + """The date the card was issued.""" + social_security: StringField + """The Social Security Number (Numéro de Sécurité Sociale) of the card holder""" + surname: StringField + """The surname of the card holder.""" + + def __init__( + self, + raw_prediction: StringDict, + page_id: Optional[int] = None, + ): + """ + Carte Vitale document. + + :param raw_prediction: Raw prediction from HTTP response + """ + + self.given_names = [ + StringField(prediction, page_id=page_id) + for prediction in raw_prediction["given_names"] + ] + self.issuance_date = DateField( + raw_prediction["issuance_date"], + page_id=page_id, + ) + self.social_security = StringField( + raw_prediction["social_security"], + page_id=page_id, + ) + self.surname = StringField( + raw_prediction["surname"], + page_id=page_id, + ) + + def __str__(self) -> str: + given_names = f"\n { ' ' * 15 }".join( + [str(item) for item in self.given_names], + ) + + return clean_out_string( + f":Given Name(s): {given_names}\n" + f":Surname: {self.surname}\n" + f":Social Security Number: {self.social_security}\n" + f":Issuance Date: {self.issuance_date}\n" + ) diff --git a/tests/product/eu/__init__.py b/tests/product/eu/__init__.py new file mode 100644 index 00000000..e69de29b