Beispiel #1
0
 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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        // 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);
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
        }