Exemple #1
0
    def do_tgrep_with_callback(root, pattern, callback, **kwargs):
        new_root = None
        for match_node, context in tgrep(root, pattern, with_context=True, **kwargs):
            debug("Callback %s matched", callback.__name__)
            if context:  # only supply a context if the expression binds variables
                # smash the case, variables in tgrep expressions are case insensitive
                result = callback(match_node, **smash_key_case(context))
            else:
                result = callback(match_node)

            # a new root will be returned if one has been installed
            if result:
                new_root = result

        return new_root or root
Exemple #2
0
    def accept_derivation(self, bundle):
        found_rc = False
        root = bundle.derivation
        for node, ctx in tgrep(root, r'{ /SBAR/=SBAR < /WHNP/=WHNP } $ /NP/=NP', with_context=True):
            trace_finder = r"^/\*T\*%s/" % extract_index(ctx.whnp)
            trace_node = get_first(ctx.sbar, trace_finder)
            if trace_node is not None:
                if not found_rc:
                    self.rcderivs += 1
                    found_rc = True

                parent_type = trace_node.parent.tag
                parent_type = re.sub(r'-\d+$', '', parent_type)
                self.parents[ parent_type ] += 1
        
        self.total += 1
Exemple #3
0
    def do_tgrep_with_callback(root, pattern, callback, **kwargs):
        new_root = None
        for match_node, context in tgrep(root,
                                         pattern,
                                         with_context=True,
                                         **kwargs):
            debug("Callback %s matched", callback.__name__)
            if context:  # only supply a context if the expression binds variables
                # smash the case, variables in tgrep expressions are case insensitive
                result = callback(match_node, **smash_key_case(context))
            else:
                result = callback(match_node)

            # a new root will be returned if one has been installed
            if result: new_root = result

        return new_root or root
Exemple #4
0
    def accept_derivation(self, bundle):
        found_rc = False
        root = bundle.derivation
        for node, ctx in tgrep(root,
                               r'{ /SBAR/=SBAR < /WHNP/=WHNP } $ /NP/=NP',
                               with_context=True):
            trace_finder = r"^/\*T\*%s/" % extract_index(ctx.whnp)
            trace_node = get_first(ctx.sbar, trace_finder)
            if trace_node is not None:
                if not found_rc:
                    self.rcderivs += 1
                    found_rc = True

                parent_type = trace_node.parent.tag
                parent_type = re.sub(r'-\d+$', '', parent_type)
                self.parents[parent_type] += 1

        self.total += 1