Ejemplo n.º 1
0
 def test_complex_durations(self):
     text = 'Vier Wochen, 3 Tage und 151 Sekunden.'
     ants = list(get_duration_annotations(text=text))
     self.assertEqual(1, len(ants))
     self.assertEqual(31.0017, ants[0].duration_days)
     self.assertTrue(ants[0].is_complex)
     self.assertEqual('second', ants[0].duration_type_en)
     self.assertEqual('sekunden', ants[0].duration_type)
Ejemplo n.º 2
0
    def test_written_duration(self):
        text = 'seit fünfundzwanzig Jahren'
        res = get_duration_list(text=text)
        self.assertCountEqual(res, [{'location_start': 4,
                                     'location_end': 26,
                                     'source_text': ' fünfundzwanzig Jahren',
                                     'unit_name_local': 'jahren',
                                     'unit_name': 'year',
                                     'unit_prefix': '',
                                     'amount': 25,
                                     'amount_days': 9125}])

        ants = list(get_duration_annotations(text=text))
        self.assertEqual((4, 26), ants[0].coords)
        self.assertEqual('fünfundzwanzig Jahren', ants[0].text.strip())
        self.assertEqual('jahren', ants[0].duration_type)
        self.assertEqual('year', ants[0].duration_type_en)
        self.assertEqual('', ants[0].prefix)
        self.assertEqual(Decimal(25), ants[0].amount)
        self.assertEqual(Decimal(9125), ants[0].duration_days)
Ejemplo n.º 3
0
def get_ordered_durations(text: str) -> List[DurationAnnotation]:
    ants = list(get_duration_annotations(text))
    ants.sort(key=lambda a: a.coords[0])
    return ants