Ejemplo n.º 1
0
        private static void AgencyPartOnTrainSet()
        {
            AgencyTfIdf.LoadDb();

            var testSet1 = DataLoad.FormalTestSet(DataLoad.FetchFarsFormalForm);
            var testSet2 = DataLoad.FormalTestSet(DataLoad.FetchAsrFormalForm);
            var testSet  = testSet1.Concat(testSet2);

            float correct   = 0;
            float incorrect = 0;

            foreach (var document in testSet)
            {
                var(wordList, cat) = document.Item;

                var scores = new Dictionary <NewsAgency, double>();

                foreach (var e in Enum.GetValues(typeof(NewsAgency)))
                {
                    var en = (NewsAgency)e;
                    scores.Add(en, 0);
                }

                Console.WriteLine("Calculating...");
                foreach (var word in wordList)
                {
                    foreach (var e in Enum.GetValues(typeof(NewsAgency)))
                    {
                        var categorie = (NewsAgency)e;
                        scores[categorie] += AgencyTfIdf.CalculateTfIdf(word, categorie);
                    }
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Correct Class: " + cat);
                var orderedScore = scores.OrderByDescending(x => x.Value);
                if (orderedScore.First().Key != cat)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    incorrect++;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    correct++;
                }

                foreach (var item in orderedScore.Take(5))
                {
                    Console.WriteLine($"{item.Key} = {item.Value}");
                    Console.ResetColor();
                }
                Console.WriteLine();
                Console.WriteLine();

                Console.WriteLine("===== ACURACY  : " + correct * 100 / (correct + incorrect) + "======");
            }
        }
Ejemplo n.º 2
0
        private static void GetUserInputAgency()
        {
            AgencyTfIdf.LoadDb();

            Console.Write("Enter file path: ");
            var path = Console.ReadLine();

            Console.WriteLine();
            var text = File.ReadAllText(path);

            Console.WriteLine(text);
            var tokens = DataCleanser.CleanseUserInput(text);

            var scores = new Dictionary <NewsAgency, double>();

            foreach (var e in Enum.GetValues(typeof(NewsAgency)))
            {
                var en = (NewsAgency)e;
                scores.Add(en, 0);
            }

            Console.WriteLine("Calculating...");
            foreach (var word in tokens)
            {
                foreach (var e in Enum.GetValues(typeof(NewsAgency)))
                {
                    var categorie = (NewsAgency)e;
                    scores[categorie] += AgencyTfIdf.CalculateTfIdf(word, categorie);
                }
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Blue;
            var orderedScore = scores.OrderByDescending(x => x.Value);

            foreach (var item in orderedScore)
            {
                Console.WriteLine($"{item.Key} = {item.Value}");
            }
            Console.ResetColor();
            Console.WriteLine();
            Console.WriteLine();
        }