def test_act_annotation(self): ant = ActAnnotation(coords=(20, 92), act_name='Some act', section='p IV', year=2021, ambiguous=True, text='Some act of 2021, p IV') s = ant.__repr__() self.assertGreater(len(s), 0) cite = ant.get_cite() self.assertEqual('/en/act/Some act/p IV/2021', cite) old_dic = ant.to_dictionary_legacy() self.assertEqual(20, old_dic['location_start']) self.assertEqual(92, old_dic['location_end']) self.assertEqual('Some act', old_dic['act_name']) self.assertEqual('p IV', old_dic['section']) self.assertEqual(str(2021), old_dic['year']) self.assertEqual(True, old_dic['ambiguous']) self.assertEqual('Some act of 2021, p IV', old_dic['value']) ant = ActAnnotation(coords=(20, 92), act_name='Some act', ambiguous=False, text='Some act of 2021, p IV', locale='pg') cite = ant.get_cite() self.assertEqual('/pg/act/Some act', cite) self.assertEqual('pg', ant.locale)
def get_acts_annotations(text: str) -> Generator[ActAnnotation, None, None]: for match in ACT_PARTS_RE.finditer(text): captures = match.capturesdict() act_name = ''.join(captures.get('act_name') or []) year_str = ''.join(captures.get('year') or []) year = TextAnnotation.safe_cast(year_str, int) act = ActAnnotation(act_name=act_name, coords=match.span(), section=''.join(captures.get('section') or []), year=year, ambiguous=act_name == 'Act', text=''.join(captures.get('text') or []), locale='en') yield act