Exemplo n.º 1
0
        public void GetStringTest()
        {
            un.function.Add(new VarTerm("key"), new VarTerm("value"));
            string s = "key";

            ITerm resultado = un.Get(s);

            VarTerm v = new VarTerm("value");

            Assert.AreEqual(v, resultado);
        }
Exemplo n.º 2
0
        public void UnifierTest()
        {
            string  var = "?x, ?y, ?z";
            string  val = "A B C";
            Unifier u   = new Unifier(var, val);

            Assert.AreEqual("B", u.Get("?y"));
        }
Exemplo n.º 3
0
        public override ITerm CApply(Unifier u)
        {
            ITerm v = u.Get(cyclicVar);

            u.Remove(cyclicVar);
            ITerm r = new CyclicTerm(this, cyclicVar.Clone() as VarTerm, u);

            if (v != null)
            {
                u.Bind(cyclicVar, v);
            }
            return(r);
        }
Exemplo n.º 4
0
        override public object Execute(Reasoner ts, Unifier un, ITerm[] args)
        {
            CheckArguments(args);
            Literal newl = (Literal)args[0];

            if (newl.IsVar())   // does 1 step unification
            {
                Literal vl = (Literal)un.Get((VarTerm)newl);
                if (vl != null)
                {
                    newl = vl;
                }
            }
            newl = newl.MakeVarsAnnon();
            return(un.Unifies(args[1], newl));
        }
Exemplo n.º 5
0
        public override ITerm CApply(Unifier u)
        {
            if (u != null)
            {
                ITerm vl = u.Get(this);
                if (vl != null)
                {
                    if (!vl.IsCyclicTerm() && vl.HasVar(this, u))
                    {
                        u.Remove(this);
                        ITerm tempVl = vl.CApply(u);
                        u.Bind(this, vl);

                        CyclicTerm ct          = new CyclicTerm(tempVl as Literal, this);
                        Unifier    renamedVars = new Unifier();
                        ct.MakeVarsAnnon(renamedVars);
                        renamedVars.Remove(this);
                        u.Compose(renamedVars);
                        vl = ct;
                    }

                    vl = vl.CApply(u);

                    if (vl.IsLiteral())
                    {
                        if (GetNS() != Literal.DefaultNS)
                        {
                            vl = (vl.CloneNS(GetNS().CApply(u) as Atom) as Literal);
                        }
                        if (Negated())
                        {
                            ((Literal)vl).SetNegated(Literal.LNeg);
                        }
                    }

                    if (vl.IsLiteral() && this.HasAnnot())
                    {
                        vl = ((Literal)vl).ForceFullLiteralImpl().AddAnnots((IListTerm)this.GetAnnots().CApply(u));
                    }
                    return(vl);
                }
            }
            return((ITerm)Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear...
        }
Exemplo n.º 6
0
 public override bool HasVar(VarTerm t, Unifier u)
 {
     if (Equals(t))
     {
         return(true);
     }
     if (u != null)
     {
         ITerm vl = u.Get(this);
         if (vl != null)
         {
             try
             {
                 u.Remove(this);
                 return(vl.HasVar(t, u));
             }
             finally
             {
                 u.Bind(this, vl);
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public override bool HasSubsetAnnot(Literal p, Unifier u)
        {
            if (annotations == null)
            {
                return(true);
            }
            if (!p.HasAnnot())
            {
                return(false);
            }
            ITerm               thisTail    = null;
            IListTerm           pAnnots     = p.GetAnnots().CloneLTShallow();
            VarTerm             pTail       = pAnnots.GetTail();
            ITerm               pAnnot      = null;
            IListTerm           pAnnotsTail = null;
            IEnumerator <ITerm> en          = pAnnots.ListTermIterator();
            bool enReset = false;

            IEnumerator <IListTerm> en2 = annotations.ListTermIterator(); // use this iterator to get the tail of the list

            while (en2.MoveNext())
            {
                IListTerm lt    = en2.Current;
                ITerm     annot = lt.GetTerm();
                if (annot == null)
                {
                    break;
                }
                if (lt.IsTail())
                {
                    thisTail = lt.GetTail();
                }
                if (annotations.IsVar() && !enReset)
                {
                    enReset = true;
                    en      = pAnnots.ListTermIterator();
                    pAnnot  = null;
                }
                bool ok = false;
                while (true)
                {
                    if (pAnnot != null && u.UnifiesNoUndo(annotations, pAnnot))
                    {
                        ok = true;
                        en.Dispose();
                        pAnnot = en.Current;
                        break;
                    }
                    else if (pAnnot != null && pAnnot.CompareTo(annot) > 0)
                    {
                        break;
                    }
                    else if (en.MoveNext())
                    {
                        pAnnot = en.Current;
                    }
                    else
                    {
                        break;
                    }
                }
                if (!ok && pTail != null)
                {
                    if (pAnnotsTail == null)
                    {
                        pAnnotsTail = (IListTerm)u.Get(pTail);
                        if (pAnnotsTail == null)
                        {
                            pAnnotsTail = new ListTermImpl();
                            u.Unifies(pTail, pAnnotsTail);
                            pAnnotsTail = (IListTerm)u.Get(pTail);
                        }
                    }
                    pAnnotsTail.Add((ITerm)annot.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear...
                    ok = true;
                }
                if (!ok)
                {
                    return(false);
                }
            }
            if (thisTail != null)
            {
                u.Unifies(thisTail, pAnnots);
            }
            return(true);
        }