Beispiel #1
0
        public bool FindMoodMethod(string g)

        {
            string dataFilePath = Server.MapPath("~/MoodCsv/GenreList.txt");


            var dataTable = DataTable.New.ReadCsv(dataFilePath);

            List <string> x = dataTable.Rows.Select(row => row["Genre"]).ToList();

            double[] y = dataTable.Rows.Select(row => double.Parse(row["Mood"])).ToArray();

            var vocabulary = x.SelectMany(GetWords).Distinct().OrderBy(word => word).ToList();

            var problemBuilder = new TextClassificationProblemBuilder();

            var problem = problemBuilder.CreateProblem(x, y, vocabulary.ToList());

            const int C = 1;

            var model = new C_SVC(problem, KernelHelper.LinearKernel(), C);

            string GenreId = g;

            Dictionary <int, string> _predictionDictionary = new Dictionary <int, string> {
                { -2, "Scared" }, { -1, "Sad" }, { 1, "Laugh" }, { 2, "Romance" }
            };

            //maybe add do,while here
            //GenreId = movie.with_genres;
            var newX = TextClassificationProblemBuilder.CreateNode(GenreId, vocabulary);

            var predictedY = model.Predict(newX);

            if (predictedY == -2 || predictedY == -1 || predictedY == 1 || predictedY == 2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            // ViewBag.Mood = _predictionDictionary[-2];
        }
Beispiel #2
0
        public ActionResult FindMood(MovieList movie)
        {
            string dataFilePath = Server.MapPath("~/MoodCsv/GenreList.txt");


            var dataTable = DataTable.New.ReadCsv(dataFilePath);

            List <string> x = dataTable.Rows.Select(row => row["Genre"]).ToList();

            double[] y = dataTable.Rows.Select(row => double.Parse(row["Mood"])).ToArray();

            var vocabulary = x.SelectMany(GetWords).Distinct().OrderBy(word => word).ToList();

            var problemBuilder = new TextClassificationProblemBuilder();

            var problem = problemBuilder.CreateProblem(x, y, vocabulary.ToList());

            const int C = 1;

            var model = new C_SVC(problem, KernelHelper.LinearKernel(), C);

            string GenreId = movie.with_genres;

            Dictionary <int, string> _predictionDictionary = new Dictionary <int, string> {
                { -2, "Scared" }, { -1, "Sad" }, { 1, "Laugh" }, { 2, "Romance" }
            };

            //maybe add do,while here
            //GenreId = movie.with_genres;
            var newX = TextClassificationProblemBuilder.CreateNode(GenreId, vocabulary);

            var predictedY = model.Predict(newX);

            ViewBag.Mood        = _predictionDictionary[(int)predictedY];
            ViewBag.MovieTitle  = movie.title;
            ViewBag.MoviePoster = movie.poster_path;



            return(View());
        }