コード例 #1
0
    def test_fraction_symbol(self):
        text = "1½ of apple"
        amts = list(get_amount_annotations(text))
        self.assertEqual(1, len(amts))
        self.assertEqual(1.5, amts[0].value)

        text = '2 ⅗'
        amts = list(get_amount_annotations(text))
        self.assertEqual(1, len(amts))
        self.assertEqual(2.6, amts[0].value)
コード例 #2
0
 def parse(self, log: ProcessLogger, text, text_unit_id, _text_unit_lang, **kwargs) -> ParseResults:
     precision = DEFAULT_FLOAT_PRECIZION
     found = list(amounts.get_amount_annotations(text,
                                                 extended_sources=False,
                                                 float_digits=precision))
     if found:
         unique = set(found)
         return ParseResults({AmountUsage: [AmountUsage(text_unit_id=text_unit_id,
                                                        amount=item.value,
                                                        amount_str=item.text[:300] if item.text else None,
                                                        count=found.count(item)
                                                        ) for item in unique]})