def test_distances_digits(self):
        text = 'Today I ran 8 miles.'
        ds = list(get_distances(text))
        self.assertEqual(1, len(ds))

        ant = list(get_distance_annotations(text))[0]
        self.assertEqual((12, 20), ant.coords)
        cite = ant.get_cite()
        self.assertEqual('/en/distance/8.0/mile', cite)
    def test_distances_words(self):
        text = 'Today I ran eight kilometers.'
        ds = list(get_distances(text))
        self.assertEqual(1, len(ds))

        ant = list(get_distance_annotations(text))[0]
        self.assertEqual((11, 29), ant.coords)
        cite = ant.get_cite()
        self.assertEqual('/en/distance/8/kilometer', cite)
Exemple #3
0
 def parse(self, log: ProcessLogger, text, text_unit_id, _text_unit_lang, **kwargs) -> ParseResults:
     precision = DEFAULT_FLOAT_PRECIZION
     found = list(distances.get_distance_annotations(text, float_digits=precision))
     if found:
         unique = set(found)
         return ParseResults({DistanceUsage: [DistanceUsage(text_unit_id=text_unit_id,
                                                            amount=item.amount,
                                                            amount_str=item.text,
                                                            distance_type=item.distance_type,
                                                            count=found.count(item)) for item in unique]})