override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); if (args[0].IsList()) { // list reverse if (!args[1].IsVar() && !args[1].IsList()) { throw JasonityException.CreateWrongArgument(this, "last argument '" + args[1] + "' must be a list or a variable."); } return(un.Unifies(((IListTerm)args[0]).Reverse(), args[1])); } else { // string reverse if (!args[1].IsVar() && !args[1].IsString()) { throw JasonityException.CreateWrongArgument(this, "last argument '" + args[1] + "' must be a string or a variable."); } string vl = args [0].ToString(); if (args [0].IsString()) { vl = ((IStringTerm)args [0]).GetString(); } /*All this shit it's because c#'s StringBuilder doesn't have reverse method in */ char[] charArray = new StringBuilder(vl).ToString().ToCharArray(); Array.Reverse(charArray); /********************************************************************/ return(un.Unifies(new StringTermImpl(new string(charArray) /*new StringBuilder(vl).Reverse().ToString()*/), args[1])); } }
private Plan Transform2Plan(ITerm t) { Plan p = null; if (t.IsString()) { string sPlan = ((IStringTerm)t).GetString(); // remove quotes \" -> " StringBuilder sTemp = new StringBuilder(); for (int c = 0; c < sPlan.Length; c++) { if (sPlan.ElementAt(c) != '\\') { sTemp.Append(sPlan.ElementAt(c)); } } sPlan = sTemp.ToString(); p = AsSyntax.AsSyntax.ParsePlan(sPlan); } else if (t.GetType() == typeof(Plan)) { p = (Plan)t; } else { throw JasonityException.CreateWrongArgument(this, "The term '" + t + "' (" + t.GetType().Name + ") can not be used as a plan for .add_plan."); } if (p.GetLabel() != null && p.GetLabel().GetFunctor().StartsWith("l__")) { // if the label is automatic label, remove it p.DelLabel(); } return(p); }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (!args[0].IsAtom()) { throw JasonityException.CreateWrongArgument(this, "illocutionary force argument must be an atom"); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (!(args[0].GetType() == typeof(ILogicalFormula))) { throw JasonityException.CreateWrongArgument(this, "first argument must be a formula"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsAtom() & !args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "first argument must be an atom or variable."); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); //check number of arguments if (!args[0].IsString()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a string (the format)"); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsLiteral() && !args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a literal or variable"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!(args[0].GetType() == typeof(Atom))) { throw JasonityException.CreateWrongArgument(this, "first argument must be 'and' or 'or'."); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (!args[0].IsLiteral()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a literal"); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!(args[1].GetType() == typeof(ILogicalFormula))) { throw JasonityException.CreateWrongArgument(this, "second argument must be a formula"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (args.Length == 1 && !args[0].IsLiteral()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a literal"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!(args[0].IsList())) { throw JasonityException.CreateWrongArgument(this, "first argument must be a list"); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (args.Length > 0 && !args[0].IsLiteral() && !args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "first argument '" + args[0] + "' must be a literal or variable"); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Trigger te = null; try { te = Trigger.TryToGetTrigger(args[0]); } catch (ParseException e) {} if (te == null) { throw JasonityException.CreateWrongArgument(this, "first argument '" + args[0] + "' must follow the syntax of a trigger."); } IListTerm labels = new ListTermImpl(); IListTerm lt = new ListTermImpl(); IListTerm last = lt; if (!te.GetLiteral().HasSource()) { // the ts.relevantPlans requires a source to work properly te.SetLiteral(te.GetLiteral().ForceFullLiteralImpl()); te.GetLiteral().AddSource(new UnnamedVar()); } List <Option> rp = ts.RelevantPlans(te); if (rp != null) { foreach (Option opt in rp) { // remove sources (this IA is used for communication) Plan np = (Plan)opt.GetPlan().Clone(); if (np.GetLabel() != null) { np.GetLabel().DelSources(); } np.SetAsPlanTerm(true); np.MakeVarsAnnon(); last = last.Append(np); if (args.Length == 3) { labels.Add(np.GetLabel()); } } } bool ok = un.Unifies(lt, args[1]); // args[1] is a var; if (ok && args.Length == 3) { ok = un.Unifies(labels, args[2]); } return(ok); }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (!args[0].IsLiteral()) { if (!args[0].IsGround() && !args[0].IsRule()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a ground literal (or rule)."); } } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a variable."); } if (args.Length == 2 && !args[1].IsNumeric()) { throw JasonityException.CreateWrongArgument(this, "second argument must be a number."); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (args.Length > 1 && !args[1].IsString()) { throw JasonityException.CreateWrongArgument(this, "second argument must be a string"); } if (args.Length == 3 && !args[2].IsList()) { throw JasonityException.CreateWrongArgument(this, "third argument must be a list"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!(args[0].GetType() == typeof(ILogicalFormula))) { throw JasonityException.CreateWrongArgument(this, "first argument (test) must be a logical formula."); } if (!args[1].IsPlanBody()) { throw JasonityException.CreateWrongArgument(this, "second argument must be a plan body term."); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsNumeric() && !args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "the first argument should be numeric or a variable -- not '" + args[0] + "'."); } if (!args[1].IsList() && !args[1].IsString()) { throw JasonityException.CreateWrongArgument(this, "the second argument should be a list or string and not '" + args[1] + "'."); } }
// improve the check of the arguments to also check the type of the arguments override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsList() && !args[0].IsVar()) { throw JasonityException.CreateWrongArgument(this, "first argument must be a list or a variable"); } if (!args[1].IsList()) { throw JasonityException.CreateWrongArgument(this, "second argument must be a list"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[0].IsAtom() && !args[0].IsList() && !args[0].IsString()) { throw JasonityException.CreateWrongArgument(this, "TO parameter ('" + args[0] + "') must be an atom, a string or a list of receivers!"); } if (!args[1].IsAtom()) { throw JasonityException.CreateWrongArgument(this, "illocutionary force parameter ('" + args[1] + "') must be an atom!"); } }
override protected void CheckArguments(ITerm[] args) { base.CheckArguments(args); // check number of arguments if (!args[1].IsNumeric()) { throw JasonityException.CreateWrongArgument(this, "second parameter ('" + args[1] + "') must be a number!"); } if (!args[2].IsNumeric()) { throw JasonityException.CreateWrongArgument(this, "third parameter ('" + args[2] + "') must be a number!"); } if (args.Length == 4 && !args[3].IsNumeric()) { throw JasonityException.CreateWrongArgument(this, "fourth parameter ('" + args[3] + "') must be a number!"); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args); if (!(args[0].GetType() == typeof(ILogicalFormula))) { throw JasonityException.CreateWrongArgument(this, "first argument (test) must be a logical formula."); } if (!args[1].IsPlanBody()) { throw JasonityException.CreateWrongArgument(this, "second argument (test) must be a plan body term."); } if (args.Length == 3 && !args[2].IsPlanBody()) { throw JasonityException.CreateWrongArgument(this, "third argument (else) must be a plan body term."); } }
protected override void CheckArguments(ITerm[] args) { base.CheckArguments(args);// check number of arguments if (!args[0].IsList()) { throw JasonityException.CreateWrongArgument(this, "first argument '" + args[0] + "'is not a list."); } if (!args[1].IsList()) { throw JasonityException.CreateWrongArgument(this, "second argument '" + args[1] + "'is not a list."); } if (!args[2].IsVar() && !args[2].IsList()) { throw JasonityException.CreateWrongArgument(this, "last argument '" + args[2] + "'is not a list nor a variable."); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { if (args[0].IsList()) { if (!args[args.Length - 1].IsVar() && !args[args.Length - 1].IsList()) { throw new JasonityException("Last argument of concat '" + args[args.Length - 1] + "'is not a list nor a variable."); } IListTerm result = args[0].Clone() as IListTerm; for (int i = 1; i < args.Length - 1; i++) { if (!args[i].IsList()) { throw JasonityException.CreateWrongArgument(this, "arg[" + i + "] is not a list"); } result.Concat((IListTerm)args[i].Clone()); } return(un.Unifies(result, args[args.Length - 1])); } else { if (!args[args.Length - 1].IsVar() && !args[args.Length - 1].IsString()) { throw JasonityException.CreateWrongArgument(this, "Last argument '" + args[args.Length - 1] + "' is not a string nor a variable."); } string vl = args[0].ToString(); if (args[0].IsString()) { vl = ((IStringTerm)args[0]).GetString(); } StringBuilder sr = new StringBuilder(vl); for (int i = 0; i < args.Length - 1; i++) { vl = args[i].ToString(); if (args[i].IsString()) { vl = ((IStringTerm)args[i]).GetString(); } sr.Append(vl); } return(un.Unifies(new StringTermImpl(sr.ToString()), args[args.Length - 1])); } }