File tree Expand file tree Collapse file tree 8 files changed +32
-22
lines changed Expand file tree Collapse file tree 8 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class ListFieldValueV1(FieldPositionMixin):
9
9
10
10
content : str
11
11
"""The content text"""
12
- confidence : float = 0.0
12
+ confidence : float
13
13
"""Confidence score"""
14
14
15
15
def __init__ (self , raw_prediction : StringDict ) -> None :
@@ -24,7 +24,7 @@ def __str__(self) -> str:
24
24
class ListFieldV1 :
25
25
"""A list of values or words."""
26
26
27
- confidence : float = 0.0
27
+ confidence : float
28
28
"""Confidence score"""
29
29
reconstructed : bool
30
30
"""Whether the field was reconstructed from other fields."""
Original file line number Diff line number Diff line change 7
7
class AmountField (FieldPositionMixin , BaseField ):
8
8
"""A field containing an amount value."""
9
9
10
- value : Optional [float ] = None
10
+ value : Optional [float ]
11
11
"""The amount value as a float."""
12
12
13
13
def __init__ (
@@ -23,6 +23,7 @@ def __init__(
23
23
:param reconstructed: Bool for reconstructed object (not extracted in the API)
24
24
:param page_id: Page number for multi-page document
25
25
"""
26
+ self .value = None
26
27
super ().__init__ (
27
28
raw_prediction ,
28
29
value_key = "value" ,
Original file line number Diff line number Diff line change @@ -25,29 +25,31 @@ def _set_position(self, raw_prediction: StringDict):
25
25
pass
26
26
if self .polygon :
27
27
self .bounding_box = get_bounding_box (self .polygon )
28
+ else :
29
+ self .bounding_box = None
28
30
29
31
30
32
class FieldConfidenceMixin :
31
33
"""Mixin class to add a confidence score."""
32
34
33
- confidence : float = 0.0
35
+ confidence : float
34
36
"""The confidence score."""
35
37
36
38
def _set_confidence (self , raw_prediction : StringDict ):
37
39
try :
38
40
self .confidence = float (raw_prediction ["confidence" ])
39
41
except (KeyError , TypeError ):
40
- pass
42
+ self . confidence = 0.0
41
43
42
44
43
45
class BaseField (FieldConfidenceMixin ):
44
46
"""Base class for most fields."""
45
47
46
- value : Optional [Any ] = None
48
+ value : Optional [Any ]
47
49
"""Raw field value"""
48
50
reconstructed : bool
49
51
"""Whether the field was reconstructed from other fields."""
50
- page_id : Optional [int ] = None
52
+ page_id : Optional [int ]
51
53
"""The document page on which the information was found."""
52
54
53
55
def __init__ (
@@ -57,6 +59,8 @@ def __init__(
57
59
reconstructed : bool = False ,
58
60
page_id : Optional [int ] = None ,
59
61
):
62
+ self .value = None
63
+ self .confidence = 0.0
60
64
"""
61
65
Base field object.
62
66
Original file line number Diff line number Diff line change 13
13
class DateField (FieldPositionMixin , BaseField ):
14
14
"""A field containing a date value."""
15
15
16
- date_object : Optional [date ] = None
16
+ date_object : Optional [date ]
17
17
"""Date as a standard Python ``datetime.date`` object."""
18
- value : Optional [str ] = None
18
+ value : Optional [str ]
19
19
"""The raw field value."""
20
20
21
21
def __init__ (
@@ -49,3 +49,7 @@ def __init__(
49
49
except (TypeError , ValueError ):
50
50
self .date_object = None
51
51
self .confidence = 0.0
52
+ else :
53
+ self .date_object = None
54
+ self .confidence = 0.0
55
+ self .value = None
Original file line number Diff line number Diff line change 7
7
class LocaleField (BaseField ):
8
8
"""The locale detected on the document."""
9
9
10
- language : Optional [str ] = None
10
+ language : Optional [str ]
11
11
"""The ISO 639-1 code of the language."""
12
- country : Optional [str ] = None
12
+ country : Optional [str ]
13
13
"""The ISO 3166-1 alpha-2 code of the country."""
14
- currency : Optional [str ] = None
14
+ currency : Optional [str ]
15
15
"""The ISO 4217 code of the currency."""
16
16
17
17
def __init__ (
Original file line number Diff line number Diff line change 7
7
class PaymentDetailsField (FieldPositionMixin , BaseField ):
8
8
"""Information on a single payment."""
9
9
10
- account_number : Optional [str ] = None
10
+ account_number : Optional [str ]
11
11
"""Account number"""
12
- iban : Optional [str ] = None
12
+ iban : Optional [str ]
13
13
"""Account IBAN"""
14
- routing_number : Optional [str ] = None
14
+ routing_number : Optional [str ]
15
15
"""Account routing number"""
16
- swift : Optional [str ] = None
16
+ swift : Optional [str ]
17
17
"""Bank's SWIFT code"""
18
18
19
19
def __init__ (
Original file line number Diff line number Diff line change 10
10
class PositionField (BaseField ):
11
11
"""A field indicating a position or area on the document."""
12
12
13
- value : Optional [Polygon ] = None
13
+ value : Optional [Polygon ]
14
14
"""Polygon of cropped area, identical to the ``polygon`` property."""
15
- polygon : Optional [Polygon ] = None
15
+ polygon : Optional [Polygon ]
16
16
"""Polygon of cropped area"""
17
- quadrangle : Optional [Quadrilateral ] = None
17
+ quadrangle : Optional [Quadrilateral ]
18
18
"""Quadrangle of cropped area (does not exceed the canvas)"""
19
- rectangle : Optional [Quadrilateral ] = None
19
+ rectangle : Optional [Quadrilateral ]
20
20
"""Oriented rectangle of cropped area (may exceed the canvas)"""
21
- bounding_box : Optional [Quadrilateral ] = None
21
+ bounding_box : Optional [Quadrilateral ]
22
22
"""Straight rectangle of cropped area (does not exceed the canvas)"""
23
23
24
24
def __init__ (
Original file line number Diff line number Diff line change 7
7
class StringField (FieldPositionMixin , BaseField ):
8
8
"""A field containing a text value."""
9
9
10
- value : Optional [str ] = None
10
+ value : Optional [str ]
11
11
12
12
def __init__ (
13
13
self ,
@@ -24,6 +24,7 @@ def __init__(
24
24
:param reconstructed: Bool for reconstructed object (not extracted in the API)
25
25
:param page_id: Page number for multi-page document
26
26
"""
27
+ self .value = None
27
28
super ().__init__ (
28
29
raw_prediction ,
29
30
value_key = value_key ,
You can’t perform that action at this time.
0 commit comments