override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { try { Literal pattern = (Literal)args[0]; IListTerm result = new ListTermImpl(); //synchronized(ts.GetAgent().GetBB().GetLock()) { IEnumerator <Literal> i = ts.GetAgent().GetBB().GetCandidateBeliefs(pattern, un); while (i.MoveNext()) { Literal l = i.Current; if (l.IsRule()) { if (un.Clone().Unifies(pattern, l)) { l = l.Copy(); l.DelSources(); ((Rule)l).SetAsTerm(true); result.Add(l); } } } //} return(un.Unifies(args[1], result)); } catch (Exception e) { //ts.GetLogger().Warning("Error in internal action 'get_rules'! "+e); } return(false); }
public static ITerm AddAnnotToList(ITerm l, DefaultTerm source) { if (l.IsList()) { IListTerm result = new ListTermImpl(); foreach (ITerm lTerm in (IListTerm)l) { ITerm t = AddAnnotToList(lTerm, source); if (t != null) { result.Add(t); } } return(result); } else if (l.IsLiteral()) { Literal result = ((Literal)l).ForceFullLiteralImpl().Copy(); //Create the source annots Literal ts = Pred.CreateSource(source).AddAnnots(result.GetAnnots("source")); result.DelSources(); result.AddAnnots(ts); return(result); } else { return(l); } }