|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from mindee.parsing.common.string_dict import StringDict |
| 4 | +from mindee.parsing.standard.text import StringField |
| 5 | + |
| 6 | + |
| 7 | +class AddressField(StringField): |
| 8 | + """A field containing an address value.""" |
| 9 | + |
| 10 | + street_number: Optional[str] |
| 11 | + """Street number.""" |
| 12 | + street_name: Optional[str] |
| 13 | + """Street name.""" |
| 14 | + po_box: Optional[str] |
| 15 | + """PO Box number.""" |
| 16 | + address_complement: Optional[str] |
| 17 | + """Address complement.""" |
| 18 | + city: Optional[str] |
| 19 | + """City name.""" |
| 20 | + postal_code: Optional[str] |
| 21 | + """Postal code.""" |
| 22 | + state: Optional[str] |
| 23 | + """State name.""" |
| 24 | + country: Optional[str] |
| 25 | + """Country name.""" |
| 26 | + |
| 27 | + def __init__( |
| 28 | + self, |
| 29 | + raw_prediction: StringDict, |
| 30 | + reconstructed: bool = False, |
| 31 | + page_id: Optional[int] = None, |
| 32 | + ): |
| 33 | + """ |
| 34 | + Text field object. |
| 35 | +
|
| 36 | + :param raw_prediction: Amount prediction object from HTTP response. |
| 37 | + :param reconstructed: Bool for reconstructed object (not extracted in the API). |
| 38 | + :param page_id: Page number for multi-page document. |
| 39 | + """ |
| 40 | + self.value = None |
| 41 | + super().__init__( |
| 42 | + raw_prediction, |
| 43 | + value_key="value", |
| 44 | + reconstructed=reconstructed, |
| 45 | + page_id=page_id, |
| 46 | + ) |
| 47 | + if raw_prediction.get("street_number"): |
| 48 | + self.street_number = raw_prediction["street_number"] |
| 49 | + if raw_prediction.get("street_name"): |
| 50 | + self.street_name = raw_prediction["street_name"] |
| 51 | + if raw_prediction.get("po_box"): |
| 52 | + self.po_box = raw_prediction["po_box"] |
| 53 | + if raw_prediction.get("address_complement"): |
| 54 | + self.address_complement = raw_prediction["address_complement"] |
| 55 | + if raw_prediction.get("city"): |
| 56 | + self.city = raw_prediction["city"] |
| 57 | + if raw_prediction.get("postal_code"): |
| 58 | + self.postal_code = raw_prediction["postal_code"] |
| 59 | + if raw_prediction.get("state"): |
| 60 | + self.city = raw_prediction["state"] |
| 61 | + if raw_prediction.get("country"): |
| 62 | + self.city = raw_prediction["country"] |
0 commit comments