if (featureIndex.length == 0)
{
return new DenseDoubleMatrix2D(stemToRowIndex.size(), 0);
}
final DoubleMatrix2D phraseMatrix = new SparseDoubleMatrix2D(stemToRowIndex
.size(), featureIndex.length);
final PreprocessingContext preprocessingContext = vsmContext.preprocessingContext;
final int [] wordsStemIndex = preprocessingContext.allWords.stemIndex;
final int [] stemsTf = preprocessingContext.allStems.tf;
final int [][] stemsTfByDocument = preprocessingContext.allStems.tfByDocument;
final int [][] phrasesWordIndices = preprocessingContext.allPhrases.wordIndices;
final int documentCount = preprocessingContext.documents.size();
final int wordCount = wordsStemIndex.length;
for (int i = 0; i < featureIndex.length; i++)
{
final int feature = featureIndex[i];
final int [] wordIndices;
if (feature < wordCount)
{
wordIndices = new int []
{
feature
};
}
else
{
wordIndices = phrasesWordIndices[feature - wordCount];
}
for (int wordIndex = 0; wordIndex < wordIndices.length; wordIndex++)
{
final int stemIndex = wordsStemIndex[wordIndices[wordIndex]];
if (stemToRowIndex.containsKey(stemIndex))
{
final int rowIndex = stemToRowIndex.lget();
double weight = termWeighting.calculateTermWeight(stemsTf[stemIndex],
stemsTfByDocument[stemIndex].length / 2, documentCount);
phraseMatrix.setQuick(rowIndex, i, weight);
}
}
}
return phraseMatrix;