/// <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; }
public void templateBody(IList slots) { Token sname; int stype; int sid; Slot sl; MultiSlot msl; Object defaultvalue; if (jj_2_8(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.LBRACE); jj_consume_token(CLIPSParserConstants_Fields.SLOT); sname = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); stype = slotType(); defaultvalue = defaultValue(); jj_consume_token(CLIPSParserConstants_Fields.RBRACE); sid = slots.Count; sl = new Slot(sname.image); sl.Id = sid; sl.ValueType = stype; slots.Add(sl); sname = null; } else if (jj_2_9(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.LBRACE); jj_consume_token(CLIPSParserConstants_Fields.MULTISLOT); sname = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); jj_consume_token(CLIPSParserConstants_Fields.RBRACE); sid = slots.Count; msl = new MultiSlot(sname.image); msl.Id = sid; slots.Add(msl); sname = null; } else { jj_consume_token(- 1); throw new ParseException(); } }
/// <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; }
/* assert body */ public void assertContents(ArrayList tokens) { Token exp; Object body = null; mcc_consume_token(LBRACE); exp = mcc_consume_token(IDENTIFIER); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: case BIND: case BIND3: case BIND4: case TRUE: case TRUE2: case FALSE: case FALSE2: case IDENTIFIER: case PATH_LITERAL: body = checkMultiSlot(); break; default: mcc_la1[20] = mcc_gen; ; break; } mcc_consume_token(RBRACE); if (body != null) { if (body.GetType().IsArray) { MultiSlot msl = new MultiSlot(exp.image); msl.Value = body; tokens.Add(msl); } else { Slot s = new Slot(exp.image); s.Value = body; tokens.Add(s); } } exp.Clear(); exp = null; body = null; }
/* 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"); }
/* (non-Javadoc) * @see woolfel.engine.rete.Parameter#reset() */ public override void reset() { slot = null; }
public Deftemplate(String name, String defclass, Slot[] slots, ITemplate parent) : this(name, defclass, slots) { this.parent = parent; }
/// <summary> /// </summary> /// <param name="">util /// /// </param> public virtual void compileBinding(Rule.IRule util) { List<object> list = new List<Object>(); for (int idx = 0; idx < slots.Length; idx++) { if (slots[idx].Value is BoundParam) { hasBinding_Renamed_Field = true; list.Add(slots[idx]); BoundParam bp = (BoundParam) slots[idx].Value; Binding bd = util.getBinding(bp.VariableName); if (bd != null) { bp.rowId = bd.LeftRow; bp.column = bd.LeftIndex; } } } if (list.Count > 0) { Slot[] ary = new Slot[list.Count]; list.CopyTo(ary,0); boundSlots = ary; } }
public virtual IFact createFact(Object[] data, long id) { Slot[] values = cloneAllSlots(); List<Object> bslots = new List<Object>(); bool hasbinding = false; for (int idz = 0; idz < data.Length; idz++) { Slot s = (Slot) data[idz]; for (int idx = 0; idx < values.Length; idx++) { if (values[idx].Name.Equals(s.Name)) { if (s is MultiSlot) { // since the value is multislot, we have to // check for boundparams MultiSlot ms = (MultiSlot) s; Object[] mvals = (Object[]) ms.Value; for (int mdx = 0; mdx < mvals.Length; mdx++) { if (mvals[mdx] is BoundParam) { bslots.Add((MultiSlot) ms.Clone()); hasbinding = true; break; } } values[idx].Value = s.Value; } else { if (s.Value == null) { values[idx].Value = Constants.NIL_SYMBOL; } else if (values[idx].ValueType == Constants.STRING_TYPE && !(s.Value is BoundParam)) { values[idx].Value = s.Value.ToString(); } else if (s.Value is BoundParam) { values[idx].Value = s.Value; bslots.Add((Slot) s.Clone()); hasbinding = true; } else { values[idx].Value = s.Value; } } break; } } } Deffact newfact = new Deffact(this, null, values, id); if (hasbinding) { Slot[] slts2 = new Slot[bslots.Count]; bslots.CopyTo(slts2,0); newfact.boundSlots = slts2; newfact.hasBinding_Renamed_Field = true; } // we call this to create the string used to map the fact. newfact.equalityIndex(); return newfact; }
public Deftemplate(String name, String defclass, Slot[] slots) { templateName = name; this.defclass = defclass; this.slots = slots; }
/// <summary> clone the slots /// /// </summary> /// <returns> /// /// </returns> public virtual Slot[] cloneAllSlots() { Slot[] cloned = new Slot[slots.Length]; for (int idx = 0; idx < cloned.Length; idx++) { cloned[idx] = (Slot) slots[idx].Clone(); } return cloned; }
public static bool isTemporalAttribute(Slot s) { if (s.Name.Equals(TemporalFact_Fields.EXPIRATION) || s.Name.Equals(TemporalFact_Fields.SERVICE_TYPE) || s.Name.Equals(TemporalFact_Fields.SOURCE) || s.Name.Equals(TemporalFact_Fields.VALIDITY)) { return true; } else { return false; } }
/// <summary> /// </summary> /// <param name="">type /// </param> /// <param name="">slot /// /// </param> public SlotParam(Slot slot) { InitBlock(); this.slot = slot; }
/* 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"); }
public TemporalDeffact(Deftemplate template, Object instance, Slot[] values, long id) : base(template, instance, values, id) { }
/* assert body */ public void assertContents(IList tokens) { Token exp; Object body = null; jj_consume_token(CLIPSParserConstants_Fields.LBRACE); exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.INTEGER_LITERAL: case CLIPSParserConstants_Fields.FLOATING_POINT_LITERAL: case CLIPSParserConstants_Fields.STRING_LITERAL: case CLIPSParserConstants_Fields.BIND: case CLIPSParserConstants_Fields.BIND3: case CLIPSParserConstants_Fields.BIND4: case CLIPSParserConstants_Fields.TRUE: case CLIPSParserConstants_Fields.TRUE2: case CLIPSParserConstants_Fields.FALSE: case CLIPSParserConstants_Fields.FALSE2: case CLIPSParserConstants_Fields.IDENTIFIER: case CLIPSParserConstants_Fields.PATH_LITERAL: body = checkMultiSlot(); break; default: jj_la1[20] = jj_gen; ; break; } jj_consume_token(CLIPSParserConstants_Fields.RBRACE); if (body != null) { if (body.GetType().IsArray) { MultiSlot msl = new MultiSlot(exp.image); msl.Value = body; tokens.Add(msl); } else { Slot s = new Slot(exp.image); s.Value = body; tokens.Add(s); } } exp.clear(); exp = null; body = null; }
/// <summary> A convienance method to clone slots /// </summary> public override Object Clone() { Slot newslot = new Slot(); newslot.Id = Id; newslot.Name = Name; newslot._value = _value; newslot.ValueType = ValueType; return newslot; }
/// <summary> update the slots /// </summary> public virtual void updateSlots(Rete engine, Slot[] updates) { for (int idx = 0; idx < updates.Length; idx++) { Slot uslot = updates[idx]; if (uslot.Value is BoundParam) { BoundParam bp = (BoundParam) uslot.Value; Object val = engine.getBinding(bp.VariableName); slots[uslot.Id].Value = val; } else { slots[uslot.Id].Value = uslot.Value; } } timeStamp_Renamed_Field = (DateTime.Now.Ticks - 621355968000000000)/10000; }
public void templateBody(ArrayList slots) { Token sname; int stype; int sid; Slot sl; MultiSlot msl; Object defaultvalue; if (mcc_2_8(2147483647)) { mcc_consume_token(LBRACE); mcc_consume_token(SLOT); sname = mcc_consume_token(IDENTIFIER); stype = slotType(); defaultvalue = defaultValue(); mcc_consume_token(RBRACE); sid = slots.Count; sl = new Slot(sname.image); sl.Id = sid; sl.ValueType = stype; sl.Value = defaultvalue; slots.Add(sl); sname = null; } else if (mcc_2_9(2147483647)) { mcc_consume_token(LBRACE); mcc_consume_token(MULTISLOT); sname = mcc_consume_token(IDENTIFIER); mcc_consume_token(RBRACE); sid = slots.Count; msl = new MultiSlot(sname.image); msl.Id = sid; slots.Add(msl); sname = null; } else { mcc_consume_token(-1); throw new ParseException(); } }
/// <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; }
/// <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; }