nodes: 0, module; 1, function_definition; 2, function_name:get_candidates; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:docs; 14, None; 15, identifier:split; 16, integer:0; 17, identifier:sort; 18, False; 19, comment:"""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``.
          """; 20, assignment; 21, identifier:docs; 22, block; 23, else_clause; 24, identifier:result; 25, identifier:result; 26, list; 27, expression_statement; 28, comment:# Get cands from all splits; 29, for_statement; 30, block; 31, assignment; 32, identifier:candidate_class; 33, attribute; 34, block; 35, for_statement; 36, identifier:docs; 37, conditional_expression:docs if isinstance(docs, (list, tuple)) else [docs]; 38, identifier:self; 39, identifier:candidate_classes; 40, expression_statement; 41, if_statement; 42, expression_statement; 43, identifier:candidate_class; 44, attribute; 45, comment:# Filter by candidate_ids in a particular split; 46, block; 47, identifier:docs; 48, call; 49, list; 50, assignment; 51, identifier:sort; 52, block; 53, call; 54, identifier:self; 55, identifier:candidate_classes; 56, expression_statement; 57, expression_statement; 58, if_statement; 59, expression_statement; 60, identifier:isinstance; 61, argument_list; 62, identifier:docs; 63, identifier:cands; 64, parenthesized_expression; 65, expression_statement; 66, attribute; 67, argument_list; 68, assignment; 69, assignment; 70, identifier:sort; 71, block; 72, call; 73, identifier:docs; 74, tuple; 75, call; 76, assignment; 77, identifier:result; 78, identifier:append; 79, identifier:cands; 80, identifier:sub_query; 81, parenthesized_expression; 82, identifier:cands; 83, parenthesized_expression; 84, expression_statement; 85, attribute; 86, argument_list; 87, identifier:list; 88, identifier:tuple; 89, attribute; 90, argument_list; 91, identifier:cands; 92, call; 93, call; 94, call; 95, assignment; 96, identifier:result; 97, identifier:append; 98, identifier:cands; 99, call; 100, identifier:all; 101, identifier:sorted; 102, argument_list; 103, attribute; 104, argument_list; 105, attribute; 106, argument_list; 107, identifier:cands; 108, call; 109, attribute; 110, argument_list; 111, identifier:cands; 112, keyword_argument; 113, call; 114, identifier:subquery; 115, call; 116, identifier:all; 117, identifier:sorted; 118, argument_list; 119, call; 120, identifier:order_by; 121, attribute; 122, identifier:key; 123, lambda; 124, attribute; 125, argument_list; 126, attribute; 127, argument_list; 128, identifier:cands; 129, keyword_argument; 130, attribute; 131, argument_list; 132, identifier:candidate_class; 133, identifier:id; 134, lambda_parameters; 135, call; 136, call; 137, identifier:filter; 138, comparison_operator:Candidate.split == split; 139, call; 140, identifier:order_by; 141, attribute; 142, identifier:key; 143, lambda; 144, call; 145, identifier:filter; 146, call; 147, identifier:x; 148, attribute; 149, argument_list; 150, attribute; 151, argument_list; 152, attribute; 153, identifier:split; 154, attribute; 155, argument_list; 156, identifier:candidate_class; 157, identifier:id; 158, lambda_parameters; 159, call; 160, attribute; 161, argument_list; 162, attribute; 163, argument_list; 164, string:" "; 165, identifier:join; 166, list_comprehension; 167, attribute; 168, identifier:query; 169, attribute; 170, identifier:Candidate; 171, identifier:split; 172, call; 173, identifier:filter; 174, call; 175, identifier:x; 176, attribute; 177, argument_list; 178, attribute; 179, identifier:query; 180, identifier:candidate_class; 181, attribute; 182, identifier:in_; 183, list_comprehension; 184, call; 185, for_in_clause; 186, identifier:self; 187, identifier:session; 188, identifier:Candidate; 189, identifier:id; 190, attribute; 191, argument_list; 192, attribute; 193, argument_list; 194, string:" "; 195, identifier:join; 196, list_comprehension; 197, identifier:self; 198, identifier:session; 199, identifier:candidate_class; 200, identifier:document_id; 201, attribute; 202, for_in_clause; 203, attribute; 204, argument_list; 205, identifier:i; 206, call; 207, attribute; 208, identifier:query; 209, identifier:candidate_class; 210, attribute; 211, identifier:in_; 212, identifier:sub_query; 213, call; 214, for_in_clause; 215, identifier:doc; 216, identifier:id; 217, identifier:doc; 218, identifier:docs; 219, subscript; 220, identifier:get_stable_id; 221, identifier:range; 222, argument_list; 223, identifier:self; 224, identifier:session; 225, identifier:candidate_class; 226, identifier:id; 227, attribute; 228, argument_list; 229, identifier:i; 230, call; 231, subscript; 232, integer:0; 233, call; 234, subscript; 235, identifier:get_stable_id; 236, identifier:range; 237, argument_list; 238, identifier:x; 239, identifier:i; 240, identifier:len; 241, argument_list; 242, subscript; 243, integer:0; 244, call; 245, identifier:x; 246, identifier:x; 247, identifier:i; 248, identifier:len; 249, argument_list; 250, identifier:x
code: def get_candidates(self, docs=None, split=0, sort=False):
          """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``.
          """
          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