/// <summary> /// </summary> /// <param name="">cond /// </param> /// <param name="">templ /// </param> /// <param name="">engine /// </param> /// <returns> /// /// </returns> public static IFact generateDeffact(ObjectCondition cond, Deftemplate templ, Rete.Rete engine) { List<object> list = new List<Object>(); IConstraint[] cnstr = cond.Constraints; for (int idx = 0; idx < cnstr.Length; idx++) { IConstraint cn = cnstr[idx]; if (cn is LiteralConstraint) { Slot s = new Slot(cn.Name, cn.Value); list.Add(s); } else if (cn is PredicateConstraint) { PredicateConstraint pc = (PredicateConstraint) cn; Object val = generatePredicateValue(pc); Slot s = new Slot(cn.Name, val); list.Add(s); } else if (cn is BoundConstraint) { // for now we do the simple thing and just set // any bound slots to 1 Slot s = new Slot(cn.Name, 1); list.Add(s); } } IFact f = templ.createFact(list, engine.nextFactId()); return f; }
/// <summary> this is the default constructor /// </summary> /// <param name="">instance /// </param> /// <param name="">values /// /// </param> public Deffact(Deftemplate template, Object instance, Slot[] values, long id) { deftemplate = template; objInstance = instance; slots = values; this.id = id; timeStamp_Renamed_Field = (DateTime.Now.Ticks - 621355968000000000)/10000; }
/// <summary> find the matching fact in the array /// </summary> /// <param name="">temp /// </param> /// <param name="">facts /// </param> /// <returns> /// /// </returns> public static IFact findFact(Deftemplate temp, IFact[] facts) { IFact ft = null; for (int idx = 0; idx < facts.Length; idx++) { if (facts[idx].Deftemplate == temp) { ft = facts[idx]; } } return(ft); }
/// <summary> find a parent template using the string template name /// </summary> public virtual ITemplate findParentTemplate(String key) { Deftemplate tmpl = null; IEnumerator itr = deftemplates.Keys.GetEnumerator(); while (itr.MoveNext()) { Object keyval = itr.Current; Deftemplate entry = (Deftemplate)deftemplates.Get(keyval); if (entry.Name.Equals(key)) { tmpl = entry; break; } } return(tmpl); }
/// <summary> /// create the deftemplate for the defclass /// </summary> /// <param name="tempName">Name of the temp.</param> /// <returns></returns> public virtual Deftemplate createDeftemplate(String tempName) { Slot[] st = new Slot[PROPS.Length]; for (int idx = 0; idx < st.Length; idx++) { if (PROPS[idx].PropertyType.IsArray) { st[idx] = new MultiSlot(PROPS[idx].Name); st[idx].Id = idx; } else { st[idx] = new Slot(PROPS[idx].Name); st[idx].ValueType = ConversionUtils.getTypeCode(PROPS[idx].PropertyType); // set the column id for the slot st[idx].Id = idx; } } Deftemplate temp = new Deftemplate(tempName, OBJECT_CLASS.FullName, st); return(temp); }
/// <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); } } }
/// <summary> this will make sure the fact is GC immediately /// </summary> public virtual void clear() { deftemplate = null; objInstance = null; slots = null; id = 0; timeStamp_Renamed_Field = 0; }
public TemporalDeffact(Deftemplate template, Object instance, Slot[] values, long id) : base(template, instance, values, id) { }
/* templateExpr gets the slots of a deftemplate */ public Deftemplate templateExpr() { Token exp; Deftemplate template; IList slots = new ArrayList(); /* javacc gives a warning for this, but not sure how to do it better */ exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); while (true) { templateBody(slots); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.LBRACE: ; break; default: jj_la1[30] = jj_gen; //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"' goto label_16_brk; } } //UPGRADE_NOTE: Label 'label_16_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"' label_16_brk: ; Slot[] s = new Slot[slots.Count]; slots.CopyTo(s,0); template = new Deftemplate(exp.image, null, s); slots.Clear(); exp.clear(); exp = null; { if (true) return template; } throw new ApplicationException("Missing return statement in function"); }
/// <summary> /// create the deftemplate for the defclass /// </summary> /// <param name="tempName">Name of the temp.</param> /// <returns></returns> public virtual Deftemplate createDeftemplate(String tempName) { Slot[] st = new Slot[PROPS.Length]; for (int idx = 0; idx < st.Length; idx++) { if (PROPS[idx].PropertyType.IsArray) { st[idx] = new MultiSlot(PROPS[idx].Name); st[idx].Id = idx; } else { st[idx] = new Slot(PROPS[idx].Name); st[idx].ValueType = ConversionUtils.getTypeCode(PROPS[idx].PropertyType); // set the column id for the slot st[idx].Id = idx; } } Deftemplate temp = new Deftemplate(tempName, OBJECT_CLASS.FullName, st); return temp; }
/// <summary> The method uses Defclass, Class, Deftemplate and Rete to create a new /// instance of the java object. Once the instance is created, the method /// uses Defclass to look up the write method and calls it with the /// appropriate value. /// </summary> /// <param name="">cond /// </param> /// <param name="">templ /// </param> /// <param name="">engine /// </param> /// <returns> /// /// </returns> public static Object generateJavaFacts(ObjectCondition cond, Deftemplate templ, Rete.Rete engine) { try { Type theclz = Type.GetType(templ.ClassName); Defclass dfc = engine.findDefclass(theclz); Object data = CreateNewInstance(theclz); IConstraint[] cnstr = cond.Constraints; for (int idx = 0; idx < cnstr.Length; idx++) { IConstraint cn = cnstr[idx]; if (cn is LiteralConstraint) { MethodInfo meth = dfc.getWriteMethod(cn.Name); meth.Invoke(data, (Object[]) new Object[] {cn.Value}); } } // for now the method doesn't inspect the bindings // later on it needs to be added return data; } catch (UnauthorizedAccessException e) { return null; } catch (ArgumentException e) { return null; } catch (TargetInvocationException e) { return null; } catch (Exception e) { return null; } }
/// <summary> TODO - need to finish implementing this /// </summary> public virtual Deftemplate cloneDeftemplate() { Deftemplate dt = new Deftemplate(templateName, defclass, slots); return(dt); }
/// <summary> TODO - need to finish implementing this /// </summary> public virtual Deftemplate cloneDeftemplate() { Deftemplate dt = new Deftemplate(templateName, defclass, slots); return dt; }
/// <summary> convert the SlotParam to Slot objects /// </summary> /// <param name="">params /// </param> /// <returns> /// /// </returns> public virtual Slot[] convertToSlots(IParameter[] params_Renamed, Deftemplate templ) { Slot[] slts = new Slot[params_Renamed.Length]; for (int idx = 0; idx < params_Renamed.Length; idx++) { slts[idx] = ((SlotParam) params_Renamed[idx]).SlotValue; int col = templ.getColumnIndex(slts[idx].Name); if (col != - 1) { slts[idx].Id = col; } } return slts; }
/* templateExpr gets the slots of a deftemplate */ public Deftemplate templateExpr() { Token exp; Deftemplate template; ArrayList slots = new ArrayList(); /* javacc gives a warning for this, but not sure how to do it better */ exp = mcc_consume_token(IDENTIFIER); while (true) { templateBody(slots); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case LBRACE: ; break; default: mcc_la1[30] = mcc_gen; goto label_16; } } label_16: ; Slot[] s = new Slot[slots.Count]; slots.CopyTo(s); template = new Deftemplate(exp.image, null, s); slots.Clear(); exp.Clear(); exp = null; { if (true) return template; } throw new Exception("Missing return statement in function"); }
private void InitBlock() { defclass = CollectionFactory.localMap(); templateToDefclass = CollectionFactory.localMap(); functions = CollectionFactory.localMap(); outputStreams = CollectionFactory.localMap(); listeners = new List<Object>(); functionGroups = new List<Object>(); //log = new Log4netLogger(typeof (Rete)); router = new MessageRouter(this); initFact = new InitialFact(); deffunctions = new DeffunctionGroup(); root = new RootNode(); rulesFired = CollectionFactory.localMap(); }
/// <summary> find the matching fact in the array /// </summary> /// <param name="">temp /// </param> /// <param name="">facts /// </param> /// <returns> /// /// </returns> public static IFact findFact(Deftemplate temp, IFact[] facts) { IFact ft = null; for (int idx = 0; idx < facts.Length; idx++) { if (facts[idx].Deftemplate == temp) { ft = facts[idx]; } } return ft; }