//private static readonly KeywordExampleComparer Cmp = new KeywordExampleComparer();

        public KeywordGroup(string keyword)
        {
            SelectedKeywords = new KeywordExample();
            SelectedKeywords.AddKeyword(keyword);
            ContainedKeywords = new Dictionary <string, int>();
            ContainedMembers  = new List <ClaimableKeywordExample>();
        }
 public double CalculateSimilarityScore(KeywordExample example)
 {
     if (example.Count == 0)
     {
         return(0);
     }
     return(SelectedKeywords.CountSimilar(example) / (double)example.Count);
 }
Ejemplo n.º 3
0
        public KeywordExample Copy()
        {
            KeywordExample ret = new KeywordExample();

            foreach (string keyword in this)
            {
                ret.AddKeyword(keyword);
            }
            return(ret);
        }
Ejemplo n.º 4
0
        /**<summary>Calculates the similarity for the provided example to every one of the groups contained in this clusterer and returns the top n.</summary>*/
        public List <int> PredictTopNSimilarGroups(KeywordExample exampleIn, int n)
        {
            List <int> similarityScores = PredictGroupSimilarity(exampleIn);

            if (similarityScores.Count < n)
            {
                for (int i = similarityScores.Count; i < n; i++)
                {
                    similarityScores.Add(0);
                }
            }
            return(similarityScores.GetRange(0, n));
        }
Ejemplo n.º 5
0
        public int CountSimilar(KeywordExample other)
        {
            int ret = 0;

            foreach (string x in other.ModifiableKeywords)
            {
                if (ModifiableKeywords.Contains(x))
                {
                    ret++;
                }
            }
            return(ret);
        }
Ejemplo n.º 6
0
        /**<summary>Calculates the similarity for the provided example to every one of the groups contained in this clusterer.</summary>*/
        public List <int> PredictGroupSimilarity(KeywordExample exampleIn)
        {
            SortedDictionary <double, List <int> > similarityScores = new SortedDictionary <double, List <int> >();

            for (int i = 0; i < ContainedGroups.Count; i++)
            {
                double similarityScore = ContainedGroups[i].CalculateSimilarityScore(exampleIn);
                if (similarityScore != 0)
                {
                    if (!similarityScores.ContainsKey(similarityScore))
                    {
                        similarityScores.Add(similarityScore, new List <int> {
                            i + 1
                        });
                    }
                    else
                    {
                        similarityScores[similarityScore].Add(i + 1);
                    }
                }
            }
            if (similarityScores.Count == 0)
            {
                similarityScores.Add(0, new List <int> {
                    0
                });
            }
            List <int> sortedGroups = new List <int>();

            foreach (KeyValuePair <double, List <int> > simScore in similarityScores)
            {
                foreach (int group in simScore.Value)
                {
                    sortedGroups.Add(group);
                }
            }
            return(sortedGroups);
        }