public void BindTest() { VarTerm v = new VarTerm("key"); ITerm t = new LiteralImpl(false, "value"); bool resultado = un.Bind(v, t); Assert.AreEqual(true, resultado); }
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); }
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... }
public VarTerm VarToReplace(ITerm t, Unifier u) { VarTerm v = (VarTerm)t; VarTerm deref = u.Deref(v); if (deref.Equals(v)) { Atom a = v.GetNS(); if (a.IsVar()) { a = VarToReplace(a, u); } //UnnamedVar uv = useShortUnnamedVars ? new UnnamedVar(a) : UnnamedVar.Create(a, t.ToString()); UnnamedVar uv = UnnamedVar.Create(a, t.ToString()); if (deref.HasAnnot()) { uv.SetAnnots(deref.GetAnnots().CloneLT()); uv.MakeVarsAnnon(u); } u.Bind(deref, v); return(v); } else { Atom a = v.GetNS(); if (a.IsVar()) { a = VarToReplace(a, u); } deref = (VarTerm)deref.CloneNS(a); if (v.HasAnnot() && !deref.HasAnnot()) { deref.SetAnnots(v.GetAnnots().CloneLT()); deref.MakeVarsAnnon(u); } return(deref); } }
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); }