public string ProcessForm(string name, ArgumentTree args) { object result = QueueArena.CallResult(action, args.Children[name].Value, int.MaxValue, double.MaxValue); if (action is IHtmlOutputable) { ArgumentTree output = ((IHtmlOutputable)action).GetHtml(result); if (output != null && output.Value != null) { return(output.Value.ToString()); } } if (action.Output is IHtmlOutputable) { ArgumentTree output = ((IHtmlOutputable)action.Output).GetHtml(result); if (output != null && output.Value != null) { return(output.Value.ToString()); } } // Try to convert to something that is outputable object output3 = plugenv.ImmediateConvertTo(result, new HtmlOutputArgumentType(), 2, 200); if (output3 != null) { return(output3.ToString()); } else { return("Done."); } }
public override ArgumentTree GetHtmlForm(string name, ArgumentTree args, ArgumentTree invalidity) { StringBuilder output = new StringBuilder(); output.AppendLine(HtmlUtilities.SpnCl("handler", title)); output.AppendLine(HtmlUtilities.DivCl("desc", description)); output.AppendLine("<table>"); for (int ii = 0; ii < argnames.Length; ii++) { if (argtypes[ii] is IHtmlFormable) { if (argreqs[ii]) { output.AppendLine("<th>" + argtitles[ii] + "<font color=\"red\">*</font></th><td>" + ((IHtmlFormable)argtypes[ii]).GetHtmlForm(HtmlArgumentTree.AppendKey(name, argnames[ii]), args, invalidity) + "</td>"); } else { output.AppendLine("<th>" + argtitles[ii] + "</th><td>" + ((IHtmlFormable)argtypes[ii]).GetHtmlForm(HtmlArgumentTree.AppendKey(name, argnames[ii]), args, invalidity) + "</td>"); } } output.AppendLine("<td colspan=\"2\">" + argdescs[ii] + "</td>"); } output.AppendLine("</table>"); output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return(new ArgumentTree(output.ToString())); }
public static ArgumentTree LoadFromParams(NameValueCollection form) { Dictionary <string, ArgumentTree> children = new Dictionary <string, ArgumentTree>(); foreach (string key in form.AllKeys) { string value = form[key]; string prefix = key; Dictionary <string, ArgumentTree> addto = children; while (true) { string stripped; prefix = StripPrefix(prefix, out stripped); if (string.IsNullOrEmpty(stripped)) { break; } ArgumentTree grandchildren; if (!addto.TryGetValue(prefix, out grandchildren)) { addto[prefix] = grandchildren = new ArgumentTree(); } addto = grandchildren.Children; prefix = stripped; } addto[prefix] = new ArgumentTree(value); } return(new ArgumentTree(null, children)); }
public override ArgumentTree Handle(ArgumentTree arg) { object value; Phrase input = null; GrammarParser.ParaphraseOptions?opts = null; List <string> emph = null; double prob = 0; if (arg.TryGetValue("input", out value)) { input = (Phrase)value; } if (arg.TryGetValue("opts", out value)) { opts = (GrammarParser.ParaphraseOptions?)value; } if (arg.TryGetValue("emph", out value)) { emph = (List <string>)value; } if (arg.TryGetValue("prob", out value)) { prob = (double)value; } Phrase result = Handle(input, opts, emph, prob); return(new ArgumentTree(result)); }
public ArgumentTree IsValid(ArgumentTree value) { if (value.Value is bool) { return(null); } return(new ArgumentTree("not boolean")); }
public virtual ArgumentTree IsValid(ArgumentTree value) { if (type.IsInstanceOfType(value.Value)) { return(null); } return(new ArgumentTree("incorrect type")); }
public override ArgumentTree IsValid(ArgumentTree value) { if (!(value.Value is KeyValuePair <TKey, TValue>)) { return(new ArgumentTree("not key-value pair")); } return(null); }
public ArgumentTree GetHtmlForm(string name, ArgumentTree args, ArgumentTree invalidity) { string innerhtml = ""; if (inner is IHtmlFormable) { innerhtml = ((IHtmlFormable)inner).GetHtmlForm(name, args, invalidity).Value.ToString(); } return(new ArgumentTree("<th>" + label + "</th><td>" + innerhtml + "</td>")); }
public static string ToHtml(ArgumentTree tree) { if (tree.Value == null) { return(""); } else { return(tree.Value.ToString()); } }
public override bool Call(object value, IContinuation succ, IFailure fail) { try { ArgumentTree result = Handle((ArgumentTree)value); return(arena.Continue(succ, salience, result, fail)); } catch (Exception ex) { return(arena.Fail(fail, salience, ex.Message, succ)); } }
public ArgumentTree IsValid(ArgumentTree value) { foreach (object option in options) { if (option.Equals(value.Value)) { return(null); } } return(new ArgumentTree("option not found")); }
public ArgumentTree IsValid(ArgumentTree value) { foreach (IArgumentType type in types) { if (type.IsValid(value) == null) { return(null); } } return(new ArgumentTree("no types matched")); }
public override ArgumentTree Handle(ArgumentTree arg) { double one = 0, two = 0; object value; Console.WriteLine (arg); if (arg.TryGetValue("one", out value)) one = (double) value; if (arg.TryGetValue("two", out value)) two = (double) value; return new ArgumentTree(one + two); }
public ArgumentTree IsValid(ArgumentTree value) { foreach (IArgumentType type in types) { ArgumentTree invalidity = type.IsValid(value); if (invalidity != null) { return(invalidity); } } return(null); }
public virtual ArgumentTree GetHtmlForm(string name, ArgumentTree args, ArgumentTree invalidity) { StringBuilder output = new StringBuilder(); output.AppendLine(HtmlUtilities.SpnCl("handler", title)); output.AppendLine(HtmlUtilities.DivCl("desc", description)); if (Input is IHtmlFormable) output.AppendLine(((IHtmlFormable)Input).GetHtmlForm(name, args, invalidity).Value.ToString()); output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return new ArgumentTree(output.ToString()); }
public static object GetArgument(ArgumentTree tree, string name, object defval) { if (string.IsNullOrEmpty(name)) return tree.Value; string stripped; string key = StripPrefix(name, out stripped); ArgumentTree child; if (!tree.Children.TryGetValue(key, out child)) return defval; return HtmlArgumentTree.GetArgument(child, stripped, defval); }
public static string AllToHtml(ArgumentTree tree) { if (tree.Children.Count == 0) return ToHtml(tree); StringBuilder output = new StringBuilder(); output.Append(tree.Value); output.Append("<ul>"); foreach (KeyValuePair<string, ArgumentTree> kvp in tree.Children) output.Append("<li>" + kvp.Key + ": " + HtmlArgumentTree.AllToHtml(kvp.Value) + "</li>"); output.Append("</ul>"); return output.ToString(); }
public void Run() { Console.WriteLine("Running tests..."); ActionEnvironment actenv = new ActionEnvironment (this); actenv.AddAction (new String2Numeric ()); actenv.AddAction (new PlusHandler ()); ArgumentTree sumargs = new ArgumentTree (); sumargs.Add("one", (double) 3); sumargs.Add("two", "5"); object result = actenv.ImmediateConvertTo (sumargs, PlusHandler.SummationResultType, 10, 1000); Assert.AreEqual(result, 8.0); }
public override ArgumentTree IsValid(ArgumentTree value) { if (value.Value is string) { if (validater.IsMatch((string)value.Value)) { return(null); } else { return(new ArgumentTree("incorrect format")); } } return(new ArgumentTree("not string")); }
public virtual ArgumentTree GetHtmlForm(string name, ArgumentTree args, ArgumentTree invalidity) { StringBuilder output = new StringBuilder(); output.AppendLine(HtmlUtilities.SpnCl("handler", title)); output.AppendLine(HtmlUtilities.DivCl("desc", description)); if (Input is IHtmlFormable) { output.AppendLine(((IHtmlFormable)Input).GetHtmlForm(name, args, invalidity).Value.ToString()); } output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return(new ArgumentTree(output.ToString())); }
public ArgumentTree IsValid(ArgumentTree value) { if (value.Value is T) { if (minimum.CompareTo(value.Value) >= 0 && maximum.CompareTo(value.Value) <= 0) { return(null); } else { return(new ArgumentTree("out of range")); } } return(new ArgumentTree("not comparable")); }
public string GetForm(string name, ArgumentTree args, ArgumentTree invalidity) { if (action is IHtmlFormable) return ((IHtmlFormable) action).GetHtmlForm(name, args, invalidity).Value.ToString(); IArgumentType type = action.Input; StringBuilder output = new StringBuilder(); output.AppendLine("<table>"); if (type is IHtmlFormable) output.AppendLine(((IHtmlFormable)type).GetHtmlForm(name, args, invalidity).Value.ToString()); output.AppendLine("</table>"); output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return output.ToString(); }
public static object GetArgument(ArgumentTree tree, string name, object defval) { if (string.IsNullOrEmpty(name)) { return(tree.Value); } string stripped; string key = StripPrefix(name, out stripped); ArgumentTree child; if (!tree.Children.TryGetValue(key, out child)) { return(defval); } return(HtmlArgumentTree.GetArgument(child, stripped, defval)); }
public static string AllToHtml(ArgumentTree tree) { if (tree.Children.Count == 0) { return(ToHtml(tree)); } StringBuilder output = new StringBuilder(); output.Append(tree.Value); output.Append("<ul>"); foreach (KeyValuePair <string, ArgumentTree> kvp in tree.Children) { output.Append("<li>" + kvp.Key + ": " + HtmlArgumentTree.AllToHtml(kvp.Value) + "</li>"); } output.Append("</ul>"); return(output.ToString()); }
// Parapharse a phrase, with a given set of options public IParsedPhrase Paraphrase(IParsedPhrase phrase, ParaphraseOptions?options, List <string> emphasizes, double prob) { ArgumentTree args = new ArgumentTree(); args["input"] = phrase; args["prob"] = prob; if (options.HasValue) { args["opts"] = options.Value; } if (emphasizes != null) { args["emph"] = emphasizes; } ArgumentTree result = (ArgumentTree)plugenv.ImmediateConvertTo(args, GrammarParser.ParaphrasingResultType, 2, 1000 + 100 * phrase.Text.Length); return((IParsedPhrase)result.Value); }
public override ArgumentTree IsValid(ArgumentTree value) { if (!(value.Value is IDictionary <string, object>)) { return(new ArgumentTree("not argument dictionary")); } IDictionary <string, object> dict = (IDictionary <string, object>)value.Value; foreach (KeyValuePair <string, object> kvp in dict) { ArgumentTree invalidity = values[argmap[kvp.Key]].IsValid(new ArgumentTree(kvp.Value)); if (invalidity != null) { return(invalidity); } } return(null); }
public override ArgumentTree Handle(ArgumentTree arg) { object value; Phrase input = null; GrammarParser.ParaphraseOptions? opts = null; List<string> emph = null; double prob = 0; if (arg.TryGetValue("input", out value)) input = (Phrase) value; if (arg.TryGetValue("opts", out value)) opts = (GrammarParser.ParaphraseOptions?) value; if (arg.TryGetValue("emph", out value)) emph = (List<string>) value; if (arg.TryGetValue("prob", out value)) prob = (double) value; Phrase result = Handle(input, opts, emph, prob); return new ArgumentTree(result); }
public string GetForm(string name, ArgumentTree args, ArgumentTree invalidity) { if (action is IHtmlFormable) { return(((IHtmlFormable)action).GetHtmlForm(name, args, invalidity).Value.ToString()); } IArgumentType type = action.Input; StringBuilder output = new StringBuilder(); output.AppendLine("<table>"); if (type is IHtmlFormable) { output.AppendLine(((IHtmlFormable)type).GetHtmlForm(name, args, invalidity).Value.ToString()); } output.AppendLine("</table>"); output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return(output.ToString()); }
public bool CheckAction(IArena arena, double salience, object value, IFailure fail, params object[] args) { // params: object oldval, IContinuation succ if (aborter.IsAborted) { return(true); // abort! } ArgumentTree argtree = new ArgumentTree(args[0]); IContinuation succ = (IContinuation)args[1]; IAction action = (IAction)value; ArgumentTree result = action.Input.IsValid(argtree); if (result == null) { // abort the search-- we found an appropriate action! aborter.Abort(); return(arena.Call(action, salience, args[0], succ, fail)); } else { return(arena.Fail(fail, salience, "input type doesn't match", succ)); } }
public string ProcessForm(string name, ArgumentTree args) { object result = QueueArena.CallResult(action, args.Children[name].Value, int.MaxValue, double.MaxValue); if (action is IHtmlOutputable) { ArgumentTree output = ((IHtmlOutputable)action).GetHtml(result); if (output != null && output.Value != null) return output.Value.ToString(); } if (action.Output is IHtmlOutputable) { ArgumentTree output = ((IHtmlOutputable)action.Output).GetHtml(result); if (output != null && output.Value != null) return output.Value.ToString(); } // Try to convert to something that is outputable object output3 = actenv.ImmediateConvertTo(result, new HtmlOutputArgumentType(), 2, 200); if (output3 != null) return output3.ToString(); else return "Done."; }
public int CheckAction(IArena arena, double salience, object value, IFailure fail, params object[] args) { // params: object oldval, IContinuation succ if (aborter.IsAborted) return 1; // abort! ArgumentTree argtree = new ArgumentTree(args[0]); IContinuation succ = (IContinuation)args[1]; IAction action = (IAction)value; ArgumentTree result = action.Input.IsValid(argtree); if (result == null) { // abort the search-- we found an appropriate action! aborter.Abort(); return arena.Call(action, salience, args[0], succ, fail); } else return arena.Fail(fail, salience, "input type doesn't match", succ); }
// Parapharse a phrase, with a given set of options public IParsedPhrase Paraphrase(IParsedPhrase phrase, ParaphraseOptions? options, List<string> emphasizes, double prob) { ArgumentTree args = new ArgumentTree(); args["input"] = phrase; args["prob"] = prob; if (options.HasValue) args["opts"] = options.Value; if (emphasizes != null) args["emph"] = emphasizes; ArgumentTree result = (ArgumentTree)plugenv.ImmediateConvertTo(args, GrammarParser.ParaphrasingResultType, 2, 1000 + 100 * phrase.Text.Length); return (IParsedPhrase) result.Value; }
public override ArgumentTree GetHtmlForm(string name, ArgumentTree args, ArgumentTree invalidity) { StringBuilder output = new StringBuilder(); output.AppendLine(HtmlUtilities.SpnCl("handler", title)); output.AppendLine(HtmlUtilities.DivCl("desc", description)); output.AppendLine("<table>"); for (int ii = 0; ii < argnames.Length; ii++) { if (argtypes[ii] is IHtmlFormable) { if (argreqs[ii]) output.AppendLine("<th>" + argtitles[ii] + "<font color=\"red\">*</font></th><td>" + ((IHtmlFormable)argtypes[ii]).GetHtmlForm(HtmlArgumentTree.AppendKey(name, argnames[ii]), args, invalidity) + "</td>"); else output.AppendLine("<th>" + argtitles[ii] + "</th><td>" + ((IHtmlFormable)argtypes[ii]).GetHtmlForm(HtmlArgumentTree.AppendKey(name, argnames[ii]), args, invalidity) + "</td>"); } output.AppendLine("<td colspan=\"2\">" + argdescs[ii] + "</td>"); } output.AppendLine("</table>"); output.AppendLine(HtmlUtilities.Input("submit", "submit", "Process")); return new ArgumentTree(output.ToString()); }
public abstract ArgumentTree Handle(ArgumentTree args);
public static string ToHtml(ArgumentTree tree) { if (tree.Value == null) return ""; else return tree.Value.ToString(); }
public static ArgumentTree LoadFromParams(NameValueCollection form) { Dictionary<string, ArgumentTree> children = new Dictionary<string, ArgumentTree>(); foreach (string key in form.AllKeys) { string value = form[key]; string prefix = key; Dictionary<string, ArgumentTree> addto = children; while (true) { string stripped; prefix = StripPrefix(prefix, out stripped); if (string.IsNullOrEmpty(stripped)) break; ArgumentTree grandchildren; if (!addto.TryGetValue(prefix, out grandchildren)) addto[prefix] = grandchildren = new ArgumentTree(); addto = grandchildren.Children; prefix = stripped; } addto[prefix] = new ArgumentTree(value); } return new ArgumentTree(null, children); }
public ArgumentTree TestForm(string name, ArgumentTree args) { // Are all inputs valid? return action.Input.IsValid(args.Children[name]); }