Skip to content

Commit 2b89be1

Browse files
authored
✨ allow comparing v2 field confidence (#362)
1 parent c0f45a7 commit 2b89be1

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

.github/workflows/_test-integrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
5252
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
5353
run: |
54-
pytest -m integration
54+
pytest --cov mindee -m integration
5555
5656
5757
- name: Notify Slack Action on Failure

.github/workflows/_test-regressions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
env:
4848
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
4949
run: |
50-
pytest -m regression
50+
pytest --cov mindee -m regression
5151
5252
- name: Notify Slack Action on Failure
5353
uses: ravsamhq/[email protected]

.github/workflows/_test-units.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
env:
5151
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
5252
run: |
53-
pytest --cov-fail-under 87
53+
pytest --cov mindee --cov-fail-under 87

mindee/parsing/v2/field/field_confidence.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,29 @@ class FieldConfidence(str, Enum):
88
HIGH = "High"
99
MEDIUM = "Medium"
1010
LOW = "Low"
11+
12+
def __int__(self) -> int:
13+
return {"Certain": 4, "High": 3, "Medium": 2, "Low": 1}[self.value]
14+
15+
def __str__(self) -> str:
16+
return self.value
17+
18+
def __lt__(self, other) -> bool:
19+
if isinstance(other, FieldConfidence):
20+
return int(self) < int(other)
21+
raise TypeError(f"Cannot compare FieldConfidence with {type(other)}")
22+
23+
def __le__(self, other) -> bool:
24+
if isinstance(other, FieldConfidence):
25+
return int(self) <= int(other)
26+
raise TypeError(f"Cannot compare FieldConfidence with {type(other)}")
27+
28+
def __gt__(self, other) -> bool:
29+
if isinstance(other, FieldConfidence):
30+
return int(self) > int(other)
31+
raise TypeError(f"Cannot compare FieldConfidence with {type(other)}")
32+
33+
def __ge__(self, other) -> bool:
34+
if isinstance(other, FieldConfidence):
35+
return int(self) >= int(other)
36+
raise TypeError(f"Cannot compare FieldConfidence with {type(other)}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ safe_licenses = [
120120

121121

122122
[tool.pytest.ini_options]
123-
addopts = "--pyargs --cov mindee --cov-report term:skip-covered --cov-report term-missing -m 'not regression and not integration'"
123+
addopts = "--pyargs --cov-report term:skip-covered --cov-report term-missing -m 'not regression and not integration'"
124124
python_files = "test*.py"
125125
junit_family = "xunit2"
126126
markers = [

tests/v2/test_inference_response.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,12 @@ def test_field_locations_and_confidence() -> None:
268268
assert polygon[3][0] == 0.948849
269269
assert polygon[3][1] == 0.244565
270270

271+
assert str(date_field.confidence) == "Medium"
272+
assert int(date_field.confidence) == 2
271273
assert date_field.confidence == FieldConfidence.MEDIUM
272-
assert str(date_field.confidence.value) == "Medium"
274+
assert date_field.confidence >= FieldConfidence.MEDIUM
275+
assert date_field.confidence <= FieldConfidence.MEDIUM
276+
assert date_field.confidence >= FieldConfidence.LOW
277+
assert date_field.confidence > FieldConfidence.LOW
278+
assert date_field.confidence <= FieldConfidence.HIGH
279+
assert date_field.confidence < FieldConfidence.HIGH

0 commit comments

Comments
 (0)