-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbase_field.py
More file actions
33 lines (25 loc) · 1.14 KB
/
base_field.py
File metadata and controls
33 lines (25 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import List, Optional
from mindee.parsing.common.string_dict import StringDict
from mindee.parsing.v2.field.dynamic_field import DynamicField, FieldType
from mindee.parsing.v2.field.field_confidence import FieldConfidence
from mindee.parsing.v2.field.field_location import FieldLocation
class BaseField(DynamicField):
"""Field with base information."""
locations: List[FieldLocation]
confidence: Optional[FieldConfidence]
def __init__(
self, field_type: FieldType, raw_response: StringDict, indent_level: int = 0
) -> None:
super().__init__(field_type, indent_level)
self._indent_level = indent_level
self.confidence = None
self.locations = []
if "confidence" in raw_response and raw_response["confidence"] is not None:
try:
self.confidence = FieldConfidence(raw_response["confidence"])
except ValueError:
self.confidence = None
if "locations" in raw_response:
self.locations = []
for location in raw_response["locations"]:
self.locations.append(FieldLocation(location))