Пример #1
0
 def build_from_api_prediction(self, api_prediction, page_n=0):
     """
     :param api_prediction: Raw prediction from HTTP response
     :param page_n: Page number for multi pages pdf input
     :return: (void) set the object attributes with api prediction values
     """
     self.country = Field(api_prediction["country"], page_n=page_n)
     self.id_number = Field(api_prediction["id_number"], page_n=page_n)
     self.birth_date = Date(api_prediction["birth_date"],
                            "value",
                            page_n=page_n)
     self.expiry_date = Date(api_prediction["expiry_date"],
                             "value",
                             page_n=page_n)
     self.issuance_date = Date(api_prediction["issuance_date"],
                               "value",
                               page_n=page_n)
     self.birth_place = Field(api_prediction["birth_place"], page_n=page_n)
     self.gender = Field(api_prediction["gender"], page_n=page_n)
     self.surname = Field(api_prediction["surname"], page_n=page_n)
     self.mrz1 = Field(api_prediction["mrz1"], page_n=page_n)
     self.mrz2 = Field(api_prediction["mrz2"], page_n=page_n)
     self.given_names = [
         Field(given_name, page_n=page_n)
         for given_name in api_prediction["given_names"]
     ]
     self.mrz = Field({"value": None, "probability": 0.}, page_n=page_n)
     self.full_name = Field({
         "value": None,
         "probability": 0.
     },
                            page_n=page_n)
Пример #2
0
 def build_from_api_prediction(self, api_prediction, page_n=0):
     """
     :param api_prediction: Raw prediction from HTTP response
     :param page_n: Page number for multi pages pdf input
     :return: (void) set the object attributes with api prediction values
     """
     self.company_number = [
         Field(company_reg, extra_fields={"type"}, page_n=page_n)
         for company_reg in api_prediction["company_registration"]
     ]
     self.invoice_date = Date(api_prediction["date"],
                              value_key="value",
                              page_n=page_n)
     self.due_date = Date(api_prediction["due_date"],
                          value_key="value",
                          page_n=page_n)
     self.invoice_number = Field(api_prediction["invoice_number"],
                                 page_n=page_n)
     self.locale = Locale(api_prediction["locale"],
                          value_key="language",
                          page_n=page_n)
     self.orientation = Orientation(api_prediction["orientation"],
                                    page_n=page_n)
     self.supplier = Field(api_prediction["supplier"], page_n=page_n)
     self.taxes = [
         Tax(tax_prediction, page_n=page_n, value_key="value")
         for tax_prediction in api_prediction["taxes"]
     ]
     self.payment_details = [
         PaymentDetails(payment_detail, page_n=page_n)
         for payment_detail in api_prediction["payment_details"]
     ]
     self.total_incl = Amount(api_prediction["total_incl"],
                              value_key="value",
                              page_n=page_n)
     self.total_excl = Amount(api_prediction["total_excl"],
                              value_key="value",
                              page_n=page_n)
     self.total_tax = Amount({
         "value": None,
         "probability": 0.
     },
                             value_key="value",
                             page_n=page_n)
Пример #3
0
def test_constructor():
    field_dict = {
        'iso': "2018-04-01",
        'probability': 0.1,
        'segmentation': {
            "bounding_box": [[0.016, 0.707], [0.414, 0.707], [0.414, 0.831],
                             [0.016, 0.831]]
        }
    }
    date = Date(field_dict)
    assert date.value == "2018-04-01"
Пример #4
0
 def build_from_api_prediction(self, api_prediction, page_n=0):
     """
     :param api_prediction: Raw prediction from HTTP response
     :param page_n: Page number for multi pages pdf input
     :return: (void) set the object attributes with api prediction values
     """
     self.locale = Locale(api_prediction["locale"], page_n=page_n)
     self.total_incl = Amount(api_prediction["total_incl"], value_key="value", page_n=page_n)
     self.date = Date(api_prediction["date"], value_key="value", page_n=page_n)
     self.category = Field(api_prediction["category"], page_n=page_n)
     self.merchant_name = Field(api_prediction["supplier"], value_key="value", page_n=page_n)
     self.time = Field(api_prediction["time"], value_key="value", page_n=page_n)
     self.taxes = [
         Tax(tax_prediction, page_n=page_n, value_key="value", rate_key="rate", code_key="code")
         for tax_prediction in api_prediction["taxes"]]
     self.orientation = Orientation(api_prediction["orientation"], page_n=page_n)
     self.total_tax = Amount({"value": None, "probability": 0.}, value_key="value", page_n=page_n)
     self.total_excl = Amount({"value": None, "probability": 0.}, value_key="value", page_n=page_n)
Пример #5
0
    def __init__(self,
                 api_prediction=None,
                 input_file=None,
                 locale=None,
                 total_incl=None,
                 total_excl=None,
                 invoice_date=None,
                 invoice_number=None,
                 due_date=None,
                 taxes=None,
                 supplier=None,
                 payment_details=None,
                 company_number=None,
                 vat_number=None,
                 orientation=None,
                 total_tax=None,
                 page_n=0):
        """
        :param api_prediction: Raw prediction from HTTP response
        :param input_file: Input object
        :param locale: locale value for creating Invoice object from scratch
        :param total_incl: total_incl value for creating Invoice object from scratch
        :param total_excl: total_excl value for creating Invoice object from scratch
        :param invoice_date: invoice_date value for creating Invoice object from scratch
        :param invoice_number: invoice_number value for creating Invoice object from scratch
        :param due_date: due_date value for creating Invoice object from scratch
        :param taxes: taxes value for creating Invoice object from scratch
        :param supplier: supplier value for creating Invoice object from scratch
        :param payment_details: payment_details value for creating Invoice object from scratch
        :param company_number: company_number value for creating Invoice object from scratch
        :param vat_number: vat_number value for creating Invoice object from scratch
        :param orientation: orientation value for creating Invoice object from scratch
        :param total_tax: total_tax value for creating Invoice object from scratch
        :param page_n: Page number for multi pages pdf input
        """
        self.type = "Invoice"
        self.locale = None
        self.total_incl = None
        self.total_excl = None
        self.invoice_date = None
        self.invoice_number = None
        self.due_date = None
        self.taxes = []
        self.supplier = None
        self.payment_details = None
        self.company_number = None
        self.orientation = None
        self.total_tax = None

        if api_prediction is not None:
            self.build_from_api_prediction(api_prediction, page_n=page_n)
        else:
            self.locale = Locale({"value": locale},
                                 value_key="value",
                                 page_n=page_n)
            self.total_incl = Amount({"value": total_incl},
                                     value_key="value",
                                     page_n=page_n)
            self.date = Date({"value": invoice_date},
                             value_key="value",
                             page_n=page_n)
            self.invoice_date = Date({"value": invoice_date},
                                     value_key="value",
                                     page_n=page_n)
            self.due_date = Date({"value": due_date},
                                 value_key="value",
                                 page_n=page_n)
            self.supplier = Field({"value": supplier},
                                  value_key="value",
                                  page_n=page_n)
            if taxes is not None:
                self.taxes = [
                    Tax({
                        "value": t[0],
                        "rate": t[1]
                    },
                        page_n=page_n,
                        value_key="value",
                        rate_key="rate") for t in taxes
                ]
            self.orientation = Orientation({"value": orientation},
                                           value_key="value",
                                           page_n=page_n)
            self.total_tax = Amount({"value": total_tax},
                                    value_key="value",
                                    page_n=page_n)
            self.total_excl = Amount({"value": total_excl},
                                     value_key="value",
                                     page_n=page_n)
            self.invoice_number = Field({"value": invoice_number},
                                        value_key="value",
                                        page_n=page_n)
            self.payment_details = Field({"value": payment_details},
                                         value_key="value",
                                         page_n=page_n)
            self.company_number = Field({"value": company_number},
                                        value_key="value",
                                        page_n=page_n)

        # Invoke Document constructor
        super(Invoice, self).__init__(input_file)

        # Run checks
        self._checklist()

        # Reconstruct extra fields
        self._reconstruct()
Пример #6
0
def test_constructor_no_date():
    field_dict = {'iso': "N/A", 'probability': 0.1}
    date = Date(field_dict)
    assert date.value is None
Пример #7
0
    def __init__(self,
                 api_prediction=None,
                 input_file=None,
                 country=None,
                 id_number=None,
                 birth_date=None,
                 expiry_date=None,
                 issuance_date=None,
                 birth_place=None,
                 gender=None,
                 surname=None,
                 mrz1=None,
                 mrz2=None,
                 given_names=None,
                 mrz=None,
                 full_name=None,
                 page_n=0):
        """
        :param api_prediction: Raw prediction from HTTP response
        :param input_file: Input object
        :param country: country value for creating Passport object from scratch
        :param id_number: id_number value for creating Passport object from scratch
        :param birth_date: birth_date value for creating Passport object from scratch
        :param expiry_date: expiry_date value for creating Passport object from scratch
        :param issuance_date: issuance_date value for creating Passport object from scratch
        :param birth_place: birth_place value for creating Passport object from scratch
        :param gender: gender value for creating Passport object from scratch
        :param surname: surname value for creating Passport object from scratch
        :param mrz1: mrz1 value for creating Passport object from scratch
        :param mrz2: mrz2 value for creating Passport object from scratch
        :param given_names: given_names value for creating Passport object from scratch
        :param mrz: mrz value for creating Passport object from scratch
        :param full_name: full_name value for creating Passport object from scratch
        :param page_n: Page number for multi pages pdf input
        """
        # Raw data
        self.type = "Passport"
        self.country = None
        self.id_number = None
        self.birth_date = None
        self.expiry_date = None
        self.issuance_date = None
        self.birth_place = None
        self.gender = None
        self.surname = None
        self.mrz1 = None
        self.mrz2 = None
        self.given_names = []
        self.mrz = None
        self.full_name = None

        if api_prediction is not None:
            self.build_from_api_prediction(api_prediction)
        else:
            self.country = Field({"value": country},
                                 value_key="value",
                                 page_n=page_n)
            self.id_number = Field({"value": id_number},
                                   value_key="value",
                                   page_n=page_n)
            self.birth_date = Date({"value": birth_date},
                                   value_key="value",
                                   page_n=page_n)
            self.expiry_date = Date({"value": expiry_date},
                                    value_key="value",
                                    page_n=page_n)
            self.issuance_date = Date({"value": issuance_date},
                                      value_key="value",
                                      page_n=page_n)
            self.birth_place = Field({"value": birth_place},
                                     value_key="value",
                                     page_n=page_n)
            self.gender = Field({"value": gender},
                                value_key="value",
                                page_n=page_n)
            self.surname = Field({"value": surname},
                                 value_key="value",
                                 page_n=page_n)
            self.mrz1 = Field({"value": mrz1},
                              value_key="value",
                              page_n=page_n)
            self.mrz2 = Field({"value": mrz2},
                              value_key="value",
                              page_n=page_n)
            if given_names is not None:
                self.given_names = [
                    Field({"value": g}, value_key="value", page_n=page_n)
                    for g in given_names
                ]
            self.mrz = Field({"value": mrz}, value_key="value", page_n=page_n)
            self.full_name = Field({"value": full_name},
                                   value_key="value",
                                   page_n=page_n)

        # Invoke Document constructor
        super(Passport, self).__init__(input_file)

        # Run checks
        self._checklist()

        # Reconstruct extra fields
        self._reconstruct()
Пример #8
0
    def __init__(
            self,
            api_prediction=None,
            input_file=None,
            locale=None,
            total_incl=None,
            date=None,
            category=None,
            merchant_name=None,
            time=None,
            taxes=None,
            orientation=None,
            total_tax=None,
            total_excl=None,
            page_n=0
    ):
        """
        :param api_prediction: Raw prediction from HTTP response
        :param input_file: Input object
        :param locale: locale value for creating Receipt object from scratch
        :param total_incl: total_incl value for creating Receipt object from scratch
        :param date: date value for creating Receipt object from scratch
        :param category: category value for creating Receipt object from scratch
        :param merchant_name: merchant_name value for creating Receipt object from scratch
        :param time: time value for creating Receipt object from scratch
        :param taxes: taxes value for creating Receipt object from scratch
        :param orientation: orientation value for creating Receipt object from scratch
        :param total_tax: total_tax value for creating Receipt object from scratch
        :param total_excl: total_excl value for creating Receipt object from scratch
        :param page_n: Page number for multi pages pdf input
        """
        self.type = "Receipt"
        self.locale = None
        self.total_incl = None
        self.date = None
        self.category = None
        self.merchant_name = None
        self.time = None
        self.taxes = []
        self.orientation = None
        self.total_tax = None
        self.total_excl = None

        if api_prediction is not None:
            self.build_from_api_prediction(api_prediction, page_n=page_n)
        else:
            self.locale = Locale({"value": locale}, value_key="value", page_n=page_n)
            self.total_incl = Amount({"value": total_incl}, value_key="value", page_n=page_n)
            self.date = Date({"value": date}, value_key="value", page_n=page_n)
            self.category = Field({"value": category}, value_key="value", page_n=page_n)
            self.merchant_name = Field({"value": merchant_name}, value_key="value", page_n=page_n)
            self.time = Field({"value": time}, value_key="value", page_n=page_n)
            if taxes is not None:
                self.taxes = [
                    Tax({"value": t[0], "rate": t[1]}, page_n=page_n, value_key="value", rate_key="rate")
                    for t in taxes]
            self.orientation = Orientation({"value": orientation}, value_key="value", page_n=page_n)
            self.total_tax = Amount({"value": total_tax}, value_key="value", page_n=page_n)
            self.total_excl = Amount({"value": total_excl}, value_key="value", page_n=page_n)

        # Invoke Document constructor
        super(Receipt, self).__init__(input_file)

        # Run checks
        self._checklist()

        # Reconstruct extra fields
        self._reconstruct()