def test_money(self): text = "100 bucks, 100 dollars, 100 greens" ds = list(get_money(text)) self.assertEqual(1, len(ds)) ants = list(get_money_annotations(text)) self.assertEqual(1, len(ds)) self.assertEqual('en', ants[0].locale) self.assertEqual('USD', ants[0].currency) self.assertEqual(100.0, ants[0].amount)
def parse(self, log: ProcessLogger, text, text_unit_id, _text_unit_lang, **kwargs) -> ParseResults: found = list(money.get_money_annotations(text, float_digits=DEFAULT_FLOAT_PRECIZION)) if found: unique = set(found) return ParseResults({CurrencyUsage: [CurrencyUsage(text_unit_id=text_unit_id, amount=item.amount, amount_str=item.text, currency=item.currency, count=found.count(item) ) for item in unique]})
def get_money_annotations_sorted(text): ants = list(get_money_annotations(text)) ants.sort(key=lambda a: a.coords[0]) return ants