def apply(self, context, clear, split, **kwargs):
logger.debug(f"<STR_LIT>")<EOL>for i, candidate_class in enumerate(self.candidate_classes):<EOL><INDENT>logger.debug(f"<STR_LIT>")<EOL>candidate_args = {"<STR_LIT>": split}<EOL>candidate_args["<STR_LIT>"] = context.id<EOL>cands = product(<EOL>*[<EOL>enumerate(<EOL>self.session.query(mention)<EOL>.filter(mention.document_id == context.id)<EOL>.order_by(mention.id)<EOL>.all()<EOL>)<EOL>for mention in candidate_class.mentions<EOL>]<EOL>)<EOL>for cand in cands:<EOL><INDENT>if self.throttlers[i]:<EOL><INDENT>if not self.throttlers[i](<EOL>tuple(cand[j][<NUM_LIT:1>] for j in range(self.arities[i]))<EOL>):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if self.arities[i] == <NUM_LIT:2>:<EOL><INDENT>ai, a = (cand[<NUM_LIT:0>][<NUM_LIT:0>], cand[<NUM_LIT:0>][<NUM_LIT:1>].context)<EOL>bi, b = (cand[<NUM_LIT:1>][<NUM_LIT:0>], cand[<NUM_LIT:1>][<NUM_LIT:1>].context)<EOL>if not self.self_relations and a == b:<EOL><INDENT>logger.debug(f"<STR_LIT>")<EOL>continue<EOL><DEDENT>if not self.nested_relations and (a in b or b in a):<EOL><INDENT>logger.debug(f"<STR_LIT>")<EOL>continue<EOL><DEDENT>if not self.symmetric_relations and ai > bi:<EOL><INDENT>logger.debug(f"<STR_LIT>")<EOL>continue<EOL><DEDENT><DEDENT>for j, arg_name in enumerate(candidate_class.__argnames__):<EOL><INDENT>candidate_args[arg_name + "<STR_LIT>"] = cand[j][<NUM_LIT:1>].id<EOL><DEDENT>if not clear:<EOL><INDENT>q = select([candidate_class.id])<EOL>for key, value in list(candidate_args.items()):<EOL><INDENT>q = q.where(getattr(candidate_class, key) == value)<EOL><DEDENT>candidate_id = self.session.execute(q).first()<EOL>if candidate_id is not None:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>yield candidate_class(**candidate_args)<EOL><DEDENT><DEDENT>
Extract candidates from the given Context.

        :param context: A document to process.
        :param clear: Whether or not to clear the existing database entries.
        :param split: Which split to use.