def _date(year=None, month=None, day=None): nv = interaction_pb2.NumericValue() if year: nv.date.year = year if month: nv.date.month = month if day: nv.date.day = day return nv
def test_parse_complete_dates(self, text, day, month, year): span = interaction_pb2.NumericValueSpan( begin_index=0, end_index=len(text), values=[ interaction_pb2.NumericValue( date=interaction_pb2.Date(year=year, month=month, day=day)) ]) self.assertEqual([span], number_utils.parse_text(text))
def _get_numeric_value_from_date(date, mask): """Converts date to a numeric value proto with a date value.""" if date.year < _MIN_YEAR or date.year > _MAX_YEAR: raise ValueError('Invalid year: %d' % date.year) new_date = interaction_pb2.Date() if mask.year: new_date.year = date.year if mask.month: new_date.month = date.month if mask.day: new_date.day = date.day return interaction_pb2.NumericValue(date=new_date)
def _get_numeric_value_from_float(value): return interaction_pb2.NumericValue(float_value=value)
def _number(float_value): nv = interaction_pb2.NumericValue() nv.float_value = float_value return nv
def test_parse_numerals(self, text): span = interaction_pb2.NumericValueSpan( begin_index=0, end_index=len(text), values=[interaction_pb2.NumericValue(float_value=12)]) self.assertEqual([span], number_utils.parse_text(text))