예제 #1
0
 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);
 }
예제 #2
0
        // Adds a new literal at the end of the belief base
        protected bool Add(Literal l, bool addInEnd)
        {
            if (!l.CanBeAddedInBB())
            {
                return(false);
            }

            Literal bl = Contains(l);

            if (bl != null && !bl.IsRule())
            {
                if (bl.ImportAnnots(l))
                {
                    if (l.HasAnnot(TPercept))
                    {
                        percepts.Add(bl);
                    }
                    return(true);
                }
            }
            else
            {
                // new belief
                l = l.Copy();
                BelEntry entry = ProvideBelEntry(l);
                entry.Add(l, addInEnd);

                // Add it to percepts list
                if (l.HasAnnot(TPercept))
                {
                    percepts.Add(l);
                }

                size++;
                return(true);
            }
            return(false);
        }