def identify_needed_fields(self):
        default_fuzziness = 'e<=2'

        cnpj_found = None
        coo_found = None
        date_found = None
        total_found = None

        lines = "\n".join(self.ocr_results).rstrip().split('\n')
        # Try to get a good match for CNPJ
        cnpj_priority_1_matches = BaseFuzzyRegex.approximate_match(
            word_re='(CNPJ\:\s*){0,1}(\d{2}[\.\,]*\d{3}[\.\,]*\d{3}\/{0,1}\d{4}.{0,1}\d{2})',
            lines=lines,
            fuzziness=default_fuzziness
        )

        cnpj_priority_2_matches = BaseFuzzyRegex.approximate_match(
            word_re='(\d{2}[\.\,]*\d{3}[\.\,]*\d{3}\/{0,1}\d{4}.{0,1}\d{2})',
            lines=lines,
            fuzziness=default_fuzziness
        )

        lines_trim = list(lines)
        lines_trim = [(w.replace(" ","")) for w in lines_trim]

        cnpj_priority_3_matches = BaseFuzzyRegex.approximate_match(
            word_re='(CNPJ\:\s*){0,1}(\d{2}[\.\,]*\d{3}[\.\,]*\d{3}\/{0,1}\d{4}.{0,1}\d{2})',
            lines=lines_trim,
            fuzziness=default_fuzziness
        )

        cnpj_priority_4_matches = BaseFuzzyRegex.approximate_match(
            word_re='(\d{2}[\.\,]*\d{3}[\.\,]*\d{3}\/{0,1}\d{4}.{0,1}\d{2})',
            lines=lines_trim,
            fuzziness=default_fuzziness
        )

        cnpjmerged_lists = cnpj_priority_1_matches + cnpj_priority_2_matches + \
                           cnpj_priority_3_matches + cnpj_priority_4_matches
        if not cnpjmerged_lists is None and len(cnpjmerged_lists) > 0:
            for possible_cnpj in cnpjmerged_lists:
                possible_cnpj = BaseFuzzyRegex.remove_non_numeric(possible_cnpj)
                if Cnpj.validate(possible_cnpj):
                    cnpj_found = possible_cnpj
                    break
            # In case we haven't found a match yet we'll use the best match
            # for the priority group 1
            if cnpj_found is None:
                cnpj_found = BaseFuzzyRegex.remove_non_numeric(cnpjmerged_lists[0])

        # Try to get a good match for COO
        coo_priority_1_matches = BaseFuzzyRegex.approximate_match(
            word_re='COO\:\s*(\d{6})$',
            lines=lines,
            fuzziness=default_fuzziness
        )

        if not coo_priority_1_matches is None and len(coo_priority_1_matches) > 0:
            coo_found = BaseFuzzyRegex.remove_non_numeric(coo_priority_1_matches[0])

        # Try to get a good match for Data
        date_priority_1_matches = BaseFuzzyRegex.approximate_match(
            word_re='(\d{2}\/\d{2}\/\d{4})',
            lines=lines
        )

        if not date_priority_1_matches is None and len(date_priority_1_matches) > 0:
            valid_date_matches = []
            for possible_date in date_priority_1_matches:
                temp = Date.parse(possible_date)
                if not temp is None:
                    valid_date_matches.append(temp)

            if len(valid_date_matches) > 0:
                valid_date_matches.sort(reverse=True)
                date_found = Date.format(valid_date_matches[0])
            else:
                date_found = BaseFuzzyRegex.remove_non_numeric_date(
                    date_priority_1_matches[0]
                )

        # Try to get a good match for Total
        total_priority_1_matches = BaseFuzzyRegex.approximate_match(
            word_re='[TOTAL|R\$]\s*\d+[\,\.]\d{2}$',
            lines=lines
        )

        if not total_priority_1_matches is None and len(total_priority_1_matches) > 0:
            total_found = BaseFuzzyRegex.remove_non_numeric_currency(
                total_priority_1_matches[0])

        return {
            'cnpj': cnpj_found,
            'coo':coo_found,
            'date': date_found,
            'total': total_found
        }
dataset/ETHPy150Open nfscan/ocr-process-service/service/postprocessing.py/TaxReceiptFuzzyRegex.identify_needed_fields/original