public void AddCorrection(MisspelledWord error) { string context = ExportContext ? ";" + error.GetLeftContext().ToStringRepresentation() + ";" + error.GetRightContext().ToStringRepresentation() : ""; writer.WriteLine(error.WrongWord + ";" + error.CorrectWord + ";" + error.RevokedByLm.ToString() + context); if (!String.IsNullOrEmpty(error.CorrectWord)) { writerCorrected.WriteLine(error.WrongWord + ";" + error.CorrectWord + ";" + Math.Round(error.Accuracy,1).ToString() + ";" + error.CorrectedBy.ToString() +";" + error.IsName().ToString()); } }
public LanguageModelEvaluation EvaluateCandidates(MisspelledWord word, Dictionary<string, double> candidates) { foundInNgrams = false; List<string> leftContext = word.GetLeftContext(); NgramType type = this.dictionary.GetHighestAvailableNgramCollection(leftContext.Count); Dictionary<string, double> probability = new Dictionary<string, double>(); string[] lcArray = this.GetLeftContext(leftContext, type); NgramEvaluation evaluation; foreach (KeyValuePair<string, double> option in candidates) { lcArray[leftContext.Count - 1] = option.Key.Contains(' ') ? option.Key.Split(space).First() : option.Key; evaluation = this.dictionary.GetNgramCollection(type).GetProbability(lcArray); probability.Add(option.Key, evaluation.Probability); if (!foundInNgrams && evaluation.Occurence > 0) { foundInNgrams = true; } } List<string> rightContext = word.GetRightContext(); NgramType secType = this.dictionary.GetHighestAvailableNgramCollection(rightContext.Count); if (type == NgramType.Unigram && type == NgramType.Unigram) { // do nothing } else { string[] rcArray = this.GetRightContext(rightContext, secType); foreach (KeyValuePair<string, double> option in candidates) { rcArray[0] = option.Key.Contains(' ') ? option.Key.Split(space).Last() : option.Key; evaluation = this.dictionary.GetNgramCollection(secType).GetProbability(rcArray); probability[option.Key] *= evaluation.Probability; if (!foundInNgrams && evaluation.Occurence > 0) { foundInNgrams = true; } } } return new LanguageModelEvaluation(probability, foundInNgrams); }