Пример #1
0
    def test_get_regulations_csv(self):
        """
        Test default get regulations behavior.
        :return:
        """
        test_data_path = os.path.join(
            lexnlp_test_path,
            'lexnlp/extract/en/tests/test_regulations/test_get_regulations.csv'
        )
        lexnlp_tests.test_extraction_func_on_test_data(
            get_regulations,
            expected_data_converter=lambda d: [
                (reg_type, reg_code) for reg_type, reg_code, _reg_str in d
            ],
            return_source=False,
            as_dict=False,
            test_data_path=test_data_path)
        lexnlp_tests.test_extraction_func_on_test_data(
            get_regulations,
            expected_data_converter=lambda d: [(reg_type, reg_code, reg_str)
                                               for reg_type, reg_code, reg_str
                                               in d],
            return_source=True,
            as_dict=False,
            test_data_path=test_data_path)

        cmp = DictionaryComparer(check_order=True)
        errors = []

        for (i, text, _input_args, expected) in \
                lexnlp_tests.iter_test_data_text_and_tuple(file_name=test_data_path):
            expected = [{
                'regulation_type': reg_type,
                'regulation_code': reg_code,
                'regulation_text': reg_str
            } for reg_type, reg_code, reg_str in expected]
            actual = list(
                lexnlp_tests.benchmark_extraction_func(get_regulations,
                                                       text,
                                                       return_source=True,
                                                       as_dict=True))

            line_errors = cmp.compare_list_of_dicts(expected, actual)
            if line_errors:
                line_errors_str = '\n'.join(line_errors)
                errors.append(f'Regulation tests, line [{i + 1}] errors:\n' +
                              line_errors_str)

        if errors:
            raise Exception('\n\n'.join(errors))
Пример #2
0
def test_get_citations_as_dict():
    text = 'bob lissner v. test 1 F.2d 1, 2-5 (2d Cir., 1982)'
    expected = [{'citation_str': '1 F.2d 1, 2-5 (2d Cir., 1982)',
                 'court': '2d Cir.',
                 'page': 1,
                 'page2': '2-5',
                 'reporter': 'F.2d',
                 'reporter_full_name': 'Federal Reporter',
                 'volume': 1,
                 'year': 1982}]
    actual = list(lexnlp_tests.benchmark_extraction_func(get_citations,
                                                         text,
                                                         return_source=True,
                                                         as_dict=True))

    cmp = DictionaryComparer(check_order=True)
    errors = cmp.compare_list_of_dicts(expected, actual)
    if errors:
        errors_str = '\n'.join(errors)
        raise Exception('Citations test has errors:\n' + errors_str)