static void Phase1() { List <Word> words2 = ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "training_dataset.txt"); words2.AddRange(ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "testing_dataset.txt")); loadTests(words2); // while (true) // { Console.WriteLine("Enter a seed word:"); string searchNext = Console.ReadLine(); Console.WriteLine("Enter how many words to generate:"); int genNum = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); for (int n = 0; n < genNum; n++) { WordAndPercentage answer = predictNextWord(searchNext); searchNext = answer.word; Console.Write(searchNext + " "); } }
/* * static WordAndPercentage predictNextWord(string word) * { * if (wordAndNextWords.ContainsKey(word)) * { * string topWord = ""; * int times = 0; * int total = 0; * foreach(KeyValuePair<string, int> pair in wordAndNextWords[word]) * { * if(pair.Value > times) * { * topWord = pair.Key; * times = pair.Value; * } * total++; * } * double percent = (double)times / (double)total; * return new WordAndPercentage(topWord, percent); * } * return new WordAndPercentage("word isn't in database", 100); * } */ static WordAndPercentage predictNextWord(string word) { WordAndPercentage w = getTopWord(word); if (w == null) { return(new WordAndPercentage("Word does not exist", 0)); } return(w); }
public static void printWordPredictorMatrix(Dictionary <string, List <WordAndPercentage> > model, List <string> myDictionary) { StringBuilder output = new StringBuilder(); int max = 50; for (int row = 0; row < myDictionary.Count; row++) { string from = myDictionary[row]; output.Append(from.escape() + ","); for (int col = 0; col < myDictionary.Count; col++) { string to = myDictionary[col]; WordAndPercentage wpTo = null; if (!model.ContainsKey(from) || (wpTo = model[from].find(to)) == null) { ; } else { output.Append((wpTo.word + "---" + wpTo.percent.ToString()).escape() + ","); } if (col > max) { break; } } output.AppendLine(); //System.IO.File.AppendAllText("predictor.csv", output.ToString()); //output.Clear(); if (row > max) { break; } } System.IO.File.WriteAllText("predictor.csv", output.ToString()); }