Ejemplo n.º 1
0
        public static void Train(string train, string test, string root)
        {
            ITokenizer      tokenizer      = new MSRA.NLC.Common.NLP.Twitter.TwitterTokenizer();
            IWordNormalizer wordNormalizer = null;

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

            Train_Test(train, test, textConverter);
        }
Ejemplo n.º 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);
        }