(list_op)
return temporary_results
Python execution of MathQA ops.
Python execution of MathQA ops.
Python execution of MathQA ops .
def compute_program(list_op):
  """Python execution of MathQA ops."""
  # The last of temporary results is the final answer.
  temporary_results = []
  num_op = 0
  for op in list_op:
    op_name = op.split('(')[0]
    start_bracket = op.find('(')
    end_bracket = op.find(')')
    op_args = op[start_bracket + 1:end_bracket].split(',')
    num_args = []
    for arg in op_args:
      # The hash stands for a number stored in temporary_results.
      # For example #2 refers to the third temporary result.
      if arg[0] == '#':
        temp_index = int(
            re.findall(r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?',
                       arg)[0])
        num_args.append('t{}'.format(temp_index))
      # The n prefix stands for numbers which listed in list_num -
      # originally they were contained in the text.
      elif arg[0] == 'n':
        # n_index = int(
        #     re.findall(r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?',
        #                arg)[0])
        num_args.append(arg)
      elif arg[0] == 'c':
        if arg == 'const_pi':
          constant = math.pi
        elif arg == 'const_deg_to_rad':
          constant = math.pi / 180
        else:
          consts = re.findall(
              r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?', arg)
          if len(consts) == 1:
            constant = float(consts[0])
          else:
            constant1 = float(consts[0])
            constant2 = float('0.' + consts[1])
            constant = constant1 + constant2
        num_args.append(str(constant))
    temporary_result = 't{} = {}'.format(
        num_op, single_op_to_python_command(op_name, num_args))
    temporary_results.append(temporary_result)
    num_op += 1
  return temporary_results
def compute_program ( list_op ) : # The last of temporary results is the final answer. temporary_results = [ ] num_op = 0 for op in list_op : op_name = op . split ( '(' ) [ 0 ] start_bracket = op . find ( '(' ) end_bracket = op . find ( ')' ) op_args = op [ start_bracket + 1 : end_bracket ] . split ( ',' ) num_args = [ ] for arg in op_args : # The hash stands for a number stored in temporary_results. # For example #2 refers to the third temporary result. if arg [ 0 ] == '#' : temp_index = int ( re . findall ( r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?' , arg ) [ 0 ] ) num_args . append ( 't{}' . format ( temp_index ) ) # The n prefix stands for numbers which listed in list_num - # originally they were contained in the text. elif arg [ 0 ] == 'n' : # n_index = int( #     re.findall(r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?', #                arg)[0]) num_args . append ( arg ) elif arg [ 0 ] == 'c' : if arg == 'const_pi' : constant = math . pi elif arg == 'const_deg_to_rad' : constant = math . pi / 180 else : consts = re . findall ( r'[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?' , arg ) if len ( consts ) == 1 : constant = float ( consts [ 0 ] ) else : constant1 = float ( consts [ 0 ] ) constant2 = float ( '0.' + consts [ 1 ] ) constant = constant1 + constant2 num_args . append ( str ( constant ) ) temporary_result = 't{} = {}' . format ( num_op , single_op_to_python_command ( op_name , num_args ) ) temporary_results . append ( temporary_result ) num_op += 1 return temporary_results