private static void CategoryPartOnTrainSet() { TfIdf.LoadDb(); var testSet = DataLoad.AsrTestSet(DataLoad.FetchAsrDocuments); float correct = 0; float incorrect = 0; foreach (var document in testSet) { var(wordList, cat) = document.Item; var scores = new Dictionary <AsrIranCategories, double>(); foreach (var e in Enum.GetValues(typeof(AsrIranCategories))) { var en = (AsrIranCategories)e; scores.Add(en, 0); } Console.WriteLine("Calculating..."); foreach (var word in wordList) { foreach (var e in Enum.GetValues(typeof(AsrIranCategories))) { var categorie = (AsrIranCategories)e; scores[categorie] += TfIdf.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) + "======"); } }
private static void GetUserInputCategory() { TfIdf.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 <AsrIranCategories, double>(); foreach (var e in Enum.GetValues(typeof(AsrIranCategories))) { var en = (AsrIranCategories)e; scores.Add(en, 0); } Console.WriteLine("Calculating..."); foreach (var word in tokens) { foreach (var e in Enum.GetValues(typeof(AsrIranCategories))) { var categorie = (AsrIranCategories)e; scores[categorie] += TfIdf.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(); }