Esempio n. 1
0
        private static void TestClassifier(string input)
        {
            Index positiveSentiment = Index.CreateMemoryIndex();
            Index negativeSentiment = Index.CreateMemoryIndex();

            // train the indexes
            positiveSentiment.Add(Entry.FromString("this is awesome?"));
            positiveSentiment.Add(Entry.FromString("i really enjoyed this program"));
            positiveSentiment.Add(Entry.FromString("the new event was GREAT!"));
            positiveSentiment.Add(Entry.FromString("I thought that new phone was ideal, some of the key features blew my mind!"));
            positiveSentiment.Add(Entry.FromString("OK, that's a super idea, lets do it!"));

            negativeSentiment.Add(Entry.FromString("That was terrible! What were you thinking?"));
            negativeSentiment.Add(Entry.FromString("OMG! No way! I can't believe that! Terrible!"));
            negativeSentiment.Add(Entry.FromString("I just got this new phone but wish I hadn't.  It's pretty crap!"));
            negativeSentiment.Add(Entry.FromString("There's no way I'd sign up with them.  Their customer service is terrible!"));
            negativeSentiment.Add(Entry.FromString("That's just rubbish!!!"));

            Analyzer analyzer = new Analyzer();

            Console.WriteLine("Classifying: " + input);

            CategorizationResult result = analyzer.Categorize(Entry.FromString(input), positiveSentiment, negativeSentiment);

            switch (result)
            {
            case CategorizationResult.First:
                Console.WriteLine("Positive sentiment");
                break;

            case CategorizationResult.Second:
                Console.WriteLine("Negative sentiment");
                break;

            case CategorizationResult.Undetermined:
                Console.WriteLine("Undecided");
                break;
            }
        }
Esempio n. 2
0
        public static BayesAnalyzer GetTrained(string dataSet)
        {
            var positive = Index.CreateMemoryIndex();
            var negative = Index.CreateMemoryIndex();


            var ms = new MemoryStream();

            using (var fs = GenerateStreamFromString(dataSet))
            {
                using (var sr = new StreamReader(fs))
                {
                    sr.ReadLine();

                    string line = null;

                    while ((line = sr.ReadLine()) != null)
                    {
                        var data = line.Split(new[] { ',' });

                        switch (data[0].Trim())
                        {
                        case "Pos":
                            positive.Add(Entry.FromString(data[1].Trim()));
                            break;

                        case "Neg":
                            negative.Add(Entry.FromString(data[1].Trim()));
                            break;
                        }
                    }
                }
            }

            return(new BayesAnalyzer(positive, negative));
        }