public override bool CallRescue(Coderack coderack, IParsedPhrase input, PatternTemplateSource patternTemplateSource, string reason, IContinuation skip, IContinuation succ, IFailure fail) { List <string> words = GroupPhrase.PhraseToTexts(input); bool changed = false; List <string> corrected = new List <string>(); foreach (string word in words) { string correct = comparer.GetCorrects(word)[0]; if (correct.ToLower() != word.ToLower()) { changed = true; } corrected.Add(correct); } if (changed) { IParsedPhrase correct = parser.Parse(StringUtilities.JoinWords(corrected)); IFailure fallfail = fallback.MakeFailure(input, patternTemplateSource, succ, fail, coderack); patternTemplateSource.Generate(coderack, correct, succ, fallfail, weight); return(true); } else { return(fallback.CallRescue(coderack, input, patternTemplateSource, reason, skip, succ, fail)); } }
protected bool MatchNextTemplate() { if (remainingDicta.Count == 0) { return(false); } PatternTemplateSource dictum = remainingDicta.Dequeue(); if (dictum.Pattern.Contents[0].Name == "%sentence") { IFailure fail = tryToRescueMatch.MakeFailure(inputs[inputIndex], dictum, this, this, coderack); dictum.Generate(coderack, inputs[inputIndex], this, fail, weight); return(true); } else if (dictum.Pattern.Contents[0].Name == "%sentences") { int count = 1; foreach (IContent content in dictum.Pattern.Contents) { if (content.Name == "/") { count++; } } GroupPhrase groupPhrase = new GroupPhrase("=P", inputs.GetRange(inputIndex, count)); IFailure fail = tryToRescueMatch.MakeFailure(groupPhrase, dictum, this, this, coderack); dictum.Generate(coderack, groupPhrase, this, fail, weight); return(true); } else { receiver.Receive(String.Format("Template starting with {0} not available in serial mode.", dictum.Pattern.Contents[0].Name), dictum); return(MatchNextTemplate()); } }