예제 #1
0
파일: Pred.cs 프로젝트: nasa03/Jasonity
 public override Literal MakeVarsAnnon(Unifier un)
 {
     if (annotations != null)
     {
         IListTerm lt = annotations;
         while (!(lt.Count == 0))
         {
             ITerm ta = lt.GetTerm();
             if (ta.IsVar())
             {
                 lt.SetTerm(VarToReplace(ta, un));
             }
             else if (ta.GetType() == typeof(Structure))
             {
                 ((Structure)ta).MakeVarsAnnon(un);
             }
             if (lt.IsTail() && lt.GetNext().IsVar())
             {
                 lt.SetNext(VarToReplace(lt.GetNext(), un));
                 break;
             }
             lt = lt.GetNext();
         }
     }
     return(base.MakeVarsAnnon(un));
 }
예제 #2
0
파일: Pred.cs 프로젝트: nasa03/Jasonity
        public override Literal SetAnnots(IListTerm listTerm)
        {
            annotations = null;
            if (listTerm == null)
            {
                return(this);
            }
            IEnumerator <IListTerm> en = listTerm.ListTermIterator();

            while (en.MoveNext())
            {
                IListTerm lt = en.Current;
                if (lt.GetTerm() == null)
                {
                    return(this);
                }
                AddAnnot(lt.GetTerm());
                if (lt.IsTail())
                {
                    annotations.SetTail(lt.GetTail());
                    return(this);
                }
            }
            return(this);
        }
예제 #3
0
파일: Pred.cs 프로젝트: nasa03/Jasonity
        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);
        }