static void Test(string path, string file, ITextConverter textConverter)
        {
            string root = Path.Combine(Constants.SPP_RootPath, @"model\sentiment\learning\");

            string[] dirs = Directory.GetDirectories(root);
            int      max  = 0;

            foreach (string dir in dirs)
            {
                string name = Path.GetFileName(dir);
                bool   run  = true;
                foreach (char ch in name)
                {
                    if (!char.IsDigit(ch))
                    {
                        run = false;
                        break;
                    }
                }

                if (!run)
                {
                    continue;
                }

                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("C VALUE AT: {0}", c_coll[Int32.Parse(name)]);
                Console.ResetColor();

                SECoreImpl      learnCoreImpl = CreateLearningCoreImpl(path, Int32.Parse(name));
                ISemanticTagger lexiconTagger = new LexiconSentimentTagger(textConverter.Tokenizer);
                SentimentEngine engine        = new SentimentEngine(textConverter, lexiconTagger, learnCoreImpl);

                SentimentEvaluator evaluator = new SentimentEvaluator(engine);

                evaluator.Evaluate(file, true, true);

                if (++max >= c_coll.Length)
                {
                    break;
                }
            }
        }
Example #2
0
        public SentimentAnalyzer()
        {
            Console.WriteLine("[LOG] /BEGIN AT {0}\n", DateTime.Now.ToString());

            // Please copy the models from <code>\\msranlcqa02\social\root\model</code> and set
            // the root path to your local copy.
            //Constants.SPP_RootPath = @"../../../../SentimentAnalyzeRoot";
            Constants.SPP_RootPath = @"Utils\\SentimentAnalysis";

            // train a model and test it
            // NOTE: SET THIS FLAG AS TRUE IF YOU WANT TO TRAIN YOUR OWN MODEL!
            bool train_test_flag = false;

            if (train_test_flag)
            {
                // Train and test data from SemEval 2013 <code>\\msranlcqa02\social\root\data</code>
                string train = Path.Combine(Constants.SPP_RootPath, @"data\train");
                string test  = Path.Combine(Constants.SPP_RootPath, @"data\test");
                SentimentLearner.Train(train, test, Constants.SPP_RootPath);
                return;
            }

            ITokenizer      tokenizer      = new TwitterTokenizer();
            IWordNormalizer wordNormalizer = new TweetWordNormalizer();
            ITextConverter  textConverter  = new BaseTextConverter(tokenizer, null, null, wordNormalizer);

            classifier = "LIBLINEAER";
            //classifier = "svm_light";

            ISemanticTagger lexiconTagger = new LexiconSentimentTagger(tokenizer);

            SECoreImpl coreImpl = CreateLearningCoreImpl(Constants.SPP_RootPath);

            _engine = new SentimentEngine(textConverter, lexiconTagger, coreImpl);

            Console.WriteLine("\n[LOG] /END AT {0}\n", DateTime.Now.ToString());

            string testFilePath = Path.Combine(Constants.SPP_RootPath, @"data\test");

            //testFilePath = @"D:\users\fuwei\Sentiment\root\data\carol\full";
            Test(testFilePath, _engine);
        }
Example #3
0
        static void Test(string file, SentimentEngine engine)
        {
            SentimentEvaluator evaluator = new SentimentEvaluator(engine);

            evaluator.Evaluate(file);
        }