private DerivationState lazyKBestExtractOnNode(KBestExtractor kbestExtractor,int k){
  if (nbests.size() >= k) {
    return nbests.get(k - 1);
  }
  DerivationState derivationState=null;
  if (null == candHeap) {
    getCandidates(kbestExtractor);
  }
  int tAdded=0;
  while (nbests.size() < k) {
    if (candHeap.size() > 0) {
      derivationState=candHeap.poll();
      if (extractUniqueNbest) {
        final String res_str=derivationState.getHypothesis();
        if (!uniqueStringsTable.contains(res_str)) {
          nbests.add(derivationState);
          uniqueStringsTable.add(res_str);
        }
      }
 else {
        nbests.add(derivationState);
      }
      lazyNext(kbestExtractor,derivationState);
      tAdded++;
      if (!extractUniqueNbest && tAdded > 1) {
        throw new RuntimeException("In lazyKBestExtractOnNode, add more than one time, k is " + k);
      }
    }
 else {
      break;
    }
  }
  if (nbests.size() < k) {
    derivationState=null;
  }
  return derivationState;
}

private DerivationState lazyKBestExtractOnNode ( KBestExtractor kbestExtractor , int k ) { if ( nbests . size ( ) >= k ) { return nbests . get ( k - 1 ) ; } DerivationState derivationState = null ; if ( null == candHeap ) { getCandidates ( kbestExtractor ) ; } int tAdded = 0 ; while ( nbests . size ( ) < k ) { if ( candHeap . size ( ) > 0 ) { derivationState = candHeap . poll ( ) ; if ( extractUniqueNbest ) { final String res_str = derivationState . getHypothesis ( ) ; if ( ! uniqueStringsTable . contains ( res_str ) ) { nbests . add ( derivationState ) ; uniqueStringsTable . add ( res_str ) ; } } else { nbests . add ( derivationState ) ; } lazyNext ( kbestExtractor , derivationState ) ; tAdded ++ ; if ( ! extractUniqueNbest && tAdded > 1 ) { throw new RuntimeException ( "In lazyKBestExtractOnNode, add more than one time, k is " + k ) ; } } else { break ; } } if ( nbests . size ( ) < k ) { derivationState = null ; } return derivationState ; }
this returns a derivationstate corresponding to the kth - best derivation rooted at this node .
