Exemplo n.º 1
0
        private static void Stemming_Setup()
        {
            stemmer     = new Stemming();
            moodList    = new MoodListing().BingLiuMoodList;
            bingliuTrie = new Trie <MoodItem>();
            var bingLiuMoodList = new List <MoodItem>();

            foreach (var item in moodList)
            {
                var stemmed = stemmer.Stem(item.Word);//removed stemming
                bingLiuMoodList.Add(new MoodItem {
                    Word = item.Word, Value = item.Value
                });
            }

            bingLiuMoodList = bingLiuMoodList.Distinct().ToList();

            foreach (var item in bingLiuMoodList)
            {
                bingliuTrie.Add(" " + item.Word + " ", item);
            }

            bingliuTrie.Build();

            drummondMoodList = new MoodListing().DrummondMoodList;
            drummondTrie     = new Trie <MoodValue>();

            foreach (var item in drummondMoodList)
            {
                var stemmed = stemmer.Stem(item.Word);
                drummondTrie.Add(stemmed, item.Value);
            }

            drummondTrie.Build();
        }
Exemplo n.º 2
0
        private static void DrummondsGenerate()
        {
            var stemmer = new Stemming();

            string line;
            var    moods = new List <MoodItem>();

            using (var reader = File.OpenText("wordlist.txt"))
            {
                string word;
                string category;
                while ((line = reader.ReadLine()) != null)
                {
                    var split = line.Split(',');
                    if (split.Length >= 2)
                    {
                        double weight = 1;
                        if (split.Length > 2)
                        {
                            weight = double.Parse(split[2]);
                        }

                        moods.Add(new MoodItem
                        {
                            Word  = stemmer.Stem(split[0].ToLower()),
                            Value = new MoodValue {
                                Category = split[1], Weight = weight
                            }
                        });
                    }
                }
            }


            StreamWriter file2 = new StreamWriter("c:\\code\\files.txt", true);

            foreach (var mood in moods)
            {
                file2.WriteLine("new MoodItem{   Word = \"" + mood.Word + "\", Value = new MoodValue { Category =\"" + mood.Value.Category + "\", Weight = " + mood.Value.Weight + " } },");
            }

            file2.Close();
        }
Exemplo n.º 3
0
        public static string stem(string input)
        {
            string[]      terms = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            List <string> list  = new List <string>();

            foreach (string term in terms)
            {
                Stemming ss = new Stemming();
                string   s  = ss.Stem(term);
                list.Add(s);
            }
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < list.Count(); i++)
            {
                if (i != 0)
                {
                    sb.Append(" ");
                }
                sb.Append(list[i]);
            }

            return(sb.ToString());
        }