コード例 #1
0
        /// <summary> The current implementation will try to find the memory for the node.
        /// If it doesn't find it, it will create a new one.
        /// </summary>
        public virtual Object getAlphaMemory(Object key)
        {
            Object m = alphaMemories.Get(key);

            if (m == null)
            {
                String mname = "alphamem" + ((BaseNode)key).nodeID;
                m = new AlphaMemoryImpl(mname);
                alphaMemories.Put(key, m);
            }
            return(m);
        }
コード例 #2
0
        /// <summary> the current implementation will try to find the memory for the node.
        /// If it doesn't find it, it will create a new Left memory, which is
        /// HashMap.
        /// </summary>
        public virtual IGenericMap <object, object> getBetaLeftMemory(Object key)
        {
            IGenericMap <object, object> m = betaLeftMemories.Get(key);

            if (m == null)
            {
                // it should create a new memory
                // and return it.
                String mname = "blmem" + ((BaseNode)key).nodeID;
                m = CollectionFactory.newBetaMemoryMap(mname);
                betaLeftMemories.Put(key, m);
            }
            return(m);
        }
コード例 #3
0
        public virtual void assertFact(IFact fact)
        {
            Deffact f = (Deffact)fact;

            if (!containsFact(f))
            {
                deffactMap.Put(fact.equalityIndex(), f);
                f.setFactId = engine;
                if (profileAssert_Renamed_Field)
                {
                    assertFactWProfile(f);
                }
                else
                {
                    if (watchFact_Renamed_Field)
                    {
                        engine.writeMessage("==> " + fact.toFactString() + Constants.LINEBREAK, "t");
                    }
                    root.assertObject(f, engine, this);
                }
            }
            else
            {
                f.resetID((Deffact)deffactMap.Get(fact.equalityIndex()));
            }
        }
コード例 #4
0
        /// <summary> Clear will Clear the lists
        /// </summary>
        public override void clear(IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem  = mem.getBetaLeftMemory(this);
            IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this);

            // first we iterate over the list for each fact
            // and Clear it.
            foreach (object item in leftmem.Keys)
            {
                ((IBetaMemory)leftmem.Get(item)).clear();
            }

            /*
             * IEnumerator itr = leftmem.Keys.GetEnumerator();
             * // first we iterate over the list for each fact
             * // and Clear it.
             * while (itr.MoveNext())
             * {
             *  IBetaMemory bmem = (IBetaMemory) leftmem.Get(itr.Current);
             *  bmem.clear();
             * }
             */

            // now that we've cleared the list for each fact, we
            // can Clear the Creshendo.rete.util.Map.
            leftmem.Clear();
            rightmem.Clear();
        }
コード例 #5
0
 /// <summary>
 /// assertObject begins the pattern matching
 /// </summary>
 /// <param name="fact">The fact.</param>
 /// <param name="engine">The engine.</param>
 /// <param name="mem">The mem.</param>
 public virtual void assertObject(IFact fact, Rete engine, IWorkingMemory mem)
 {
     lock (this)
     {
         // we assume Rete has already checked to see if the object
         // has been added to the working memory, so we just assert.
         // we need to lookup the defclass and deftemplate to assert
         // the object to the network
         ObjectTypeNode otn = (ObjectTypeNode)inputNodes.Get(fact.Deftemplate);
         if (otn != null)
         {
             otn.assertFact(fact, engine, mem);
         }
         if (fact.Deftemplate.Parent != null)
         {
             assertObjectParent(fact, fact.Deftemplate.Parent, engine, mem);
         }
     }
 }
コード例 #6
0
        public virtual Object getTerminalMemory(Object key)
        {
            Object m = terminalMemories.Get(key);

            if (m == null)
            {
                m = CollectionFactory.newTerminalMap();
                terminalMemories.Put(key, m);
            }
            return(m);
        }
コード例 #7
0
ファイル: Agenda.cs プロジェクト: joaocc/creshendo--git
        /// <summary> Clear will Clear all the modules and Remove all activations
        /// </summary>
        public virtual void clear()
        {
            IEnumerator itr = modules.Keys.GetEnumerator();

            while (itr.MoveNext())
            {
                Object  key = itr.Current;
                IModule mod = (IModule)modules.Get(key);
                mod.clear();
            }
            modules.Clear();
        }
コード例 #8
0
        /// <summary> the current implementation will try to find the memory for the node.
        /// If it doesn't find it, it checks the node type and creates the
        /// appropriate AlphaMemory for the node. Since right memories are
        /// hashed, it creates the appropriate type of Hashed memory.
        /// </summary>
        public virtual Object getBetaRightMemory(Object key)
        {
            Object val = betaRightMemories.Get(key);

            if (val != null)
            {
                return(val);
            }
            else
            {
                if (key is HashedEqBNode || key is HashedEqNJoin || key is ExistJoin)
                {
                    String mname = "hnode" + ((BaseNode)key).nodeID;
                    HashedAlphaMemoryImpl alpha = new HashedAlphaMemoryImpl(mname);
                    betaRightMemories.Put(key, alpha);
                    return(alpha);
                }
                else if (key is HashedNotEqBNode || key is HashedNotEqNJoin || key is ExistNeqJoin)
                {
                    String mname = "hneq" + ((BaseNode)key).nodeID;
                    HashedNeqAlphaMemory alpha = new HashedNeqAlphaMemory(mname);
                    betaRightMemories.Put(key, alpha);
                    return(alpha);
                }
                else if (key is TemporalEqNode)
                {
                    String mname = "hnode" + ((BaseNode)key).nodeID;
                    TemporalHashedAlphaMem alpha = new TemporalHashedAlphaMem(mname);
                    betaRightMemories.Put(key, alpha);
                    return(alpha);
                }
                else
                {
                    String mname = "brmem" + ((BaseNode)key).nodeID;
                    IGenericMap <IFact, IFact> right = CollectionFactory.newAlphaMemoryMap(mname);
                    betaRightMemories.Put(key, right);
                    return(right);
                }
            }
        }
コード例 #9
0
        /// <summary> Remove a rule from this module
        /// </summary>
        public virtual void removeRule(Rule.IRule rl, Rete engine, IWorkingMemory mem)
        {
            rules.Remove(rl.Name);
            // we should iterate over the nodes of the rule and Remove
            // them if they are not shared
            ICondition[] cnds = rl.Conditions;
            // first Remove the alpha nodes
            for (int idx = 0; idx < cnds.Length; idx++)
            {
                ICondition cnd = cnds[idx];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    removeAlphaNodes(oc.Nodes, otn);
                }
            }
            // now Remove the betaNodes, since the engine currently
            // doesn't share the betaNodes, we can just Remove it
            IList bjl = rl.Joins;

            for (int idx = 0; idx < bjl.Count; idx++)
            {
                BaseJoin   bjoin = (BaseJoin)bjl[idx];
                ICondition cnd   = cnds[idx + 1];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    otn.removeNode(bjoin);
                }
            }
        }
コード例 #10
0
ファイル: EventCounter.cs プロジェクト: joaocc/creshendo--git
        /* (non-Javadoc)
         * @see woolfel.engine.rete.EngineEventListener#eventOccurred(woolfel.engine.rete.EngineEvent)
         */

        #region EngineEventListener Members

        public virtual void eventOccurred(EngineEvent event_Renamed)
        {
            if (event_Renamed.EventType == EngineEvent.ASSERT_EVENT)
            {
                asserts.Add(event_Renamed);
            }
            else if (event_Renamed.EventType == EngineEvent.ASSERT_PROFILE_EVENT)
            {
                asserts.Add(event_Renamed);
                profiles.Add(event_Renamed);
            }
            else if (event_Renamed.EventType == EngineEvent.ASSERT_RETRACT_EVENT)
            {
                asserts.Add(event_Renamed);
                retracts.Add(event_Renamed);
            }
            else if (event_Renamed.EventType == EngineEvent.ASSERT_RETRACT_PROFILE_EVENT)
            {
                asserts.Add(event_Renamed);
                profiles.Add(event_Renamed);
                retracts.Add(event_Renamed);
            }
            else if (event_Renamed.EventType == EngineEvent.PROFILE_EVENT)
            {
                profiles.Add(event_Renamed);
            }
            else if (event_Renamed.EventType == EngineEvent.RETRACT_EVENT)
            {
                retracts.Add(event_Renamed);
            }
            Object val = nodeFilter.Get(event_Renamed.SourceNode);

            if (val != null)
            {
                ((List <Object>)val).Add(event_Renamed);
            }
        }
コード例 #11
0
        /// <summary> Clear will Clear the lists
        /// </summary>
        public override void clear(IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem  = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);
            HashedNeqAlphaMemory         rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this);
            IEnumerator itr = leftmem.Keys.GetEnumerator();

            // first we iterate over the list for each fact
            // and Clear it.
            while (itr.MoveNext())
            {
                IBetaMemory bmem = (IBetaMemory)leftmem.Get(itr.Current);
                bmem.clear();
            }
            // now that we've cleared the list for each fact, we
            // can Clear the Creshendo.rete.util.Map.
            leftmem.Clear();
            rightmem.clear();
        }
コード例 #12
0
        /// <summary> addPartialMatch stores the fact with the factId as the
        /// key.
        /// </summary>
        public virtual int addPartialMatch(IHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(index);
            int count = 0;

            if (matches == null)
            {
                count = addNewPartialMatch(index, fact);
            }
            else
            {
                matches.Put(fact, fact);
                count = matches.Count;
            }
            counter++;
            return(count);
        }
コード例 #13
0
        /// <summary> return the value associated with the binding
        /// </summary>
        public virtual Object getBindingValue(string key)
        {
            Object val = bindValues.Get(key);

            if (val == null)
            {
                Binding bd = (Binding)bindings[key];
                if (bd != null)
                {
                    IFact left = triggerFacts[bd.LeftRow];
                    if (bd.IsObjectVar)
                    {
                        val = left;
                    }
                    else
                    {
                        val = left.getSlotValue(bd.LeftIndex);
                    }
                }
            }
            return(val);
        }
コード例 #14
0
        /// <summary> assert using HashMap approach
        ///
        /// </summary>
        /// <param name="">fact
        /// </param>
        /// <param name="">engine
        /// </param>
        /// <param name="">mem
        ///
        /// </param>
        public virtual void assertFactWithMap(IFact fact, Rete engine, IWorkingMemory mem)
        {
            Slot[] slots = fact.Deftemplate.AllSlots;
            // iterate over the slots
            for (int idx = 0; idx < slots.Length; idx++)
            {
                // only if the slot's node count is greater than zero
                // do we go ahead and lookup in the HashMap
                if (slots[idx].NodeCount > 0)
                {
                    // iterate over the operators
                    for (int ops = 0; ops < operators.Length; ops++)
                    {
                        CompositeIndex comIndex = new CompositeIndex(slots[idx].Name, operators[ops], fact.getSlotValue(idx));

                        Object node = entries.Get(comIndex);
                        if (node != null)
                        {
                            if (node is BaseAlpha)
                            {
                                ((BaseAlpha)node).assertFact(fact, engine, mem);
                            }
                            else if (node is BaseJoin)
                            {
                                ((BaseJoin)node).assertRight(fact, engine, mem);
                            }
                            else if (node is TerminalNode)
                            {
                                Index inx = new Index(new IFact[] { fact });
                                ((TerminalNode)node).assertFacts(inx, engine, mem);
                            }
                        }
                    }
                }
            }
            assertSecondSuccessors(fact, engine, mem);
        }
コード例 #15
0
 /// <summary> implementation looks up the rule in the HashMap
 /// </summary>
 public virtual Rule.IRule findRule(String name)
 {
     return((Rule.IRule)rules.Get(name));
 }
コード例 #16
0
        public virtual bool isPartialMatch(NotEqHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> match = (IGenericMap <Object, Object>)memory.Get(index);

            if (match != null)
            {
                IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)match.Get(index.SubIndex);
                if (submatch != null)
                {
                    return(submatch.ContainsKey(fact));
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #17
0
 public virtual IModule findModule(String name)
 {
     return((IModule)modules.Get(name));
 }
コード例 #18
0
        /// <summary> Remove a partial match from the memory
        /// </summary>
        public virtual int removePartialMatch(NotEqHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> match = (IGenericMap <Object, Object>)memory.Get(index);

            if (match != null)
            {
                IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)match.Get(index.SubIndex);
                submatch.Remove(fact);
                if (submatch.Count == 0)
                {
                    match.Remove(index.SubIndex);
                }
                counter--;
                return(submatch.Count);
            }
            return(-1);
        }
コード例 #19
0
        protected internal virtual void printBetaNodes(BaseJoin bjoin, bool detailed, int betaTotal)
        {
            if (bjoin is HashedEqBNode || bjoin is HashedEqNJoin)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is HashedNotEqNJoin || bjoin is HashedNotEqBNode)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is ExistJoin)
            {
                ExistJoin henj = (ExistJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(henj);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(henj);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(henj.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is NotJoin)
            {
                NotJoin nj = (NotJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)getBetaLeftMemory(bjoin);
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index       indx = (Index)bitr.Current;
                    IBetaMemory bmem = (IBetaMemory)bm.Get(indx);
                    engine.writeMessage(bmem.toPPString());
                }
            }
            else if (bjoin is TemporalEqNode)
            {
                TemporalEqNode ten = (TemporalEqNode)bjoin;
            }
            else
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index  indx     = (Index)bm.Get(bitr.Current);
                    Object rightmem = betaRightMemories.Get(bjoin);
                    if (detailed)
                    {
                        if (rightmem is HashedAlphaMemoryImpl)
                        {
                            HashedAlphaMemoryImpl hami = (HashedAlphaMemoryImpl)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + hami.size() + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                        else
                        {
                            IGenericMap <Object, Object> rmap = (IGenericMap <Object, Object>)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + rmap.Count + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                    }
                    if (rightmem is HashedAlphaMemoryImpl)
                    {
                        betaTotal += ((HashedAlphaMemoryImpl)rightmem).size();
                    }
                    else
                    {
                        betaTotal += ((IGenericMap <IFact, IFact>)rightmem).Count;
                    }
                }
            }
        }
コード例 #20
0
        /// <summary> return an List with all the facts
        /// </summary>
        /// <returns>
        ///
        /// </returns>
        public override Object[] iterateAll()
        {
            Object[]    facts = new Object[counter];
            IEnumerator itr   = memory.Keys.GetEnumerator();
            int         idx   = 0;

            while (itr.MoveNext())
            {
                IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(itr.Current);
                IEnumerator itr2 = matches.Keys.GetEnumerator();
                while (itr2.MoveNext())
                {
                    IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)matches.Get(itr2.Current);
                    IEnumerator itr3 = submatch.Values.GetEnumerator();
                    while (itr3.MoveNext())
                    {
                        facts[idx] = itr3.Current;
                        idx++;
                    }
                }
            }
            Object[] trim = new Object[idx];
            Array.Copy(facts, 0, trim, 0, idx);
            facts = null;
            return(trim);
        }
コード例 #21
0
        /// <summary> Return the number of memories of all hash buckets
        /// </summary>
        public override int size()
        {
            IEnumerator itr   = memory.Keys.GetEnumerator();
            int         count = 0;

            while (itr.MoveNext())
            {
                IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(itr.Current);
                IEnumerator itr2 = matches.Keys.GetEnumerator();
                while (itr2.MoveNext())
                {
                    EqHashIndex ehi = (EqHashIndex)itr2.Current;
                    IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)matches.Get(ehi);
                    count += submatch.Count;
                }
            }
            return(count);
        }
コード例 #22
0
        /// <summary> Here is a description of the compilation algorithm.
        /// 1. iterate over the conditional elements
        /// i. generate the alpha nodes
        /// a. literal constraints generate alpha node
        /// b. predicate constaints that compare against a literal generate alpha node
        /// ii. calculate the bindings
        /// a. each binding has a rowId
        /// b. NOT and EXIST CE do not increment the rowId
        /// 2. iterate over the conditional elements
        /// i. generate the beta nodes
        /// ii. attach the Left Input adapater nodes
        /// iii. attach the join nodes to the alpha nodes
        /// 3. create the terminal node and attach to the last
        /// join node.
        ///
        /// This means the rule compiler takes a 2 pass approach to
        /// compiling rules. At the start of the method, it sets 3
        /// attributes to null: prevCE, prevJoinNode, joinNode.
        /// Those attributes are used by the compile join methods,
        /// so it's important to set it to null at the start. If
        /// we don't the Current rule won't compile correctly.
        /// </summary>
        public virtual bool addRule(Rule.IRule rule)
        {
            rule.resolveTemplates(engine);
            if (!validate || (validate && tval.analyze(rule) == Analysis_Fields.VALIDATION_PASSED))
            {
                // we have to set the attributes to null, before we start compiling a rule.

                // we've set the attributes to null, so we can compile now!!

                if (rule.Conditions != null && rule.Conditions.Length > 0)
                {
                    // we check the name of the rule to see if it is for a specific
                    // module. if it is, we have to Add it to that module
                    Module = rule;
                    try
                    {
                        ICondition[] conds = rule.Conditions;
                        // first we create the constraints, before creating the Conditional
                        // elements which include joins
                        // we use a counter and only increment it to make sure the
                        // row index of the bindings are accurate. this makes it simpler
                        // for the rule compiler and compileJoins is cleaner and does
                        // less work.
                        int counter = 0;
                        for (int idx = 0; idx < conds.Length; idx++)
                        {
                            ICondition con = conds[idx];
                            // compile object conditions
                            //implement in the ObjectConditionCompiler.compile or ExistConditionCompiler.compile
                            con.getCompiler(this).compile(con, counter, rule, rule.RememberMatch);

                            if ((con is ObjectCondition) && (!((ObjectCondition)con).Negated))
                            {
                                counter++;
                            }
                        }
                        // now we compile the joins
                        compileJoins(rule);

                        BaseNode     last  = rule.LastNode;
                        TerminalNode tnode = createTerminalNode(rule);

                        attachTerminalNode(last, tnode);
                        // compile the actions
                        compileActions(rule, rule.Actions);
                        // now we pass the bindings to the rule, so that actiosn can
                        // resolve the bindings

                        // now we Add the rule to the module
                        currentMod.addRule(rule);
                        CompileMessageEventArgs ce = new CompileMessageEventArgs(rule, EventType.ADD_RULE_EVENT);
                        ce.Rule = rule;
                        notifyListener(ce);
                        return(true);
                    }
                    catch (AssertException e)
                    {
                        CompileMessageEventArgs ce = new CompileMessageEventArgs(rule, EventType.INVALID_RULE);
                        ce.Message = Messages.getString("RuleCompiler.assert.error"); //$NON-NLS-1$
                        notifyListener(ce);
                        TraceLogger.Instance.Debug(e);
                        return(false);
                    }
                }
                else if (rule.Conditions.Length == 0)
                {
                    Module = rule;
                    // the rule has no LHS, this means it only has actions
                    BaseNode     last  = (BaseNode)inputnodes.Get(engine.initFact);
                    TerminalNode tnode = createTerminalNode(rule);
                    compileActions(rule, rule.Actions);
                    attachTerminalNode(last, tnode);
                    // now we Add the rule to the module
                    currentMod.addRule(rule);
                    CompileMessageEventArgs ce = new CompileMessageEventArgs(rule, EventType.ADD_RULE_EVENT);
                    ce.Rule = rule;
                    notifyListener(ce);
                    return(true);
                }
                return(false);
            }
            else
            {
                // we need to print out a message saying the rule was not valid
                ISummary error = tval.Errors;
                engine.writeMessage("Rule " + rule.Name + " was not added. ", Constants.DEFAULT_OUTPUT); //$NON-NLS-1$ //$NON-NLS-2$
                engine.writeMessage(error.Message, Constants.DEFAULT_OUTPUT);
                ISummary warn = tval.Warnings;
                engine.writeMessage(warn.Message, Constants.DEFAULT_OUTPUT);
                return(false);
            }
        }
コード例 #23
0
        /// <summary> Return an GetEnumerator of the values
        /// </summary>
        public virtual Object[] iterator(NotEqHashIndex index)
        {
            IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(index);

            Object[] list = new Object[counter];
            Object[] trim = null;
            int      idz  = 0;

            if (matches != null)
            {
                IEnumerator itr = matches.Keys.GetEnumerator();
                while (itr.MoveNext())
                {
                    Object key = itr.Current;
                    // if the key doesn't match the subindex, we
                    // Add it to the list. If it matches, we exclude
                    // it.
                    if (!index.SubIndex.Equals(key))
                    {
                        IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)matches.Get(key);
                        IEnumerator itr2 = submatch.Keys.GetEnumerator();
                        while (itr2.MoveNext())
                        {
                            list[idz] = itr2.Current;
                            idz++;
                        }
                    }
                    trim = new Object[idz];
                    Array.Copy(list, 0, trim, 0, idz);
                }
                list = null;
                return(trim);
            }
            else
            {
                return(null);
            }
        }
コード例 #24
0
 /// <summary>
 /// Return the write method using slot name for the key
 /// </summary>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public virtual MethodInfo getWriteMethod(String name)
 {
     return(((PropertyInfo)methods.Get(name)).GetSetMethod());
 }
コード例 #25
0
        /// <summary> addPartialMatch stores the fact with the factId as the
        /// key.
        /// </summary>
        public virtual int addPartialMatch(NotEqHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(index);
            int count = 0;

            if (matches == null)
            {
                count = addNewPartialMatch(index, fact);
            }
            else
            {
                IGenericMap <object, object> submatch = (IGenericMap <object, object>)matches.Get(index.SubIndex);
                if (submatch == null)
                {
                    submatch = CollectionFactory.newHashMap();
                    submatch.Put(fact, fact);
                    matches.Put(index.SubIndex, submatch);
                    count = matches.Count;
                }
                else
                {
                    submatch.Put(fact, fact);
                    count = submatch.Count;
                }
            }
            counter++;
            return(count);
        }
コード例 #26
0
ファイル: DefglobalMap.cs プロジェクト: joaocc/creshendo--git
 /// <summary> The current implementation calls HashMap.Get(key). if the key
 /// and value aren't in the HashMap, it returns null.
 /// </summary>
 /// <param name="">name
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public virtual Object getValue(String name)
 {
     return(variables.Get(name));
 }
コード例 #27
0
        /// <summary> Clear the memory.
        /// </summary>
        public override void clear()
        {
            IEnumerator itr = memory.Keys.GetEnumerator();

            while (itr.MoveNext())
            {
                object key = itr.Current;
                IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(key);
                IEnumerator itr2 = matches.Keys.GetEnumerator();
                while (itr2.MoveNext())
                {
                    Object subkey = itr2.Current;
                    IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)matches.Get(subkey);
                    submatch.Clear();
                }
                matches.Clear();
            }
            memory.Clear();
        }
コード例 #28
0
        /// <summary>
        /// if there are zero matches for the NotEqHashIndex2, the method
        /// return true. If there are matches, the method returns false.
        /// False means there's 1 or more matches
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public virtual bool zeroMatch(NotEqHashIndex index)
        {
            IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory.Get(index);
            int idz = 0;

            if (matches != null)
            {
                IEnumerator itr = matches.Keys.GetEnumerator();
                while (itr.MoveNext())
                {
                    Object key = itr.Current;
                    // if the key doesn't match the subindex, Add it to the
                    // counter.
                    if (!index.SubIndex.Equals(key))
                    {
                        IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)matches.Get(key);
                        idz += submatch.Count;
                    }
                    if (idz > 0)
                    {
                        break;
                    }
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }