override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); // case 1, no vars if (!args[0].IsVar() && args[1].IsString()) { return(args[0].ToString().Equals(((IStringTerm)args[1]).GetString())); } // case 2, second is var if (!args[0].IsVar() && args[1].IsVar()) { return(un.Unifies(new StringTermImpl(args[0].ToString()), args[1])); } // case 3, first is var if (args[0].IsVar()) { if (args[1].IsString()) { return(un.Unifies(args[0], AsSyntax.AsSyntax.ParseTerm(((IStringTerm)args[1]).GetString()))); } else { return(un.Unifies(args[0], AsSyntax.AsSyntax.ParseTerm(args[1].ToString()))); } } throw new JasonityException("invalid case of term2string"); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Circumstance C = ts.GetCircumstance(); Trigger teGoal = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]); // search in PA foreach (ExecuteAction a in C.GetPendingActions().Values) { if (a.GetIntention().HasTrigger(teGoal, un)) { return(un.Unifies(args[1], aAct)); } } // search in PI Dictionary <string, Intention> pi = C.GetPendingIntentions(); foreach (string reason in pi.Keys) { if (pi[reason].HasTrigger(teGoal, un)) { return(un.Unifies(args[1], new StringTermImpl(reason))); } } return(false); }
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])); } }
public void UnifiesTriggerTest() { Trigger t = new Trigger(TEOperator.add, TEType.belief, new LiteralImpl("literal")); bool resultado = un.Unifies(t, t); Assert.AreEqual(true, resultado); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); DateTime dt = new DateTime(); GregorianCalendar now = new GregorianCalendar(); return(un.Unifies(args[0], new NumberTermImpl(now.GetYear(dt))) && un.Unifies(args[0], new NumberTermImpl(now.GetMonth(dt) + 1)) && un.Unifies(args[0], new NumberTermImpl(now.GetDayOfMonth(dt)))); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); DateTime myDt = new DateTime(); Calendar now = new GregorianCalendar(); return(un.Unifies(args[0], new NumberTermImpl(now.GetHour(myDt))) && un.Unifies(args[1], new NumberTermImpl(now.GetMinute(myDt))) && un.Unifies(args[2], new NumberTermImpl(now.GetSecond(myDt)))); }
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 override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ILogicalFormula logExpr = args[1] as ILogicalFormula; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); if (iu.Current != null) { return(un.Unifies(args[0], Literal.LTrue)); } else { return(un.Unifies(args[0], Literal.LFalse)); } }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); Agent ag = reasoner.GetAgent(); Pred inc = new Pred(ns, "include"); inc.AddTerms(args); //-Cosas Java??? //-Sí Peterrr, cÓsas Naz* ¡digo! cÓsas Java Agent result = ((Include)DirectiveProcessor.GetDirective("include")).Process(inc, ag, null); ag.ImportComponents(result); ag.AddInitialBelsInBB(); ag.AddInitialDesiresInReasoner(); if (args.Length > 1 && args[1].IsVar()) { return(un.Unifies(args[1], inc.GetTerm(1))); } else { return(true); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm result = AddAnnotToList(un, args[0], args[1]); return(un.Unifies(result, args[2])); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); //try to get the intention from the "body" Intention i = ts.GetCircumstance().GetSelectedIntention(); if (i == null) { //try to get the intention from the event Event evt = ts.GetCircumstance().GetSelectedEvent(); if (evt != null) { i = evt.GetIntention(); } } if (i != null) { return(un.Unifies(i.GetAsTerm(), args[0])); } else { return(false); } }
public override bool DropInt(Circumstance C, Literal goal, Unifier un) { Unifier bak = un.Clone(); bool isCurrentInt = false; IEnumerator <Intention> iint = C.GetAllIntentions(); while (iint.Current != null) { Intention i = iint.Current; IPlanBody pb = i.Peek().GetPlan().GetBody(); while (pb != null) { if (pb.GetBodyType() == BodyType.Body_Type.achieve || pb.GetBodyType() == BodyType.Body_Type.achieveNF) { if (un.Unifies(pb.GetBodyTerm(), goal)) { C.DropIntention(i); isCurrentInt = isCurrentInt || i.Equals(C.GetSelectedIntention()); un = bak.Clone(); break; } } pb = pb.GetBodyNext(); } } return(isCurrentInt); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { try { Literal pattern = (Literal)args[0]; IListTerm result = new ListTermImpl(); //synchronized(ts.GetAgent().GetBB().GetLock()) { IEnumerator <Literal> i = ts.GetAgent().GetBB().GetCandidateBeliefs(pattern, un); while (i.MoveNext()) { Literal l = i.Current; if (l.IsRule()) { if (un.Clone().Unifies(pattern, l)) { l = l.Copy(); l.DelSources(); ((Rule)l).SetAsTerm(true); result.Add(l); } } } //} return(un.Unifies(args[1], result)); } catch (Exception e) { //ts.GetLogger().Warning("Error in internal action 'get_rules'! "+e); } return(false); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm label = args[1]; Plan p; if (label.IsLiteral()) { p = ts.GetAgent().GetPL().Get(((Literal)label).ToString()); } else { p = ts.GetAgent().GetPL().Get((new Atom(label.ToString()).ToString())); } if (p != null) { p = (Plan)p.Clone(); p.GetLabel().DelSources(); p.SetAsPlanTerm(true); p.MakeVarsAnnon(); //String ps = p.toASString().replaceAll("\"", "\\\\\""); //return un.unifies(new StringTermImpl(ps), args[0]); return(un.Unifies(p, args[0])); } else { return(false); } }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); List <ITerm> l = ((IListTerm)args[0]).GetAsList(); l.Sort(); return(un.Unifies(AsSyntax.AsSyntax.CreateList(l), args[1])); }
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])); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); IListTerm lt = new ListTermImpl(); foreach (string a in ts.GetUserAgArch().GetRuntimeServices().DfSearch(GetService(args), GetType(args))) { lt.Add(new Atom(a)); } return(un.Unifies(args[args.Length - 1], lt)); }
// Returns the IntendedPlan with TE = g, null if there isn't one public IntendedPlan GetIntendedPlan(Trigger g, Unifier u) { foreach (IntendedPlan ip in plans) { if (u.Unifies(g, ip.GetTrigger())) { return(ip); } } return(null); }
// Returns true if intention has an IP where TE = g, using u to verify equality public bool HasTrigger(Trigger g, Unifier u) { foreach (IntendedPlan ip in plans) { if (u.Unifies(g, ip.GetTrigger())) { return(true); } } return(false); }
public object Execute(Reasoner ts, Unifier un, DefaultTerm[] args) { CheckArguments(args); try { return(un.Unifies(AddAnnotToList(args[0], args[1]), args[2])); } catch (Exception e) { throw new Exception("Error adding nest source '" + args[1] + "' to" + args[0], e); } }
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 ts, Unifier un, ITerm[] args) { CheckArguments(args); if (args[0].IsNumeric()) { int nextArg = 1; int start = (int)((args[0] as INumberTerm).Solve()); int end = start + 1; if (args.Length == 4 && args[1].IsNumeric()) { nextArg = 2; end = (int)((args[0] as INumberTerm).Solve()); } if (args[nextArg].IsString()) { return(un.Unifies(args[nextArg + 1], DeleteFromString(start, end, args[nextArg] as IStringTerm))); } else if (args[nextArg].IsList()) { return(un.Unifies(args[nextArg + 1], DeleteFromList(start, end, args[nextArg] as IListTerm))); } } if (args[0].IsString() && args[1].IsString()) { return(un.Unifies(args[2], DeleteFromString(args[0] as IStringTerm, args[1] as IStringTerm))); } if (args[0].IsString()) { return(un.Unifies(args[2], DeleteFromString(args[0] as IStringTerm, new StringTermImpl(args[1].ToString())))); } if (args[0].IsList()) { return(un.Unifies(args[2], DeleteFromList(args[0], args[1] as IListTerm, un.Clone()))); } throw new JasonityException("Incorrect use of the internal action '.delete' (see documentation)."); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ILogicalFormula logExpr = args[0] as ILogicalFormula; int n = 0; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); while (iu.Current != null) { iu.MoveNext(); n++; } return(un.Unifies(args[1], new NumberTermImpl(n))); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); if (args.Length == 1) { return(un.Unifies(args[0], new NumberTermImpl(random.NextDouble()))); } else { int max = (int)((INumberTerm)args[1]).Solve(); return(new RandomStdLibIterator <Unifier>(max, ts, un, random, args)); } }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); string s0; if (args[0].IsString()) { s0 = ((IStringTerm)args[0]).GetString(); } else { s0 = args[0].ToString(); } string s1; if (args[1].IsString()) { s1 = ((IStringTerm)args[1]).GetString(); } else { s1 = args[1].ToString(); } if (args.Length == 2) { // no backtracking utilisation return(s1.IndexOf(s0) >= 0); } else if (args[2].IsGround() && args[2].IsNumeric() && args[1].IsVar()) { // no backtracking utilisation // unifies the var with the substring int start = (int)((INumberTerm)(args[2])).Solve(); int end = s0.Length; if (args.Length == 4 && args[3].IsNumeric()) { end = (int)((INumberTerm)(args[3])).Solve(); } return(un.Unifies(args[1], new StringTermImpl(s0.Substring(start, end)))); } else { // backtrack version: unifies in the third argument all possible positions of s0 in s1 return(new SubStringStdLibIterator <Unifier>(reasoner, un, args, s1, s0)); } }
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)); }
//public bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != default; //} //public Unifier Next() //{ // if (c == null) // Find(); // find next response // Unifier b = c; // Find(); // return b; //} void Find() { while (ilist.MoveNext()) { index++; ITerm candidate = ilist.Current; c = un.Clone(); if (c.UnifiesNoUndo(args[2], candidate)) { c.Unifies(args[0], AsSyntax.AsSyntax.CreateNumberTerm(index)); return; // found another } } c = null; }
public void EventAdded(Event e) { if (dropped) { return; } if (te != null && un.Unifies(te, e.GetTrigger())) { Resume(false); } else if (formula != null && ts.GetAgent().Believes(formula, un)) { // each new event, just test the formula being waited Resume(false); } }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm var = args[0]; ILogicalFormula logExpr = (ILogicalFormula)args[1]; ISet <ITerm> all = new HashSet <ITerm>(); IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); while (iu.MoveNext()) { all.Add(var.CApply(iu.Current)); } return(un.Unifies(args[2], SetToList(all))); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); string arg = null; if (args[0].IsString()) { arg = ((IStringTerm)args[0]).GetString(); } else { arg = args[0].ToString(); } arg = arg.ToUpper(); return(un.Unifies(new StringTermImpl(arg), args[1])); }