Exemple #1
0
 def parse(self, log: ProcessLogger, text, text_unit_id, _text_unit_lang, **kwargs) -> ParseResults:
     found = list(regulations.get_regulation_annotations(text))
     if found:
         unique = set(found)
         return ParseResults({RegulationUsage: [RegulationUsage(text_unit_id=text_unit_id,
                                                                regulation_type=item.source,
                                                                regulation_name=item.name,
                                                                count=found.count(item)) for item in unique]})
Exemple #2
0
    def test_regulations(self):
        text = 'test 123 U.S.C § 456, code'
        rs = list(get_regulations(text))
        self.assertEqual(1, len(rs))
        self.assertEqual('United States Code', rs[0][0])
        self.assertEqual('123 USC § 456', rs[0][1])

        rs = list(get_regulations(text, as_dict=True))
        self.assertEqual(1, len(rs))
        self.assertEqual('United States Code', rs[0]['regulation_type'])
        self.assertEqual('123 USC § 456', rs[0]['regulation_code'])

        ants = list(get_regulation_annotations(text))
        self.assertEqual(1, len(ants))
        self.assertEqual('en', ants[0].locale)
        self.assertEqual('123 USC § 456', ants[0].name)
        self.assertEqual('United States Code', ants[0].source)

        start = text.find('123')
        self.assertGreater(ants[0].coords[1], ants[0].coords[0])
        self.assertEqual((start, ants[0].coords[1]), ants[0].coords)