Esempio n. 1
0
        //returns index of closest cluster centroid
        public static int FindClosestClusterCenter(List <Centroid> clusterCenter, DocumentVector obj, string sim)
        {
            float[] similarityMeasure = new float[clusterCenter.Count()];

            for (int i = 0; i < clusterCenter.Count(); i++)
            {
                if (sim == "Cosine")
                {
                    similarityMeasure[i] = SimilarityMatrics.FindCosineSimilarity(clusterCenter[i].GroupedDocument[0].VectorSpace, obj.VectorSpace);
                }
                else
                {
                    Wnlib.WNCommon.path = "C:\\Program Files\\WordNet\\3.0\\dict\\";
                    SentenceSimilarity semsim = new SentenceSimilarity();
                    similarityMeasure[i] = semsim.GetScore(clusterCenter[i].GroupedDocument[0].Content, obj.Content);
                }
            }

            int   index    = 0;
            float maxValue = similarityMeasure[0];

            for (int i = 0; i < similarityMeasure.Count(); i++)
            {
                //if document is similar assign the document to the lowest index cluster center to avoid the long loop
                if (similarityMeasure[i] > maxValue)
                {
                    maxValue = similarityMeasure[i];
                    index    = i;
                }
            }
            return(index);
        }
        //returns index of closest cluster centroid
        private static int FindClosestClusterCenter(List <Centroid> clusterCenter, DocumentVector obj)
        {
            float[] similarityMeasure = new float[clusterCenter.Count()];

            for (int i = 0; i < clusterCenter.Count(); i++)
            {
                similarityMeasure[i] = SimilarityMatrics.FindCosineSimilarity(clusterCenter[i].GroupedDocument[0].VectorSpace, obj.VectorSpace);
            }

            int   index    = 0;
            float maxValue = similarityMeasure[0];

            for (int i = 0; i < similarityMeasure.Count(); i++)
            {
                //if document is similar assign the document to the lowest index cluster center to avoid the long loop
                if (similarityMeasure[i] > maxValue)
                {
                    maxValue = similarityMeasure[i];
                    index    = i;
                }
            }
            return(index);
        }