/// <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); }
public virtual IModule addModule(String name) { IModule mod = findModule(name); if (mod == null) { mod = new Defmodule(name); modules.Put(mod.ModuleName, mod); CurrentModule = mod; } return(mod); }
/// <summary> /// assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="linx">The linx.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); // we create a new list for storing the matches. // any fact that isn't in the list will be evaluated. IBetaMemory bmem = new BetaMemoryImpl(linx); leftmem.Put(bmem.Index, bmem); IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this); int prevCount = bmem.matchCount(); IEnumerator itr = rightmem.Values.GetEnumerator(); while (itr.MoveNext()) { IFact rfcts = (IFact)itr.Current; if (evaluate(linx.Facts, rfcts, engine)) { // it matched, so we Add it to the beta memory bmem.addMatch(rfcts); } } // since the Fact[] is entering the left for the first time, // if there are no matches, we merged the facts propogate. if (bmem.matchCount() == 0) { propogateAssert(linx, engine, mem); } }
/// <summary> /// Add a new ObjectTypeNode. The implementation will check to see /// if the node already exists. It will only Add the node if it /// doesn't already exist in the network. /// </summary> /// <param name="node">The node.</param> public virtual void addObjectTypeNode(ObjectTypeNode node) { if (!inputNodes.ContainsKey(node.Deftemplate)) { inputNodes.Put(node.Deftemplate, node); } }
public virtual void addNewPartialMatch(IHashIndex index, IFact fact) { IGenericMap <object, object> matches = CollectionFactory.newMap(); matches.Put(fact, fact); memory.Put(index, matches); }
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())); } }
/// <summary> /// assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="linx">The linx.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); //foreach(IFact rfcts in ((IGenericMap<IFact, IFact>)mem.getBetaRightMemory(this)).Values) //{ // propogateAssert(linx.add(rfcts), engine, mem); //} IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this); foreach (IFact rfcts in rightmem.Values) { propogateAssert(linx.add(rfcts), engine, mem); } //IEnumerator itr = rightmem.Values.GetEnumerator(); //while (itr.MoveNext()) //{ // IFact rfcts = (IFact)itr.Current; // // now we propogate // propogateAssert(linx.add(rfcts), engine, mem); //} }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); IBetaMemory bmem = new BetaMemoryImpl(linx); leftmem.Put(linx, bmem); IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.Keys.GetEnumerator(); if (itr != null) { while (itr.MoveNext()) { IFact vl = (IFact)itr.Current; // we have to evaluate the function if (vl != null && evaluate(linx.Facts, vl, engine)) { bmem.addMatch(vl); } } } if (bmem.matchCount() > 0) { propogateAssert(linx, engine, mem); } }
/// <summary> Add a successor node /// </summary> public override void addSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem) { if (!containsNode(successorNodes, node) && !successor2.Contains(node)) { if (node is BaseJoin || node is TerminalNode) { successor2.Add(node); } else { // we test to see if the operator is ==, nil, not nil // if the node isn't BaseJoin, it should be BaseAlpha BaseAlpha ba = (BaseAlpha)node; if (ba.Operator == Constants.LESS || ba.Operator == Constants.GREATER || ba.Operator == Constants.LESSEQUAL || ba.Operator == Constants.GREATEREQUAL || ba.Operator == Constants.NOTEQUAL || ba.Operator == Constants.NOTNILL) { successor2.Add(node); } else { addNode(node); } } if (gauranteeUnique && node is AlphaNode) { // now we use CompositeIndex instead of HashString AlphaNode anode = (AlphaNode)node; entries.Put(anode.HashIndex, node); // we increment the node count for the slot deftemplate.getSlot(anode.slot.Id).incrementNodeCount(); } // if there are matches, we propogate the facts to // the new successor only IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this); if (alpha.size() > 0) { IEnumerator itr = alpha.GetEnumerator(); while (itr.MoveNext()) { IFact f = (IFact)itr.Current; if (node is BaseAlpha) { BaseAlpha next = (BaseAlpha)node; next.assertFact(f, engine, mem); } else if (node is BaseJoin) { BaseJoin next = (BaseJoin)node; next.assertRight(f, engine, mem); } else if (node is TerminalNode) { TerminalNode t = (TerminalNode)node; Index inx = new Index(new IFact[] { f }); t.assertFacts(inx, engine, mem); } } } } }
public virtual int addNewPartialMatch(NotEqHashIndex index, IFact fact) { IGenericMap <object, object> matches = CollectionFactory.newHashMap(); IGenericMap <object, object> submatch = CollectionFactory.newHashMap(); submatch.Put(fact, fact); matches.Put(index.SubIndex, submatch); memory.Put(index, matches); return(1); }
public virtual Object getTerminalMemory(Object key) { Object m = terminalMemories.Get(key); if (m == null) { m = CollectionFactory.newTerminalMap(); terminalMemories.Put(key, m); } return(m); }
/// <summary> The implementation will use either the defclass or the /// template name for the key. The templates are stored in /// a HashMap. /// </summary> public virtual void addTemplate(ITemplate temp, Rete engine, IWorkingMemory mem) { if (!deftemplates.ContainsKey(temp.Name)) { // we have to set the template's module if (temp.ClassName != null) { deftemplates.Put(temp.Name, temp); deftemplates.Put(temp.ClassName, temp); templateCount++; } else { deftemplates.Put(temp.Name, temp); templateCount++; } ObjectTypeNode otn = new ObjectTypeNode(engine.nextNodeId(), temp); mem.RuleCompiler.addObjectTypeNode(otn); } }
/// <summary> /// Asserts the facts. /// </summary> /// <param name="inx">The inx.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem) { LinkedActivation act = new LinkedActivation(theRule, inx); act.TerminalNode = this; IGenericMap <Object, Object> tmem = (IGenericMap <Object, Object>)mem.getTerminalMemory(this); tmem.Put(inx, act); // Add the activation to the current module's activation list. engine.Agenda.addActivation(act); }
/// <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); }
/// <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); } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); if (rightmem.count(inx) > 0) { propogateAssert(linx, engine, mem); } }
/// <summary> addPartialMatch stores the fact with the factId as the /// key. /// </summary> public virtual void addPartialMatch(IHashIndex index, IFact fact) { IGenericMap <Object, Object> matches = (IGenericMap <Object, Object>)memory[index]; if (matches == null) { addNewPartialMatch(index, fact); } else { matches.Put(fact, fact); } counter++; }
/// <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); }
/// <summary> The implementation checks to see if the rule is active before it tries to /// assert the fact. It checks in the following order. /// 1. is the expiration date greater than zero /// 2. is the current time > the effective date /// 3. is the current time the expiration date /// </summary> /// <param name="">facts /// </param> /// <param name="">engine /// /// </param> public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem) { long time = (DateTime.Now.Ticks - 621355968000000000) / 10000; if (theRule.ExpirationDate > 0 && time > theRule.EffectiveDate && time < theRule.ExpirationDate) { LinkedActivation act = new LinkedActivation(theRule, inx); act.TerminalNode = this; IGenericMap <Object, Object> tmem = (IGenericMap <Object, Object>)mem.getTerminalMemory(this); tmem.Put(act.Index, act); // Add the activation to the current module's activation list. engine.Agenda.addActivation(act); } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); // need to think the getLeftValues through better to // account for cases when a join has no bindings NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); if (rightmem.zeroMatch(inx)) { propogateAssert(linx, engine, mem); } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); // we don't bother adding the right fact to the left, since // the right side is already Hashed if (rightmem.count(inx) == 0) { propogateAssert(linx, engine, mem); } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(inx); // if the right side has 1 or more matches, we propogate the original // index down the network. We don't Add any facts to the index if (objs != null && objs.Length > 0) { propogateAssert(linx, engine, mem); } }
/// <summary> Assert will first pass the facts to the parameters. Once the /// parameters are set, it should call execute to Get the result. /// </summary> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); if (!leftmem.ContainsKey(linx)) { Parameters = linx.Facts; IReturnVector rv = func.executeFunction(engine, params_Renamed); if (rv.firstReturnValue().BooleanValue) { IBetaMemory bmem = new BetaMemoryImpl(linx); leftmem.Put(bmem.Index, bmem); propogateAssert(linx, engine, mem); } } }
/// <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); }
/// <summary> init is responsible for checking the class to make sure /// it implements addPropertyChangeListener(java.beans.PropertyChangeListener) /// and removePropertyChangeListener(java.beans.PropertyChangeListener). /// We don't require the classes extend PropertyChangeSupport. /// </summary> public void init() { try { INFO = Introspector.getBeanInfo(OBJECT_CLASS); // we have to filter out the class PropertyDescriptor PropertyInfo[] pd = INFO.getPropertyDescriptors(); List <Object> list = new List <Object>(); for (int idx = 0; idx < pd.Length; idx++) { if (pd[idx].Name.Equals("class")) { // don't Add } else { // we map the methods using the PropertyDescriptor.getName for // the key and the PropertyDescriptor as the value methods.Put(pd[idx].Name, pd[idx]); list.Add(pd[idx]); } } PropertyInfo[] newpd = new PropertyInfo[list.Count]; list.CopyTo(newpd, 0); PROPS = (PropertyInfo[])newpd; // logic for filtering the PropertyDescriptors if (ObjectFilter.lookupFilter(OBJECT_CLASS) != null) { // Remove the props that should be invisible BeanFilter bf = ObjectFilter.lookupFilter(OBJECT_CLASS); PROPS = bf.filter(PROPS); } if (checkBean()) { ISBEAN = true; } // we clean up the array and List<Object> list.Clear(); pd = null; } catch (System.Exception e) { // we should log this and throw an exception } }
/// <summary> Assert from the right side is always going to be from an /// Alpha node. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertRight(IFact rfact, Rete engine, IWorkingMemory mem) { // we only proceed if the fact hasn't already entered // the join node Index inx = new Index(new IFact[] { rfact }); IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); if (!rightmem.ContainsKey(inx)) { int count = rightmem.Count; rightmem.Put(inx, rfact); // now that we've added the facts to the list, we // proceed with evaluating the fact if (count == 0 && rightmem.Count == 1) { propogateAssert(inx, engine, mem); } } }
/// <summary> Assert from the right side is always going to be from an Alpha node. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertRight(IFact rfact, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); rightmem.Put(rfact, rfact); IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); IEnumerator itr = leftmem.Values.GetEnumerator(); while (itr.MoveNext()) { IBetaMemory bmem = (IBetaMemory)itr.Current; if (evaluate(bmem.LeftFacts, rfact, engine)) { // now we propogate bmem.addMatch(rfact); propogateAssert(bmem.Index.add(rfact), engine, mem); } } }
/// <summary> implementation uses the deftemplate for the HashMap key and the /// node for the value. If the node already exists in the HashMap, /// or the key already exists, the compiler will not Add it to the /// network. /// </summary> public virtual void addObjectTypeNode(ObjectTypeNode node) { if (!inputnodes.ContainsKey(node.Deftemplate)) { inputnodes.Put(node.Deftemplate, node); } // if it is the objectTypeNode for InitialFact, we go ahead and create // the Left Input Adapter node for it if (node.Deftemplate is InitialFact) { try { IFLIANode lian = new IFLIANode(engine.nextNodeId()); node.addSuccessorNode(lian, engine, engine.workingMem); } catch (AssertException e) { } } }
/// <summary> Method will call checkFacts() first to make sure none of the facts have /// expired. An activation is only created if the facts are valid. /// </summary> /// <param name="">facts /// </param> /// <param name="">engine /// /// </param> public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem) { // first check the facts and make sure they didn't expire if (checkFacts(inx, engine, mem)) { LinkedActivation act = new LinkedActivation(theRule, inx); act.TerminalNode = this; if (temporal) { engine.fireActivation(act); } else { IGenericMap <Object, Object> tmem = (IGenericMap <Object, Object>)mem.getTerminalMemory(this); tmem.Put(inx, act); // Add the activation to the current module's activation list. engine.Agenda.addActivation(act); } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); // need to think the getLeftValues through better to // account for cases when a join has no bindings NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(inx); if (objs != null && objs.Length > 0) { for (int idx = 0; idx < objs.Length; idx++) { IFact rfcts = (IFact)objs[idx]; // now we propogate propogateAssert(linx.add(rfcts), engine, mem); } } }