-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first working export: fr.CarteVitaleV1
- Loading branch information
1 parent
c981cda
commit 7ddb74a
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from mindee.product.fr.carte_vitale.carte_vitale_v1 import CarteVitaleV1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
57 changes: 57 additions & 0 deletions
57
mindee/product/fr/carte_vitale/carte_vitale_v1_document.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) |
Empty file.