//public bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != null; //} //public Unifier Next() //{ // if (c == null) Find(); // Unifier b = c; // Find(); // find next response // return b; //} void Find() { while (listOutter != null && listOutter.Count != 0) { while (list.Count != 0) { IListTerm candidate = AsSyntax.AsSyntax.CreateList(list); list.Remove(list.ElementAt(list.Count - 1)); c = un.Clone(); if (c.UnifiesNoUndo(sublist, candidate)) { return; // found another sublist, c is the current response } } listOutter = listOutter.GetNext(); if (listOutter == null || listOutter.IsVar()) // the case of lists with tail { break; } list = listOutter.GetAsList(); } if (!triedEmpty) { triedEmpty = true; c = un.Clone(); if (c.UnifiesNoUndo(sublist, AsSyntax.AsSyntax.CreateList())) { return; // found another sublist, c is the current response } } c = null; // no more sublists found }
public void UnifiesNoUndoTriggerTest() { //HACER pruebas mas severas Trigger t = new Trigger(TEOperator.add, TEType.belief, new LiteralImpl("literal")); bool resultado = un.UnifiesNoUndo(t, t); Assert.AreEqual(true, resultado); }
// Returns an unifier if this plan is relevant for event "te", null otherwise internal Unifier IsRelevant(Trigger te) { // Annots in plan's TE must be a subset of the ones in the event! Unifier u = new Unifier(); if (u.UnifiesNoUndo(tevent, te)) { return(u); } else { return(null); } }
//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 bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != null; //} //public Unifier Next() //{ // if (c == null) Find(); // Unifier b = c; // Find(); // find next response // return b; //} void Find() { if (pos < s1.Length) { pos = s1.IndexOf(s0, pos); if (pos >= 0) { c = (Unifier)un.Clone(); c.UnifiesNoUndo(args[2], new NumberTermImpl(pos)); pos++; return; } pos = s1.Length; // to stop searching } c = null; }
//public bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != null; //} //public Unifier Next() //{ // if (c == null) // Find(); // Unifier b = c; // Find(); // find next response // return b; //} void Find() { while (list.MoveNext()) { IListTerm l = list.Current; if (l.IsVar()) // the case of the tail of the list { break; } c = un.Clone(); if (c.UnifiesNoUndo(sublist, AsSyntax.AsSyntax.CreateList(l))) { return; // found another sublist, c is the current response } } c = null; // no more sublists found }
//public bool HasNext() //{ // if (needsUpdate) // Get(); // return current != null; //} //public Unifier Next() //{ // if (needsUpdate) // Get(); // if (current != null) // needsUpdate = true; // return current; //} private void Get() { needsUpdate = false; current = default; if (arch != null && !arch.IsRunning()) { return; } if (annotsOptions != null) { while (annotsOptions.MoveNext()) { Literal belToTry = belInBB.Copy().SetAnnots(null).AddAnnots(annotsOptions.Current); Unifier u = un.Clone(); if (u.UnifiesNoUndo(lit, belToTry)) { current = u; return; } } annotsOptions = null; } if (ruleIt != null) { while (ruleIt.MoveNext()) { Unifier ruleUn = ruleIt.Current; Literal rHead = rule.HeadCApply(ruleUn); UseDerefVars(rHead, ruleUn); rHead.MakeVarsAnnon(); Unifier unC = un.Clone(); if (unC.UnifiesNoUndo(lit, rHead)) { current = unC; return; } } ruleIt = null; } while (il.MoveNext()) { belInBB = il.Current; if (belInBB.IsRule()) { rule = (Rule)belInBB; if (cloneAnnon == null) { cloneAnnon = (Literal)lit.CApply(un); cloneAnnon.MakeVarsAnnon(); } Unifier ruleUn = new Unifier(); if (ruleUn.UnifiesNoUndo(cloneAnnon, rule)) { ruleIt = rule.GetBody().LogicalConsequence(ag, ruleUn); Get(); if (current != null) { return; } } else { if (nbAnnots > 0) { if (belInBB.HasAnnot()) { int nbAnnotsB = belInBB.GetAnnots().Count; if (nbAnnotsB >= nbAnnots) { annotsOptions = belInBB.GetAnnots().SubSets(nbAnnots); Get(); if (current != null) { return; } } } } else { Unifier u = un.Clone(); if (u.UnifiesNoUndo(lit, belInBB)) { current = u; return; } } } } } }
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); }