public override bool Match(object check, Context context, IContinuation succ, IFailure fail) { if (check is IParsedPhrase) { IParsedPhrase phrase = (IParsedPhrase)check; if (phrase.Part == "=P") { // Match against each element foreach (IParsedPhrase constituent in phrase.Branches) { Context child = new Context(context, context.Contents); child.Map["$check"] = constituent; ContinueToCallAgent.Instantiate(new ClauseVariable(salience, tagger, parser), child, succ, fail); } } else if (phrase.Part == "FRAG" || phrase.Part == "S" || phrase.Part == "SBARQ") { GroupPhrase groupPhrase = new GroupPhrase(phrase); IParsedPhrase last = groupPhrase.GetBranch(groupPhrase.Count - 1); if (last.Part == "." || last.Part == "?" || last.Part == "!" || last.Part == ";") { phrase = new GroupPhrase("?", groupPhrase.GetRange(0)); } // Set up propogate-on-clear ContinueToCallAgent cont = CallAgentWrapper.MakeContinuation(PropogateOnClear, succ, 100.0, 4, 10, "%clause", phrase); // Do a match using my contents Matcher.MatchAgainst(salience, context, phrase, new List <IParsedPhrase>(), cont, fail); } } return(true); }
public override bool Match(object check, Context context, IContinuation succ, IFailure fail) { if (check is IParsedPhrase && ((IParsedPhrase)check).IsLeaf) { return(true); } // Match against each element foreach (IParsedPhrase constituent in ((IParsedPhrase)check).Branches) { // Set up propogate-on-clear ContinueToCallAgent cont = CallAgentWrapper.MakeContinuation(PropogateOnClear, succ, 100.0, 4, 10, "%phrase", check); if (variable == null || variable.IsMatch(constituent)) { Matcher.MatchAgainst(salience, context, constituent, new List <IParsedPhrase>(), cont, fail); } if (!(constituent.IsLeaf)) { Context child = new Context(context, context.Contents); child.Map["$check"] = constituent; ContinueToCallAgent.Instantiate(new PhraseVariable(salience, variable, tagger, parser), child, cont, fail); } } return(true); }
public override bool Produce(Context context, IContinuation succ, IFailure fail) { // Evaluate all children ContinueToCallAgent cont = CallAgentWrapper.MakeContinuation(ConstructSentence, succ, 100.0, 10, 10); ContinuationAppender appender = new ContinuationAppender(context, cont); Evaluator eval = new Evaluator(salience, ArgumentMode.ManyArguments, appender.AsIndex(0), appender.AsIndex(1), true); eval.Continue(context, fail); return(true); }
public override bool Match(object check, Context context, IContinuation succ, IFailure fail) { if (check is IParsedPhrase && ((IParsedPhrase)check).Part == "PRN") { // Set up propogate-on-clear ContinueToCallAgent cont = CallAgentWrapper.MakeContinuation(PropogateOnClear, succ, 100.0, 4, 10, "%paren", check); // Do a match using my contents Matcher.MatchAgainst(salience, context, (IParsedPhrase)check, new List <IParsedPhrase>(), cont, fail); return(true); } else { fail.Fail("check is not parenthetical", succ); return(true); } }