diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 57cdd4e8..44168c64 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,12 +21,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-docs-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml index ec3ffa6d..640fa666 100644 --- a/.github/workflows/license.yml +++ b/.github/workflows/license.yml @@ -18,12 +18,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-lic-${{ hashFiles('**/setup.cfg') }} diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 55d76447..0c76dcb4 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,12 +17,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} @@ -36,7 +36,7 @@ jobs: pip install -e .[dev] - name: Cache pre-commit - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pre-commit key: ${{ runner.os }}-prec-${{ hashFiles('.pre-commit-config.yaml') }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 98185461..6a1d3cee 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,12 +21,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-build-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/test-code-samples.yml b/.github/workflows/test-code-samples.yml index 1aff76d1..2adfae32 100644 --- a/.github/workflows/test-code-samples.yml +++ b/.github/workflows/test-code-samples.yml @@ -25,12 +25,12 @@ jobs: submodules: recursive - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-samples-${{ hashFiles('**/setup.cfg') }} diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 27574e29..1f62e04d 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -7,8 +7,6 @@ on: pull_request: workflow_run: workflows: ["Test Code Samples"] - branches: - - '*' types: - completed @@ -32,12 +30,12 @@ jobs: submodules: recursive - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/test-regression.yml b/.github/workflows/test-regression.yml index e56a834b..bba7fbea 100644 --- a/.github/workflows/test-regression.yml +++ b/.github/workflows/test-regression.yml @@ -7,8 +7,6 @@ on: pull_request: workflow_run: workflows: ["Test Code Samples"] - branches: - - '*' types: - completed @@ -32,12 +30,12 @@ jobs: submodules: recursive - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 77fc6fc9..4042a754 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -29,12 +29,12 @@ jobs: submodules: recursive - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} diff --git a/docs/extras/guide/generated_v1.md b/docs/extras/guide/generated_v1.md index 31a3f15e..47d53095 100644 --- a/docs/extras/guide/generated_v1.md +++ b/docs/extras/guide/generated_v1.md @@ -87,12 +87,20 @@ Generated builds always have access to at least two attributes: ## Fields -**fields** (`Dict[str`: `List[Union[`[GeneratedListField](#generated-list-field)[GeneratedObjectField](#generated-object-field), `(#stringfield)[StringField]]]`): +**fields** (`Dict[str`: `List[Union[`[GeneratedListField](#generated-list-field), [GeneratedObjectField](#generated-object-field), `(#stringfield)[StringField]]]`): ```python print(str(result.document.inference.prediction.fields["my-field"])) ``` +### Nested fields + +If your field `my-field` is a `GeneratedObjectField`, you can access its individual properties using the following syntax: + +```python +print(str(result.document.inference.prediction.fields["my-field"].my_attribute)) +``` + # Questions? [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/examples/auto_invoice_splitter_extraction.py b/examples/auto_invoice_splitter_extraction.py index 56f7212e..4a456a3a 100644 --- a/examples/auto_invoice_splitter_extraction.py +++ b/examples/auto_invoice_splitter_extraction.py @@ -1,7 +1,7 @@ import os from mindee import Client -from mindee.extraction.common.pdf_extractor import PdfExtractor +from mindee.extraction.pdf_extractor import PdfExtractor from mindee.input import PathInput from mindee.product import InvoiceSplitterV1, InvoiceV4 diff --git a/mindee/product/generated/generated_v1_document.py b/mindee/product/generated/generated_v1_document.py index 72785d65..1378fc63 100644 --- a/mindee/product/generated/generated_v1_document.py +++ b/mindee/product/generated/generated_v1_document.py @@ -35,5 +35,5 @@ def __init__(self, raw_prediction: StringDict) -> None: ): field_contents_str["value"] = str( field_contents_str["value"] - ) # str cohersion for numbers + ) # str coercion for numbers self.fields[field_name] = StringField(field_contents_str) diff --git a/tests/api/__init__.py b/tests/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data b/tests/data index f737d62b..43984fb9 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit f737d62bb2fb6b064e324f31f25c75767793aa1a +Subproject commit 43984fb924bb22e1182a5eb218fafddf4ce0ec4d diff --git a/tests/extraction/test_invoice_splitter_auto_extraction.py b/tests/extraction/test_invoice_splitter_auto_extraction.py index 66ced3de..5d160476 100644 --- a/tests/extraction/test_invoice_splitter_auto_extraction.py +++ b/tests/extraction/test_invoice_splitter_auto_extraction.py @@ -9,6 +9,7 @@ from mindee.product import InvoiceSplitterV1, InvoiceV4 from tests.product import get_id, get_version from tests.test_inputs import PRODUCT_DATA_DIR +from tests.utils import levenshtein_ratio @pytest.fixture @@ -52,4 +53,4 @@ def test_pdf_should_extract_invoices_strict(): PRODUCT_DATA_DIR / "invoices" / "response_v4" / "summary_full_invoice_p1.rst", invoice_0.document, ) - assert test_string_rst_invoice_0 == str(invoice_0.document) + assert levenshtein_ratio(test_string_rst_invoice_0, str(invoice_0.document)) >= 0.97 diff --git a/tests/input/__init__.py b/tests/input/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/Input/test_local_response.py b/tests/input/test_local_response.py similarity index 100% rename from tests/Input/test_local_response.py rename to tests/input/test_local_response.py diff --git a/tests/mindee_http/__init__.py b/tests/mindee_http/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils.py b/tests/utils.py index 263ee0d4..3245adfa 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,4 @@ +from difflib import SequenceMatcher from pathlib import Path from mindee.mindee_http.mindee_api import ( @@ -25,3 +26,13 @@ def dummy_envvars(monkeypatch) -> None: EXTRAS_DIR = Path("./tests/data/extras/") + + +def levenshtein_ratio(ref_str: str, target_str: str) -> float: + """ + Calculates the Levenshtein ratio between two strings. + :param ref_str: Reference string. + :param target_str: Target String. + :return: Ratio between the two strings + """ + return SequenceMatcher(None, ref_str, target_str).ratio()