示例#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
示例#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))
示例#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)
示例#4
0
def _get_numeric_value_from_float(value):
  return interaction_pb2.NumericValue(float_value=value)
示例#5
0
def _number(float_value):
  nv = interaction_pb2.NumericValue()
  nv.float_value = float_value
  return nv
示例#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))