code: def get_candidates(self, docs=None, split=0, sort=False):
          
          result = []
          if docs:
              docs = docs if isinstance(docs, (list, tuple)) else [docs]
              # Get cands from all splits
              for candidate_class in self.candidate_classes:
                  cands = (
                      self.session.query(candidate_class)
                      .filter(candidate_class.document_id.in_([doc.id for doc in docs]))
                      .order_by(candidate_class.id)
                      .all()
                  )
                  if sort:
                      cands = sorted(
                          cands,
                          key=lambda x: " ".join(
                              [x[i][0].get_stable_id() for i in range(len(x))]
                          ),
                      )
                  result.append(cands)
          else:
              for candidate_class in self.candidate_classes:
                  # Filter by candidate_ids in a particular split
                  sub_query = (
                      self.session.query(Candidate.id)
                      .filter(Candidate.split == split)
                      .subquery()
                  )
                  cands = (
                      self.session.query(candidate_class)
                      .filter(candidate_class.id.in_(sub_query))
                      .order_by(candidate_class.id)
                      .all()
                  )
                  if sort:
                      cands = sorted(
                          cands,
                          key=lambda x: " ".join(
                              [x[i][0].get_stable_id() for i in range(len(x))]
                          ),
                      )
                  result.append(cands)
          return result
docs: Return a list of lists of the candidates associated with this extractor.
  
          Each list of the return will contain the candidates for one of the
          candidate classes associated with the CandidateExtractor.
  
          :param docs: If provided, return candidates from these documents from
              all splits.
          :type docs: list, tuple of ``Documents``.
          :param split: If docs is None, then return all the candidates from this
              split.
          :type split: int
          :param sort: If sort is True, then return all candidates sorted by stable_id.
          :type sort: bool
          :return: Candidates for each candidate_class.
          :rtype: List of lists of ``Candidates``.