public static void addToTable(int curIndex, TreeSet<PairOfFloatString> topTrans, float cumProb, TTable_monolithic_IFAs table,
Vocab trgVocab, float cumProbThreshold, HookaStats stats) {
List<Integer> sortedIndices = new ArrayList<Integer>();
HMapIF index2ProbMap = new HMapIF();
float sumOfProbs = 0.0f; //only extract the top K<15 if the mass prob. exceeds MAX_probThreshold
while(!topTrans.isEmpty() && sumOfProbs < cumProbThreshold){
PairOfFloatString e = topTrans.pollLast();
String term = e.getRightElement();
float pr = e.getLeftElement()/cumProb; // normalize
logger.debug(term+"-->"+pr);
int trgIndex = trgVocab.addOrGet(term);
sumOfProbs += e.getLeftElement(); // keep track of unnormalized cumulative prob for determining cutoff
sortedIndices.add(trgIndex);
index2ProbMap.put(trgIndex, pr);
}
// to enable faster access with binary search, we sort entries by vocabulary index.
Collections.sort(sortedIndices);
int numEntries = sortedIndices.size();
// for statistics only
stats.update(numEntries, sumOfProbs);
// write translation list to TTable object
int[] indices = new int[numEntries];
float[] probs = new float[numEntries];
int i=0;
for(int sortedIndex : sortedIndices){
indices[i]=sortedIndex;
probs[i]=index2ProbMap.get(sortedIndex);
i++;
}
table.set(curIndex, new IndexedFloatArray(indices, probs, true));
}