def evaluate_logical_form(self, logical_form: str,
                           target_list: List[str]) -> bool:
     """
     Takes a logical form, and the list of target values as strings from the original lisp
     string, and returns True iff the logical form executes to the target list.
     """
     normalized_target_list = [
         TableQuestionContext.normalize_string(value)
         for value in target_list
     ]
     target_value_list = evaluator.to_value_list(normalized_target_list)
     try:
         denotation = self.execute(logical_form)
     except ExecutionError:
         logger.warning(f'Failed to execute: {logical_form}')
         return False
     if isinstance(denotation, list):
         denotation_list = [
             str(denotation_item) for denotation_item in denotation
         ]
     else:
         denotation_list = [str(denotation)]
     denotation_value_list = evaluator.to_value_list(denotation_list)
     return evaluator.check_denotation(target_value_list,
                                       denotation_value_list)
Exemplo n.º 2
0
    def evaluate_logical_form(self, 
                            logical_form: str, 
                            target_value: List[str], 
                            target_canon: List[str]) -> bool:
        """
        Taken from Chen's script
        """
        target_value_strings = tsv_unescape_list(target_value)
        normalized_target_value_strings = [ TableQuestionContext.normalize_string(value) 
                    for value in target_value_strings]
        canon_value_strings = tsv_unescape_list(target_canon)
        target_value_list = to_value_list(normalized_target_value_strings, canon_value_strings)

        try:
            denotation = self.execute(logical_form)
        except ExecutionError:
            logger.warning(f'Failed to execute: {logical_form}')
            return False
        except Exception as ex:
            err_template = "Exception of type {0} occurred. Arguments:\n{1!r}"
            message = err_template.format(type(ex).__name__, ex.args)
            logger.warning(f'{message}')
        
        if isinstance(denotation, list):
            denotation_list = [str(denotation_item) for denotation_item in denotation]
        else: 
            denotation_list = [str(denotation)]
        denotation_value_list = to_value_list(denotation_list)
        return check_denotation(target_value_list, denotation_value_list)
 def evaluate_logical_form(self, logical_form: str, target_list: List[str]) -> bool:
     """
     Takes a logical form, and the list of target values as strings from the original lisp
     string, and returns True iff the logical form executes to the target list.
     """
     normalized_target_list = [TableQuestionContext.normalize_string(value) for value in
                               target_list]
     target_value_list = evaluator.to_value_list(normalized_target_list)
     try:
         denotation = self.execute(logical_form)
     except ExecutionError:
         logger.warning(f'Failed to execute: {logical_form}')
         return False
     if isinstance(denotation, list):
         denotation_list = [str(denotation_item) for denotation_item in denotation]
     else:
         denotation_list = [str(denotation)]
     denotation_value_list = evaluator.to_value_list(denotation_list)
     return evaluator.check_denotation(target_value_list, denotation_value_list)
Exemplo n.º 4
0
 def evaluate_denotation(self, denotation: Any,
                         target_list: List[str]) -> bool:
     """
     Compares denotation with a target list and returns whether they are both the same according to the official
     evaluator.
     """
     normalized_target_list = [
         TableQuestionContext.normalize_string(value)
         for value in target_list
     ]
     target_value_list = evaluator.to_value_list(normalized_target_list)
     if isinstance(denotation, list):
         denotation_list = [
             str(denotation_item) for denotation_item in denotation
         ]
     else:
         denotation_list = [str(denotation)]
     denotation_value_list = evaluator.to_value_list(denotation_list)
     return evaluator.check_denotation(target_value_list,
                                       denotation_value_list)