public static float run(User user) { var writeRight = new WriteRight(); var evaluation = new ExperimentEvaluation(); /* Train the engine */ User trainSet = user.GetTopKTweetsTrainSet(trainSetSize); while (trainSet.HasNext()) { var ch = trainSet.ConsumeNext(); writeRight.CharacterTyped(ch); } writeRight.CharacterTyped(' '); User testSet = user.GetTestSet(); var totalChars = 0; var guessedChars = 0; writeRight.InTestMode(); while (testSet.HasNext()) { var ch = testSet.ConsumeNext(); writeRight.CharacterTyped(ch); var next = Char.ToLower(testSet.PeekNext()); var predictions = writeRight.GetTopKPredictions(); if (writeRight.IsValidCharacter(next) == false || writeRight.IsWordSeparator(next)) { continue; } if (predictions == null || predictions.ContainsKey(next) == false) { writeRight.BadPrediction(); totalChars++; evaluation.Miss(); } else if (writeRight.IsWordSeparator(next) == false) { guessedChars++; totalChars++; evaluation.Hit(predictions.Count); } } return(evaluation.GetPrecission()); }
public static float run(int k) { var dataSet = DataSet.GetInstance(); float hitRatio = 0.0f; float precission = 0.0f; memory = 0; foreach (User user in dataSet.Users) { var writeRight = new WriteRight(); var evaluation = new ExperimentEvaluation(); writeRight.LoadDB(""); /* Train the engine */ User trainSet = user.GetTopKTweetsTrainSet(k); while (trainSet.HasNext()) { var ch = trainSet.ConsumeNext(); writeRight.CharacterTyped(ch); } writeRight.CharacterTyped(' '); User testSet = user.GetTestSet(); var totalChars = 0; var guessedChars = 0; writeRight.InTestMode(); while (testSet.HasNext()) { var ch = testSet.ConsumeNext(); writeRight.CharacterTyped(ch); var next = Char.ToLower(testSet.PeekNext()); var predictions = writeRight.GetTopKPredictions(); if (writeRight.IsValidCharacter(next) == false || writeRight.IsWordSeparator(next)) { continue; } if (predictions == null || predictions.ContainsKey(next) == false) { writeRight.BadPrediction(); totalChars++; evaluation.Miss(); } else if (writeRight.IsWordSeparator(next) == false) { guessedChars++; totalChars++; evaluation.Hit(predictions.Count); } } hitRatio += (float)guessedChars / (float)totalChars; precission += evaluation.GetPrecission(); memory += writeRight.GetKnowledgeSize(); } /* * this.hitRatioWriter.WriteLine (hitRatio / dataSet.Users.Count); * this.evalWriter.WriteLine (evaluationScore / dataSet.Users.Count); * * this.hitRatioWriter.Flush (); * this.evalWriter.Flush (); */ memory = memory / dataSet.Users.Count; return((float)precission / dataSet.Users.Count); }
public static void Main(string[] args) { var writeRight = new WriteRight(); writeRight.LoadDB(WriteRightDb); var buffer = ""; var character = '\0'; var foregroundColor = Console.ForegroundColor; var topKPredictions = new Dictionary<char, float>(); do { var key = Console.ReadKey(); character = key.KeyChar; if (character == ShellExit) { break; } if (writeRight.IsValidCharacter(character) == false) { continue; } writeRight.CharacterTyped(character); buffer += character; Console.Clear(); Console.WriteLine(buffer); topKPredictions = writeRight.GetTopKPredictions(); if (writeRight.IsUnknownWord()) { Console.WriteLine("Unknown word!"); continue; } Console.ForegroundColor = ConsoleColor.Green; foreach (var prediction in topKPredictions) { Console.WriteLine("P(" + prediction.Key + ") = " + prediction.Value); } Console.WriteLine("\n"); Console.ForegroundColor = ConsoleColor.Red; var predictions = writeRight.GetPredictions(); foreach (var prediction in predictions) { if (topKPredictions.ContainsKey(prediction.Key) == false) { Console.WriteLine("P(" + prediction.Key + ") = " + prediction.Value); } } Console.ForegroundColor = foregroundColor; } while (true); writeRight.SaveDB(WriteRightDb); }
public static float run(int k) { var dataSet = DataSet.GetInstance (); float hitRatio = 0.0f; float precission = 0.0f; memory = 0; foreach (User user in dataSet.Users) { var writeRight = new WriteRight(); var evaluation = new ExperimentEvaluation (); writeRight.LoadDB (""); /* Train the engine */ User trainSet = user.GetTopKTweetsTrainSet (k); while (trainSet.HasNext ()) { var ch = trainSet.ConsumeNext (); writeRight.CharacterTyped (ch); } writeRight.CharacterTyped (' '); User testSet = user.GetTestSet (); var totalChars = 0; var guessedChars = 0; writeRight.InTestMode (); while (testSet.HasNext ()) { var ch = testSet.ConsumeNext (); writeRight.CharacterTyped (ch); var next = Char.ToLower (testSet.PeekNext ()); var predictions = writeRight.GetTopKPredictions (); if (writeRight.IsValidCharacter (next) == false || writeRight.IsWordSeparator (next)) { continue; } if (predictions == null || predictions.ContainsKey (next) == false) { writeRight.BadPrediction (); totalChars++; evaluation.Miss (); } else if (writeRight.IsWordSeparator (next) == false) { guessedChars++; totalChars++; evaluation.Hit (predictions.Count); } } hitRatio += (float)guessedChars / (float)totalChars; precission += evaluation.GetPrecission (); memory += writeRight.GetKnowledgeSize (); } /* this.hitRatioWriter.WriteLine (hitRatio / dataSet.Users.Count); this.evalWriter.WriteLine (evaluationScore / dataSet.Users.Count); this.hitRatioWriter.Flush (); this.evalWriter.Flush (); */ memory = memory / dataSet.Users.Count; return (float) precission / dataSet.Users.Count; }