예제 #1
0
 def __reconstruct_total_excl_from_tcc_and_taxes(self):
     """
     Set self.total_excl with Amount object
     The total_excl Amount value is the difference between total_incl and sum of taxes
     The total_excl Amount probability is the product of self.taxes probabilities multiplied by total_incl probability
     """
     if len(self.taxes) and self.total_incl.value is not None:
         total_excl = {
             "value": self.total_incl.value - Field.array_sum(self.taxes),
             "probability": Field.array_probability(self.taxes) * self.total_incl.probability
         }
         self.total_excl = Amount(total_excl, value_key="value", reconstructed=True)
예제 #2
0
 def __reconstruct_total_tax(self):
     """
     Set self.total_tax with Amount object
     The total_tax Amount value is the sum of all self.taxes value
     The total_tax Amount probability is the product of self.taxes probabilities
     """
     if len(self.taxes) and self.total_tax.value is None:
         total_tax = {
             "value": sum([tax.value if tax.value is not None else 0 for tax in self.taxes]),
             "probability": Field.array_probability(self.taxes)
         }
         if total_tax["value"] > 0:
             self.total_tax = Amount(total_tax, value_key="value", reconstructed=True)
예제 #3
0
 def __reconstruct_mrz(self):
     """
     Set self.mrz with Field object
     The mrz Field value is the concatenation of mrz1 and mr2
     The mrz Field probability is the product of mrz1 and mrz2 probabilities
     """
     if self.mrz1.value is not None \
             and self.mrz2.value is not None \
             and self.mrz.value is None:
         mrz = {
             "value":
             self.mrz1.value + self.mrz2.value,
             "probability":
             Field.array_probability(
                 [self.mrz1.probability, self.mrz2.probability])
         }
         self.mrz = Field(mrz, reconstructed=True)
예제 #4
0
 def __reconstruct_full_name(self):
     """
     Set self.full_name with Field object
     The full_name Field value is the concatenation of first given name and last name
     The full_name Field probability is the product of first given name and last name probabilities
     """
     if self.surname.value is not None \
             and len(self.given_names) != 0 \
             and self.given_names[0].value is not None \
             and self.full_name.value is None:
         full_name = {
             "value":
             self.given_names[0].value + " " + self.surname.value,
             "probability":
             Field.array_probability([
                 self.surname.probability, self.given_names[0].probability
             ])
         }
         self.full_name = Field(full_name, reconstructed=True)
예제 #5
0
 def __reconstruct_total_excl_from_tcc_and_taxes(self):
     """
     Set self.total_excl with Amount object
     The total_excl Amount value is the difference between total_incl and sum of taxes
     The total_excl Amount probability is the product of self.taxes probabilities multiplied by total_incl probability
     """
     # Check total_tax, total excl and total incl exist
     if self.total_incl.value is None or len(
             self.taxes) == 0 or self.total_excl.value is not None:
         pass
     else:
         total_excl = {
             "value":
             self.total_incl.value - sum([
                 tax.value if tax.value is not None else 0
                 for tax in self.taxes
             ]),
             "probability":
             Field.array_probability(self.taxes) *
             self.total_incl.probability
         }
         self.total_excl = Amount(total_excl,
                                  value_key="value",
                                  reconstructed=True)
예제 #6
0
def test_array_probability():
    fields = [Field({"value": None, "probability": 0.1}), Field({"value": None, "probability": 0.8})]
    assert Field.array_probability(fields) == 0.8*0.1
    fields = [Field({"value": None, "probability": 0.1}), Field({"value": None, "probability": None})]
    assert Field.array_probability(fields) == 0.