def apply(self, doc, split, train, lfs, **kwargs):
logger.debug(f"<STR_LIT>")<EOL>if lfs is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self.lfs = lfs<EOL>cands_list = get_cands_list_from_split(<EOL>self.session, self.candidate_classes, doc, split<EOL>)<EOL>label_map = dict()<EOL>for cands in cands_list:<EOL><INDENT>records = list(<EOL>get_mapping(self.session, Label, cands, self._f_gen, label_map)<EOL>)<EOL>batch_upsert_records(self.session, Label, records)<EOL><DEDENT>if train:<EOL><INDENT>upsert_keys(self.session, LabelKey, label_map)<EOL><DEDENT>return<EOL>yield<EOL>
Extract candidates from the given Context.

        :param doc: A document to process.
        :param split: Which split to use.
        :param train: Whether or not to insert new LabelKeys.
        :param lfs: The list of functions to use to generate labels.