public new IListTerm GetAsListOfTerms() { IListTerm l = new ListTermImpl(); l.Add(GetLabel()); l.Add(GetTrigger()); l.Add(GetContext()); l.Add(GetBody()); return(l); }
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); }
/** returns this literal as a list with three elements: [functor, list of terms, list of annots] */ public IListTerm GetAsListOfTerms() { IListTerm l = new ListTermImpl(); l.Add(GetNS()); l.Add(new LiteralImpl(!Negated(), GetFunctor())); IListTerm lt = new ListTermImpl(); l.Add(lt); if (HasAnnot()) { l.Add(GetAnnots().CloneLT()); } else { l.Add(new ListTermImpl()); } return(l); }
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); }
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); }