Exemple #1
0
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
Exemple #2
0
 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))
Exemple #3
0
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)
Exemple #4
0
def _get_numeric_value_from_float(value):
  return interaction_pb2.NumericValue(float_value=value)
Exemple #5
0
def _number(float_value):
  nv = interaction_pb2.NumericValue()
  nv.float_value = float_value
  return nv
Exemple #6
0
 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))