code: def get_candidates(self, docs=None, split=0, sort=False):
          result = []
          if docs:
              docs = docs if isinstance(docs, (list, tuple)) else [docs]
              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:
                  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