コード例 #1
0
 /// <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;
 }
コード例 #2
0
 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();
     }
 }
コード例 #3
0
 /// <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;
 }
コード例 #4
0
 /* 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;
 }
コード例 #5
0
        /* 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");
        }
コード例 #6
0
 /* (non-Javadoc)
 * @see woolfel.engine.rete.Parameter#reset()
 */
 public override void reset()
 {
     slot = null;
 }
コード例 #7
0
 public Deftemplate(String name, String defclass, Slot[] slots, ITemplate parent)
     : this(name, defclass, slots)
 {
     this.parent = parent;
 }
コード例 #8
0
 /// <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;
     }
 }
コード例 #9
0
 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;
 }
コード例 #10
0
 public Deftemplate(String name, String defclass, Slot[] slots)
 {
     templateName = name;
     this.defclass = defclass;
     this.slots = slots;
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 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;
     }
 }
コード例 #13
0
 /// <summary> 
 /// </summary>
 /// <param name="">type
 /// </param>
 /// <param name="">slot
 /// 
 /// </param>
 public SlotParam(Slot slot)
 {
     InitBlock();
     this.slot = slot;
 }
コード例 #14
0
        /* 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");
        }
コード例 #15
0
 public TemporalDeffact(Deftemplate template, Object instance, Slot[] values, long id)
     : base(template, instance, values, id)
 {
 }
コード例 #16
0
        /* 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;
        }
コード例 #17
0
 /// <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;
 }
コード例 #18
0
 /// <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;
 }
コード例 #19
0
 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();
     }
 }
コード例 #20
0
 /// <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;
 }
コード例 #21
0
 /// <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;
 }