public void AddErrorAnnot(ITerm t) { if (errorAnnots == null) { errorAnnots = new ListTermImpl(); } errorAnnots.Append(t); }
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); }
public static IListTerm CreateList(List <ITerm> terms) { IListTerm l = new ListTermImpl(); IListTerm tail = l; foreach (ITerm t in terms) { tail = tail.Append((ITerm)t.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... } return(l); }
public static IListTerm CreateList(params ITerm[] terms) { IListTerm l = new ListTermImpl(); IListTerm tail = l; foreach (ITerm t in terms) { tail = tail.Append(t); } return(l); }
// copy the set to a new list private IListTerm SetToList(ISet <ITerm> set) { IListTerm result = new ListTermImpl(); IListTerm tail = result; foreach (ITerm t in set) { tail = tail.Append((ITerm)t.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... } return(result); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); IRuntimeServices rs = ts.GetUserAgArch().GetRuntimeServices(); IListTerm ln = new ListTermImpl(); IListTerm tail = ln; foreach (string a in rs.GetAgentsNames()) { tail = tail.Append(new Atom(a)); } return(un.Unifies(args[0], ln)); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); ITerm var = args[0]; ILogicalFormula logExpr = (ILogicalFormula)args[1]; IListTerm all = new ListTermImpl(); IListTerm tail = all; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(reasoner.GetAgent(), un); while (iu.MoveNext()) { tail = tail.Append(var.CApply(iu.Current)); } return(un.Unifies(args[2], all)); }
IListTerm DeleteFromList(int index, int end, IListTerm l) { IListTerm r = new ListTermImpl(); IListTerm last = r; int i = 0; foreach (ITerm t in l) { if (i < index || i >= end) { last = last.Append((ITerm)t.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... } i++; } return(r); }
IListTerm DeleteFromList(ITerm element, IListTerm l, Unifier un) { Unifier bak = un; IListTerm r = new ListTermImpl(); IListTerm last = r; foreach (ITerm t in l) { if (un.Unifies(element, t)) { un = bak.Clone(); } else { last = last.Append((ITerm)t.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... } } return(r); }
public ITerm GetAsTerm() { IListTerm lf = new ListTermImpl(); IListTerm tail = lf; foreach (VarTerm k in function.Keys) { ITerm vl; function.TryGetValue(k, out vl); vl.Clone(); // Como uso el Clone de C# lo que clono son object que luego hay que castear... if (vl is Literal) { ((Literal)vl).MakeVarsAnnon(); } // Variable must be changed to avoid cyclic references later Structure pair = AsSyntax.AsSyntax.CreateStructure("dictionary", UnnamedVar.Create(k.ToString()), vl); tail = tail.Append(pair); } return(lf); }
public override IListTerm GetAnnots(string functor) { IListTerm ls = new ListTermImpl(); if (annotations != null) { IListTerm tail = ls; foreach (ITerm ta in annotations) { if (ta.IsLiteral()) { if (((Literal)ta).GetFunctor().Equals(functor)) { tail = tail.Append(ta); } } } } return(ls); }
public override IListTerm GetSources() { IListTerm ls = new ListTermImpl(); if (annotations != null) { IListTerm tail = ls; foreach (ITerm ta in annotations) { if (ta.IsStructure()) { Structure tas = (Structure)ta; if (tas.GetFunctor().Equals("source")) { tail = tail.Append(tas.GetTerm(0)); } } } } return(ls); }