Пример #1
0
        private List <List <Review> > FindFoldsFromTrainingData(int foldcount)
        {
            List <Review> reviews = ReadSentimentTrainingData.readFileAsReview("SentimentTrainingData.txt")
                                    .Where(r => r != null).ToList();
            List <List <Review> > folds = new List <List <Review> >();



            List <Review> negReviews   = reviews.Where(r => r.sentiment == Review.Sentiment.negative).ToList();
            List <Review> posReviews   = reviews.Where(r => r.sentiment == Review.Sentiment.positive).ToList();
            List <Review> blankReviews = reviews.Where(r => r.sentiment == Review.Sentiment.blank).ToList();
            int           res          = negReviews.Count + posReviews.Count;

            //neg
            int foldLengthNeg = (int)negReviews.Count / foldcount;

            for (int i = 0; i < foldcount; i++)
            {
                int foldIndex = i * foldLengthNeg;
                folds.Add(new List <Review>(negReviews.Skip(foldIndex).Take(foldLengthNeg)));
            }

            //pos
            int foldLengthPos = (int)posReviews.Count / foldcount;

            for (int i = 0; i < foldcount; i++)
            {
                int foldIndex = i * foldLengthPos;
                folds[i].AddRange(posReviews.Skip(foldIndex).Take(foldLengthPos));
            }
            return(folds);
        }
Пример #2
0
        private static void Train()
        {
            SentimentModel model = new SentimentModel(ReadSentimentTrainingData.readFileAsReview("SentimentTrainingData.txt"));

            FileStream brain = File.Create("brain.json");

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(brain))
            {
                file.Write(model.vocabulary.JSONSerialize());
            }
        }