def apply(self, context, clear, split, **kwargs):
    for i in range(self.arity):
        self.child_context_sets[i].clear()
        for tc in self.matchers[i].apply(self.candidate_spaces[i].apply(context)):
            tc.load_id_or_insert(self.session)
            self.child_context_sets[i].add(tc)
    extracted = set()
    candidate_args = {'split': split}
    for args in product(*[enumerate(child_contexts) for child_contexts in self.child_context_sets]):
        if (self.arity == 2):
            (ai, a) = args[0]
            (bi, b) = args[1]
            if ((not self.self_relations) and (a == b)):
                continue
            elif ((not self.nested_relations) and ((a in b) or (b in a))):
                continue
            elif ((not self.symmetric_relations) and (((b, a) in extracted) or ((self.matchers[0] == self.matchers[1]) and (a.char_start > b.char_start)))):
                continue
            extracted.add((a, b))
        for (i, arg_name) in enumerate(self.candidate_class.__argnames__):
            candidate_args[(arg_name + '_id')] = args[i][1].id
        if (not clear):
            q = select([self.candidate_class.id])
            for (key, value) in iteritems(candidate_args):
                q = q.where((getattr(self.candidate_class, key) == value))
            candidate_id = self.session.execute(q).first()
            if (candidate_id is not None):
                continue
        (yield self.candidate_class(**candidate_args))
def apply(self, context, clear, split, **kwargs):
    for i in range(self.arity):
        self.child_context_sets[i].clear()
        for tc in self.matchers[i].apply(self.candidate_spaces[i].apply(context)):
            tc.load_id_or_insert(self.session)
            self.child_context_sets[i].add(tc)
    extracted = set()
    candidate_args = {'split': split}
    for args in product(*[enumerate(child_contexts) for child_contexts in self.child_context_sets]):
        if (self.arity == 2):
            (ai, a) = args[0]
            (bi, b) = args[1]
            if ((not self.self_relations) and (a == b)):
                continue
            elif ((not self.nested_relations) and ((a in b) or (b in a))):
                continue
            elif ((not self.symmetric_relations) and (((b, a) in extracted) or ((self.matchers[0] == self.matchers[1]) and (a.char_start > b.char_start)))):
                continue
            extracted.add((a, b))
        for (i, arg_name) in enumerate(self.candidate_class.__argnames__):
            candidate_args[(arg_name + '_id')] = args[i][1].id
        if (not clear):
            q = select([self.candidate_class.id])
            for (key, value) in iteritems(candidate_args):
                q = q.where((getattr(self.candidate_class, key) == value))
            candidate_id = self.session.execute(q).first()
            if (candidate_id is not None):
                continue
        (yield self.candidate_class(**candidate_args))