Exemplo n.º 1
0
    def _parse_compare(self, op_tokens, arg_tokens):
        if len(op_tokens) >= 3:
            if normalize(op_tokens[1]) == 'more':
                return (normalize(op_tokens[2]), False)
            elif normalize(op_tokens[1]) == 'less':
                return (normalize(op_tokens[2]), True)

        token = normalize(op_tokens[1])
        if token.endswith('er'):
            token = token[:-2]
            if token.endswith('i'):
                token = token[:-1] + 'y'

        return (token, False)
Exemplo n.º 2
0
    def parse_question(self, question, discard_global):
        # Filter out 'global' questions
        if discard_global and question['semantic'][0][
                'operation'] == 'select' and question['semantic'][0][
                    'argument'] == 'scene':
            return None

        ops, args, deps = self.parse_program(question['semantic'])
        if None in ops or None in args:
            return None

        # Combine all 'verify_attr-and' to 'verify_attrs'
        trace, _ = self._compute_op_trace(ops, deps)
        ops, args, deps, trace = self._combine_verify(ops, args, deps, trace)

        if self._is_batch_format:
            question['program'] = self._de_branch_program(ops, args, deps)
            question['program'] = self._fix_logical_branches(
                question['program'])
        else:
            question['operators'] = ops
            question['arguments'] = args
            question['dependencies'] = deps

        question['answer'] = normalize(question['answer'])
        # print(question['semantic'], ' ---> ', ops, args, deps)
        return question
Exemplo n.º 3
0
 def _parse_two_different(self, op_tokens, arg_tokens):
     op_tokens = [normalize(t) for t in op_tokens[1:]]
     return (' '.join(op_tokens), )
Exemplo n.º 4
0
 def _parse_all_different(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[0]), )
Exemplo n.º 5
0
 def _parse_all_same(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[0]), )
Exemplo n.º 6
0
 def _parse_verify_rel(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[1]), arg_tokens[2] == 's',
             normalize(arg_tokens[0]))
Exemplo n.º 7
0
 def _parse_choose_rel(self, op_tokens, arg_tokens):
     rels = re.split('\|', arg_tokens[1])
     rels = [normalize(r) for r in rels]
     return (rels, arg_tokens[2] == 's', normalize(arg_tokens[0]))
Exemplo n.º 8
0
 def _parse_verify_attrs(self, op_tokens, arg_tokens):
     return ([normalize(t) for t in arg_tokens], )
Exemplo n.º 9
0
 def _parse_verify_attr(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[0]), )
Exemplo n.º 10
0
 def _parse_choose_attr(self, op_tokens, arg_tokens):
     arg_tokens = re.split('\|', arg_tokens[0])
     return ([normalize(t) for t in arg_tokens], )
Exemplo n.º 11
0
 def _parse_filter(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[0]), )
Exemplo n.º 12
0
 def _parse_select(self, op_tokens, arg_tokens):
     return (normalize(arg_tokens[0]), )