Exemplo n.º 1
0
    def compute_precision(invoice, ground_truth):
        """
        :param invoice: Invoice object to compare
        :param ground_truth: Ground truth Invoice object
        :return: Precision metrics
        """
        precisions = {
            "__pre__total_incl":
            Benchmark.scalar_precision_score(invoice.total_incl,
                                             ground_truth.total_incl),
            "__pre__total_excl":
            Benchmark.scalar_precision_score(invoice.total_excl,
                                             ground_truth.total_excl),
            "__pre__invoice_date":
            Benchmark.scalar_precision_score(invoice.invoice_date,
                                             ground_truth.invoice_date),
            "__pre__invoice_number":
            Benchmark.scalar_precision_score(invoice.invoice_number,
                                             ground_truth.invoice_number),
            "__pre__due_date":
            Benchmark.scalar_precision_score(invoice.due_date,
                                             ground_truth.due_date),
            "__pre__total_tax":
            Benchmark.scalar_precision_score(invoice.total_tax,
                                             ground_truth.total_tax)
        }

        if len(invoice.taxes) == 0:
            precisions["__pre__taxes"] = None
        else:
            precisions["__pre__taxes"] = Tax.compare_arrays(
                invoice.taxes, ground_truth.taxes)

        return precisions
Exemplo n.º 2
0
 def compute_accuracy(receipt, ground_truth):
     """
     :param receipt: Receipt object to compare
     :param ground_truth: Ground truth Receipt object
     :return: Accuracy metrics
     """
     return {
         "__acc__total_incl": ground_truth.total_incl == receipt.total_incl,
         "__acc__total_excl": ground_truth.total_excl == receipt.total_excl,
         "__acc__receipt_date": ground_truth.date == receipt.date,
         "__acc__total_tax": ground_truth.total_tax == receipt.total_tax,
         "__acc__taxes": Tax.compare_arrays(receipt.taxes, ground_truth.taxes),
     }
Exemplo n.º 3
0
 def compute_accuracy(invoice, ground_truth):
     """
     :param invoice: Invoice object to compare
     :param ground_truth: Ground truth Invoice object
     :return: Accuracy metrics
     """
     return {
         "__acc__total_incl": ground_truth.total_incl == invoice.total_incl,
         "__acc__total_excl": ground_truth.total_excl == invoice.total_excl,
         "__acc__invoice_date":
         ground_truth.invoice_date == invoice.invoice_date,
         "__acc__invoice_number":
         ground_truth.invoice_number == invoice.invoice_number,
         "__acc__due_date": ground_truth.due_date == invoice.due_date,
         "__acc__total_tax": ground_truth.total_tax == invoice.total_tax,
         "__acc__taxes": Tax.compare_arrays(invoice.taxes,
                                            ground_truth.taxes),
     }
Exemplo n.º 4
0
    def compute_precision(receipt, ground_truth):
        """
        :param receipt: Receipt object to compare
        :param ground_truth: Ground truth Receipt object
        :return: Precision metrics
        """
        precisions = {
            "__pre__total_incl": Benchmark.scalar_precision_score(
                receipt.total_incl, ground_truth.total_incl),
            "__pre__total_excl": Benchmark.scalar_precision_score(
                receipt.total_excl, ground_truth.total_excl),
            "__pre__receipt_date": Benchmark.scalar_precision_score(
                receipt.date, ground_truth.date),
            "__pre__total_tax": Benchmark.scalar_precision_score(
                receipt.total_tax, ground_truth.total_tax)}

        if len(receipt.taxes) == 0:
            precisions["__pre__taxes"] = None
        else:
            precisions["__pre__taxes"] = Tax.compare_arrays(receipt.taxes, ground_truth.taxes)

        return precisions
Exemplo n.º 5
0
 def compute_accuracy(financial_document, ground_truth):
     """
     :param financial_document: FinancialDocument object to compare
     :param ground_truth: Ground truth FinancialDocument object
     :return: Accuracy metrics
     """
     return {
         "__acc__total_incl":
         ground_truth.total_incl == financial_document.total_incl,
         "__acc__total_excl":
         ground_truth.total_excl == financial_document.total_excl,
         "__acc__invoice_date":
         ground_truth.date == financial_document.date,
         "__acc__invoice_number":
         ground_truth.invoice_number == financial_document.invoice_number,
         "__acc__due_date":
         ground_truth.due_date == financial_document.due_date,
         "__acc__total_tax":
         ground_truth.total_tax == financial_document.total_tax,
         "__acc__taxes":
         Tax.compare_arrays(financial_document.taxes, ground_truth.taxes),
     }