diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5aabc9fe..361f6b40 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,18 +3,6 @@ -## Related Issue - - - - - -## How Has This Been Tested - - - - - ## Types of changes diff --git a/.github/workflows/_publish-guide.yml b/.github/workflows/_publish-guide.yml index 1e7814e3..27f801a2 100644 --- a/.github/workflows/_publish-guide.yml +++ b/.github/workflows/_publish-guide.yml @@ -1,4 +1,4 @@ -name: Publish Guide to readme.com +name: Publish Guide on: workflow_call: @@ -6,13 +6,5 @@ on: jobs: sync: - runs-on: ubuntu-latest - steps: - - name: Checkout this repo - uses: actions/checkout@v4 - - # Run GitHub Action to sync docs in `documentation` directory - - name: GitHub Action - uses: readmeio/rdme@v8 - with: - rdme: docs ./docs/extras/guide --key=${{ secrets.README_API_KEY }} --version=1.0 + uses: mindee/client-lib-actions/.github/workflows/publish-guide.yml@main + secrets: inherit diff --git a/docs/extras/code_samples/us_mail_v2_async.txt b/docs/extras/code_samples/us_mail_v2_async.txt deleted file mode 100644 index 1735ab37..00000000 --- a/docs/extras/code_samples/us_mail_v2_async.txt +++ /dev/null @@ -1,21 +0,0 @@ -# -# Install the Python client library by running: -# pip install mindee -# - -from mindee import Client, product, AsyncPredictResponse - -# 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.us.UsMailV2, - input_doc, -) - -# Print a brief summary of the parsed data -print(result.document) diff --git a/docs/product/us/us_mail_v2.rst b/docs/product/us/us_mail_v2.rst deleted file mode 100644 index f2335753..00000000 --- a/docs/product/us/us_mail_v2.rst +++ /dev/null @@ -1,23 +0,0 @@ -US Mail V2 ----------- - -**Sample Code:** - -.. literalinclude:: /extras/code_samples/us_mail_v2_async.txt - :language: Python - -.. autoclass:: mindee.product.us.us_mail.us_mail_v2.UsMailV2 - :members: - :inherited-members: - -.. autoclass:: mindee.product.us.us_mail.us_mail_v2_document.UsMailV2Document - :members: - :inherited-members: - -.. autoclass:: mindee.product.us.us_mail.us_mail_v2_sender_address.UsMailV2SenderAddress - :members: - :inherited-members: - -.. autoclass:: mindee.product.us.us_mail.us_mail_v2_recipient_address.UsMailV2RecipientAddress - :members: - :inherited-members: diff --git a/mindee/product/us/__init__.py b/mindee/product/us/__init__.py index d1c0da1a..781e922b 100644 --- a/mindee/product/us/__init__.py +++ b/mindee/product/us/__init__.py @@ -12,16 +12,6 @@ from mindee.product.us.healthcare_card.healthcare_card_v1_document import ( HealthcareCardV1Document, ) -from mindee.product.us.us_mail.us_mail_v2 import UsMailV2 -from mindee.product.us.us_mail.us_mail_v2_document import ( - UsMailV2Document, -) -from mindee.product.us.us_mail.us_mail_v2_recipient_address import ( - UsMailV2RecipientAddress, -) -from mindee.product.us.us_mail.us_mail_v2_sender_address import ( - UsMailV2SenderAddress, -) from mindee.product.us.us_mail.us_mail_v3 import UsMailV3 from mindee.product.us.us_mail.us_mail_v3_document import ( UsMailV3Document, diff --git a/mindee/product/us/us_mail/__init__.py b/mindee/product/us/us_mail/__init__.py index f8b761fd..b5be043b 100644 --- a/mindee/product/us/us_mail/__init__.py +++ b/mindee/product/us/us_mail/__init__.py @@ -1,13 +1,3 @@ -from mindee.product.us.us_mail.us_mail_v2 import UsMailV2 -from mindee.product.us.us_mail.us_mail_v2_document import ( - UsMailV2Document, -) -from mindee.product.us.us_mail.us_mail_v2_recipient_address import ( - UsMailV2RecipientAddress, -) -from mindee.product.us.us_mail.us_mail_v2_sender_address import ( - UsMailV2SenderAddress, -) from mindee.product.us.us_mail.us_mail_v3 import UsMailV3 from mindee.product.us.us_mail.us_mail_v3_document import ( UsMailV3Document, diff --git a/mindee/product/us/us_mail/us_mail_v2.py b/mindee/product/us/us_mail/us_mail_v2.py deleted file mode 100644 index ae1a8cca..00000000 --- a/mindee/product/us/us_mail/us_mail_v2.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.us.us_mail.us_mail_v2_document import ( - UsMailV2Document, -) - - -class UsMailV2(Inference): - """US Mail API version 2 inference prediction.""" - - prediction: UsMailV2Document - """Document-level prediction.""" - pages: List[Page[UsMailV2Document]] - """Page-level prediction(s).""" - endpoint_name = "us_mail" - """Name of the endpoint.""" - endpoint_version = "2" - """Version of the endpoint.""" - - def __init__(self, raw_prediction: StringDict): - """ - US Mail v2 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction) - - self.prediction = UsMailV2Document(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(UsMailV2Document, page)) diff --git a/mindee/product/us/us_mail/us_mail_v2_document.py b/mindee/product/us/us_mail/us_mail_v2_document.py deleted file mode 100644 index f551daa1..00000000 --- a/mindee/product/us/us_mail/us_mail_v2_document.py +++ /dev/null @@ -1,95 +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.text import StringField -from mindee.product.us.us_mail.us_mail_v2_recipient_address import ( - UsMailV2RecipientAddress, -) -from mindee.product.us.us_mail.us_mail_v2_sender_address import UsMailV2SenderAddress - - -class UsMailV2Document(Prediction): - """US Mail API version 2.0 document data.""" - - recipient_addresses: List[UsMailV2RecipientAddress] - """The addresses of the recipients.""" - recipient_names: List[StringField] - """The names of the recipients.""" - sender_address: UsMailV2SenderAddress - """The address of the sender.""" - sender_name: StringField - """The name of the sender.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - US Mail 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.recipient_addresses = [ - UsMailV2RecipientAddress(prediction, page_id=page_id) - for prediction in raw_prediction["recipient_addresses"] - ] - self.recipient_names = [ - StringField(prediction, page_id=page_id) - for prediction in raw_prediction["recipient_names"] - ] - self.sender_address = UsMailV2SenderAddress( - raw_prediction["sender_address"], - page_id=page_id, - ) - self.sender_name = StringField( - raw_prediction["sender_name"], - page_id=page_id, - ) - - @staticmethod - def _recipient_addresses_separator(char: str) -> str: - out_str = " " - out_str += f"+{char * 17}" - out_str += f"+{char * 37}" - out_str += f"+{char * 19}" - out_str += f"+{char * 13}" - out_str += f"+{char * 24}" - out_str += f"+{char * 7}" - out_str += f"+{char * 27}" - return out_str + "+" - - def _recipient_addresses_to_str(self) -> str: - if not self.recipient_addresses: - return "" - - lines = f"\n{self._recipient_addresses_separator('-')}\n ".join( - [item.to_table_line() for item in self.recipient_addresses] - ) - out_str = "" - out_str += f"\n{self._recipient_addresses_separator('-')}\n " - out_str += " | City " - out_str += " | Complete Address " - out_str += " | Is Address Change" - out_str += " | Postal Code" - out_str += " | Private Mailbox Number" - out_str += " | State" - out_str += " | Street " - out_str += f" |\n{self._recipient_addresses_separator('=')}" - out_str += f"\n {lines}" - out_str += f"\n{self._recipient_addresses_separator('-')}" - return out_str - - def __str__(self) -> str: - recipient_names = f"\n { ' ' * 17 }".join( - [str(item) for item in self.recipient_names], - ) - out_str: str = f":Sender Name: {self.sender_name}\n" - out_str += f":Sender Address:\n{self.sender_address.to_field_list()}\n" - out_str += f":Recipient Names: {recipient_names}\n" - out_str += f":Recipient Addresses: {self._recipient_addresses_to_str()}\n" - return clean_out_string(out_str) diff --git a/mindee/product/us/us_mail/us_mail_v2_recipient_address.py b/mindee/product/us/us_mail/us_mail_v2_recipient_address.py deleted file mode 100644 index e3f171e0..00000000 --- a/mindee/product/us/us_mail/us_mail_v2_recipient_address.py +++ /dev/null @@ -1,107 +0,0 @@ -from typing import Dict, Optional - -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string, format_for_display -from mindee.parsing.standard.base import ( - FieldConfidenceMixin, - FieldPositionMixin, - bool_to_string, - to_opt_bool, -) - - -class UsMailV2RecipientAddress(FieldPositionMixin, FieldConfidenceMixin): - """The addresses of the recipients.""" - - city: Optional[str] - """The city of the recipient's address.""" - complete: Optional[str] - """The complete address of the recipient.""" - is_address_change: Optional[bool] - """Indicates if the recipient's address is a change of address.""" - postal_code: Optional[str] - """The postal code of the recipient's address.""" - private_mailbox_number: Optional[str] - """The private mailbox number of the recipient's address.""" - state: Optional[str] - """Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.""" - street: Optional[str] - """The street of the recipient's address.""" - page_n: int - """The document page on which the information was found.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - self._set_confidence(raw_prediction) - self._set_position(raw_prediction) - - if page_id is None: - try: - self.page_n = raw_prediction["page_id"] - except KeyError: - pass - else: - self.page_n = page_id - - self.city = raw_prediction["city"] - self.complete = raw_prediction["complete"] - self.is_address_change = to_opt_bool(raw_prediction, "is_address_change") - self.postal_code = raw_prediction["postal_code"] - self.private_mailbox_number = raw_prediction["private_mailbox_number"] - self.state = raw_prediction["state"] - self.street = raw_prediction["street"] - - def _printable_values(self) -> Dict[str, str]: - """Return values for printing.""" - out_dict: Dict[str, str] = {} - out_dict["city"] = format_for_display(self.city) - out_dict["complete"] = format_for_display(self.complete) - out_dict["is_address_change"] = bool_to_string(self.is_address_change) - out_dict["postal_code"] = format_for_display(self.postal_code) - out_dict["private_mailbox_number"] = format_for_display( - self.private_mailbox_number - ) - out_dict["state"] = format_for_display(self.state) - out_dict["street"] = format_for_display(self.street) - return out_dict - - def _table_printable_values(self) -> Dict[str, str]: - """Return values for printing inside an RST table.""" - out_dict: Dict[str, str] = {} - out_dict["city"] = format_for_display(self.city, 15) - out_dict["complete"] = format_for_display(self.complete, 35) - out_dict["is_address_change"] = bool_to_string(self.is_address_change) - out_dict["postal_code"] = format_for_display(self.postal_code, None) - out_dict["private_mailbox_number"] = format_for_display( - self.private_mailbox_number, None - ) - out_dict["state"] = format_for_display(self.state, None) - out_dict["street"] = format_for_display(self.street, 25) - return out_dict - - def to_table_line(self) -> str: - """Output in a format suitable for inclusion in an rST table.""" - printable = self._table_printable_values() - out_str: str = f"| {printable['city']:<15} | " - out_str += f"{printable['complete']:<35} | " - out_str += f"{printable['is_address_change']:<17} | " - out_str += f"{printable['postal_code']:<11} | " - out_str += f"{printable['private_mailbox_number']:<22} | " - out_str += f"{printable['state']:<5} | " - out_str += f"{printable['street']:<25} | " - return clean_out_string(out_str) - - def __str__(self) -> str: - """Default string representation.""" - printable = self._printable_values() - out_str: str = f"City: {printable['city']}, \n" - out_str += f"Complete Address: {printable['complete']}, \n" - out_str += f"Is Address Change: {printable['is_address_change']}, \n" - out_str += f"Postal Code: {printable['postal_code']}, \n" - out_str += f"Private Mailbox Number: {printable['private_mailbox_number']}, \n" - out_str += f"State: {printable['state']}, \n" - out_str += f"Street: {printable['street']}, \n" - return clean_out_string(out_str) diff --git a/mindee/product/us/us_mail/us_mail_v2_sender_address.py b/mindee/product/us/us_mail/us_mail_v2_sender_address.py deleted file mode 100644 index a2324636..00000000 --- a/mindee/product/us/us_mail/us_mail_v2_sender_address.py +++ /dev/null @@ -1,74 +0,0 @@ -from typing import Dict, Optional - -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string, format_for_display -from mindee.parsing.standard.base import FieldConfidenceMixin, FieldPositionMixin - - -class UsMailV2SenderAddress(FieldPositionMixin, FieldConfidenceMixin): - """The address of the sender.""" - - city: Optional[str] - """The city of the sender's address.""" - complete: Optional[str] - """The complete address of the sender.""" - postal_code: Optional[str] - """The postal code of the sender's address.""" - state: Optional[str] - """Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.""" - street: Optional[str] - """The street of the sender's address.""" - page_n: int - """The document page on which the information was found.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - self._set_confidence(raw_prediction) - self._set_position(raw_prediction) - - if page_id is None: - try: - self.page_n = raw_prediction["page_id"] - except KeyError: - pass - else: - self.page_n = page_id - - self.city = raw_prediction["city"] - self.complete = raw_prediction["complete"] - self.postal_code = raw_prediction["postal_code"] - self.state = raw_prediction["state"] - self.street = raw_prediction["street"] - - def _printable_values(self) -> Dict[str, str]: - """Return values for printing.""" - out_dict: Dict[str, str] = {} - out_dict["city"] = format_for_display(self.city) - out_dict["complete"] = format_for_display(self.complete) - out_dict["postal_code"] = format_for_display(self.postal_code) - out_dict["state"] = format_for_display(self.state) - out_dict["street"] = format_for_display(self.street) - return out_dict - - def to_field_list(self) -> str: - """Output the object in a format suitable for inclusion in an rST field list.""" - printable = self._printable_values() - out_str: str = f" :City: {printable['city']}\n" - out_str += f" :Complete Address: {printable['complete']}\n" - out_str += f" :Postal Code: {printable['postal_code']}\n" - out_str += f" :State: {printable['state']}\n" - out_str += f" :Street: {printable['street']}\n" - return out_str.rstrip() - - def __str__(self) -> str: - """Default string representation.""" - printable = self._printable_values() - out_str: str = f"City: {printable['city']}, \n" - out_str += f"Complete Address: {printable['complete']}, \n" - out_str += f"Postal Code: {printable['postal_code']}, \n" - out_str += f"State: {printable['state']}, \n" - out_str += f"Street: {printable['street']}, \n" - return clean_out_string(out_str) diff --git a/tests/product/us/us_mail/test_us_mail_v2.py b/tests/product/us/us_mail/test_us_mail_v2.py deleted file mode 100644 index d5dbe708..00000000 --- a/tests/product/us/us_mail/test_us_mail_v2.py +++ /dev/null @@ -1,53 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.us.us_mail.us_mail_v2 import UsMailV2 -from mindee.product.us.us_mail.us_mail_v2_document import ( - UsMailV2Document, -) -from tests.product import PRODUCT_DATA_DIR - -RESPONSE_DIR = PRODUCT_DATA_DIR / "us_mail" / "response_v2" - -UsMailV2DocumentType = Document[ - UsMailV2Document, - Page[UsMailV2Document], -] - - -@pytest.fixture -def complete_doc() -> UsMailV2DocumentType: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(UsMailV2, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> UsMailV2DocumentType: - file_path = RESPONSE_DIR / "empty.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(UsMailV2, json_data["document"]) - - -def test_complete_doc(complete_doc: UsMailV2DocumentType): - file_path = RESPONSE_DIR / "summary_full.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert str(complete_doc) == reference_str - - -def test_empty_doc(empty_doc: UsMailV2DocumentType): - prediction = empty_doc.inference.prediction - assert prediction.sender_name.value is None - assert prediction.sender_address.city is None - assert prediction.sender_address.complete is None - assert prediction.sender_address.postal_code is None - assert prediction.sender_address.state is None - assert prediction.sender_address.street is None - assert len(prediction.recipient_names) == 0 - assert len(prediction.recipient_addresses) == 0