public void assignLabels( LingoProcessingContext context, DoubleMatrix2D stemCos, IntIntOpenHashMap filteredRowToStemIndex, DoubleMatrix2D phraseCos )
        {
            PreprocessingContext preprocessingContext = context.preprocessingContext;
            int firstPhraseIndex = preprocessingContext.allLabels.firstPhraseIndex;
            int [] labelsFeatureIndex = preprocessingContext.allLabels.featureIndex;
            int [] mostFrequentOriginalWordIndex = preprocessingContext.allStems.mostFrequentOriginalWordIndex;
            int desiredClusterCount = stemCos.columns();

            IntArrayList clusterLabelFeatureIndex = new IntArrayList(
                desiredClusterCount);
            DoubleArrayList clusterLabelScore = new DoubleArrayList(desiredClusterCount);
            for (int label = 0; label < desiredClusterCount; label++)
            {
                Pair<int, int> stemMax = max(stemCos);
                Pair<int, int> phraseMax = max(phraseCos);

                if (stemMax == null && phraseMax == null)
                {
                    break;
                }

                double stemScore = stemMax != null ? stemCos.getQuick(stemMax.objectA,
                    stemMax.objectB) : -1;
                double phraseScore = phraseMax != null ? phraseCos.getQuick(
                    phraseMax.objectA, phraseMax.objectB) : -1;

                if (phraseScore > stemScore)
                {
                    phraseCos.viewRow(phraseMax.objectA).assign(0);
                    phraseCos.viewColumn(phraseMax.objectB).assign(0);
                    stemCos.viewColumn(phraseMax.objectB).assign(0);

                    clusterLabelFeatureIndex.add(labelsFeatureIndex[phraseMax.objectA
                        + firstPhraseIndex]);
                    clusterLabelScore.add(phraseScore);
                }
                else
                {
                    stemCos.viewRow(stemMax.objectA).assign(0);
                    stemCos.viewColumn(stemMax.objectB).assign(0);
                    if (phraseCos != null)
                    {
                        phraseCos.viewColumn(stemMax.objectB).assign(0);
                    }

                    clusterLabelFeatureIndex
                        .add(mostFrequentOriginalWordIndex[filteredRowToStemIndex
                            .get(stemMax.objectA)]);
                    clusterLabelScore.add(stemScore);
                }
            }

            context.clusterLabelFeatureIndex = clusterLabelFeatureIndex.toArray();
            context.clusterLabelScore = clusterLabelScore.toArray();
        }