public void testAssertLeftOne() { // first create a rule engine instance Rete engine = new Rete(); NotJoin bn = new NotJoin(engine.nextNodeId()); Assert.IsNotNull(bn); // create a defclass Defclass dc = new Defclass(typeof(TestBean2)); // create deftemplate Deftemplate dtemp = dc.createDeftemplate("testBean2"); Assert.IsNotNull(dtemp); Binding[] binds = new Binding[1]; Binding b1 = new Binding(); b1.LeftIndex = (0); b1.IsObjectVar = (false); b1.LeftRow = (0); b1.RightIndex = (0); b1.VarName = ("var1"); binds[0] = b1; // set the binding bn.Bindings = (binds); TestBean2 bean = new TestBean2(); bean.Attr1 = ("random1"); bean.Attr2 = (101); short s = 10001; bean.Attr3 = (s); long l = 10101018; bean.Attr4 = (l); bean.Attr5 = (1010101); bean.Attr6 = (1001.1001); IFact f1 = dtemp.createFact(bean, dc, engine.nextFactId()); try { bn.assertLeft(new Index(new IFact[] { f1 }), engine, engine.WorkingMemory); IGenericMap <Object, Object> bmem = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(bn); Assert.AreEqual(1, bmem.Count); } catch (AssertException e) { Console.WriteLine(e.Message); } engine.close(); }
public void testCreateDeffactWithPrimitive() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); bean.Attr1 = ("testString"); IFact fact = dtemp.createFact(bean, dc, 1); Assert.IsNotNull(fact); Console.WriteLine(fact.toFactString()); }
/// <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); }
public void testOneSlot() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); Slot[] slts = dtemp.AllSlots; ObjectTypeNode otn = new ObjectTypeNode(1, dtemp); AlphaNode an = new AlphaNode(1); slts[0].Value = ConversionUtils.convert(110); an.Operator = Constants.EQUAL; an.Slot = (slts[0]); Console.WriteLine("node::" + an.ToString()); Assert.IsNotNull(an.ToString(), "Should have a value."); }
/// <summary> Configure will lookup the function and set it /// </summary> public virtual void configure(Rete.Rete engine, IRule util) { if (functionName != null && engine.findFunction(functionName) != null) { faction = engine.findFunction(functionName); } // now setup the BoundParameters if there are any for (int idx = 0; idx < parameters.Length; idx++) { if (parameters[idx] is BoundParam) { BoundParam bp = (BoundParam)parameters[idx]; Binding bd = util.getBinding(bp.VariableName); if (bd != null) { bp.Row = bd.LeftRow; bp.Column = bd.LeftIndex; } } else if (parameters[idx] is FunctionParam2) { FunctionParam2 fp2 = (FunctionParam2)parameters[idx]; fp2.configure(engine, util); } else if (parameters[idx] is ValueParam) { ValueParam vp = (ValueParam)parameters[idx]; // if the value is a deffact, we need to check and make sure // the slots with BoundParam value are compiled properly if (vp.Value is Deffact) { ((Deffact)vp.Value).compileBinding(util); } } } // in the case of Assert, we do further compilation if (faction is AssertFunction) { Deftemplate tmpl = (Deftemplate)engine.CurrentFocus.getTemplate(parameters[0].StringValue); Deffact fact = (Deffact)tmpl.createFact((Object[])parameters[1].Value, -1); fact.compileBinding(util); parameters = new ValueParam[1]; parameters[0] = new ValueParam(Constants.OBJECT_TYPE, fact); } }
public void testCreateTemplateSlot() { String acc = "account"; Defclass dc = new Defclass(typeof(Account)); Deftemplate dtemp = dc.createDeftemplate(acc); Assert.IsNotNull(dtemp); Assert.IsNotNull(dtemp.toPPString()); Assert.AreEqual(acc, dtemp.Name); Console.WriteLine(dtemp.toPPString()); Slot[] theslots = dtemp.AllSlots; for (int idx = 0; idx < theslots.Length; idx++) { Slot aslot = theslots[idx]; Assert.AreEqual(idx, aslot.Id); Console.WriteLine("slot id: " + aslot.Id); } }
protected void parse(Rete engine, CLIPSParser parser, IList factlist) { Object itm = null; try { while ((itm = parser.basicExpr()) != null) { // System.Console.WriteLine("obj is " + itm.getClass().Name); if (itm is Defrule) { Defrule rule = (Defrule)itm; engine.RuleCompiler.addRule(rule); } else if (itm is Deftemplate) { Deftemplate dt = (Deftemplate)itm; Console.WriteLine("template=" + dt.Name); engine.declareTemplate(dt); } else if (itm is FunctionAction) { FunctionAction fa = (FunctionAction)itm; } else if (itm is IFunction) { IReturnVector rv = ((IFunction)itm).executeFunction(engine, null); IEnumerator itr = rv.Iterator; while (itr.MoveNext()) { IReturnValue rval = (IReturnValue)itr.Current; Console.WriteLine(rval.StringValue); } } } } catch { // Console.WriteLine(e.Message); parser.ReInit(Console.OpenStandardInput()); } }
public void testCreateFactFromInstance() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); bean.Attr1 = ("random1"); bean.Attr2 = (101); short s = 10001; bean.Attr3 = (s); long l = 10101018; bean.Attr4 = (l); bean.Attr5 = (1010101); bean.Attr6 = (1001.1001); IFact fact = dtemp.createFact(bean, dc, 0); Assert.IsNotNull(fact); Console.WriteLine(fact.toFactString()); }
public void testSingleBinding() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); Slot[] slts = dtemp.AllSlots; Binding bn = new Binding(); bn.LeftRow = (0); bn.LeftIndex = (0); bn.RightIndex = (0); Binding[] binds = { bn }; HashedEqBNode btnode = new HashedEqBNode(1); btnode.Bindings = (binds); Console.WriteLine("betaNode::" + btnode.toPPString()); Assert.IsNotNull(btnode.toPPString()); }
/// <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); } }
public void testDeclareClass() { Rete engine = new Rete(); Assert.IsNotNull(engine); engine.declareObject(typeof(Account)); int count = engine.Defclasses.Count; Assert.AreEqual(1, count); Console.WriteLine("number of Defclass is " + count); ICollection <object> templates = engine.CurrentFocus.Templates; Assert.AreEqual(2, templates.Count); IEnumerator itr = templates.GetEnumerator(); while (itr.MoveNext()) { Deftemplate dtemp = (Deftemplate)itr.Current; Console.WriteLine(dtemp.toPPString()); } Console.WriteLine("--------------------------------"); engine.close(); }
public void testSlotID() { Slot[] slots = new Slot[4]; slots[0] = new Slot(); slots[0].Id = (0); slots[0].Name = ("col1"); slots[0].ValueType = (Constants.INT_PRIM_TYPE); slots[1] = new Slot(); slots[1].Id = (1); slots[1].Name = ("col2"); slots[1].ValueType = (Constants.DOUBLE_PRIM_TYPE); slots[2] = new Slot(); slots[2].Id = (2); slots[2].Name = ("col3"); slots[2].ValueType = (Constants.OBJECT_TYPE); slots[3] = new Slot(); slots[3].Id = (3); slots[3].Name = ("col4"); slots[3].ValueType = (Constants.LONG_PRIM_TYPE); Deftemplate dtemp = new Deftemplate("template1", null, slots); Assert.IsNotNull(dtemp); Assert.AreEqual(4, dtemp.NumberOfSlots); Console.WriteLine(dtemp.toPPString()); Slot[] theslots = dtemp.AllSlots; for (int idx = 0; idx < theslots.Length; idx++) { Slot aslot = theslots[idx]; Assert.AreEqual(idx, aslot.Id); Console.WriteLine("slot id: " + aslot.Id); } }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { bool add = true; if (params_Renamed.Length == 1 && params_Renamed[0].Value is Deftemplate) { Deftemplate tpl = (Deftemplate)params_Renamed[0].Value; IModule mod = tpl.checkName(engine); if (mod == null) { mod = engine.CurrentFocus; } mod.addTemplate(tpl, engine, engine.WorkingMemory); } else { add = false; } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, add); ret.addReturnValue(rv); return(ret); }
public void testTwoSlots() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); Slot[] slts = dtemp.AllSlots; ObjectTypeNode otn = new ObjectTypeNode(1, dtemp); AlphaNode an1 = new AlphaNode(1); AlphaNode an2 = new AlphaNode(1); slts[0].Value = ("testString"); slts[1].Value = (ConversionUtils.convert(999)); an1.Slot = (slts[0]); an1.Operator = (Constants.EQUAL); Console.WriteLine("node::" + an1.toPPString()); Assert.IsNotNull(an1.toPPString()); an2.Slot = (slts[1]); an2.Operator = (Constants.GREATER); Console.WriteLine("node::" + an2.toPPString()); Assert.IsNotNull(an2.toPPString()); }
public void testFiveFacts() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); bean.Attr1 = "testString"; bean.Attr2 = 1; short a3 = 3; bean.Attr3 = a3; long a4 = 101; bean.Attr4 = a4; float a5 = 10101; bean.Attr5 = a5; double a6 = 101.101; bean.Attr6 = a6; TestBean2 bean2 = new TestBean2(); bean2.Attr1 = "testString2"; bean2.Attr2 = 12; short a32 = 32; bean2.Attr3 = a32; long a42 = 1012; bean2.Attr4 = a42; float a52 = 101012; bean2.Attr5 = a52; double a62 = 101.1012; bean2.Attr6 = a62; TestBean2 bean3 = new TestBean2(); bean3.Attr1 = "testString3"; bean3.Attr2 = 13; short a33 = 33; bean3.Attr3 = a33; long a43 = 1013; bean3.Attr4 = a43; float a53 = 101013; bean3.Attr5 = a53; double a63 = 101.1013; bean3.Attr6 = a63; TestBean2 bean4 = new TestBean2(); bean4.Attr1 = "testString4"; bean4.Attr2 = 14; short a34 = 34; bean4.Attr3 = a34; long a44 = 1014; bean4.Attr4 = a44; float a54 = 101014; bean4.Attr5 = a54; double a64 = 101.1014; bean4.Attr6 = a64; TestBean2 bean5 = new TestBean2(); bean5.Attr1 = "testString5"; bean5.Attr2 = 15; short a35 = 35; bean5.Attr3 = a35; long a45 = 1015; bean5.Attr4 = a45; float a55 = 101015; bean5.Attr5 = a55; double a65 = 101.1015; bean5.Attr6 = a65; IFact fact = dtemp.createFact(bean, dc, 1); IFact fact2 = dtemp.createFact(bean2, dc, 1); IFact fact3 = dtemp.createFact(bean3, dc, 1); IFact fact4 = dtemp.createFact(bean4, dc, 1); IFact fact5 = dtemp.createFact(bean5, dc, 1); IFact[] list1 = new IFact[] { fact, fact2, fact3, fact4, fact5 }; IFact[] list2 = new IFact[] { fact, fact2, fact3, fact4, fact5 }; Index in1 = new Index(list1); Index in2 = new Index(list2); Assert.AreEqual(true, in1.Equals(in2)); }
public void testPropogateNoMatch() { Console.WriteLine("testPropogateNoMatch"); // first create a rule engine instance Rete engine = new Rete(); NotJoin nj = new NotJoin(engine.nextNodeId()); HashedEqBNode bn2 = new HashedEqBNode(engine.nextNodeId()); Assert.IsNotNull(nj); // create a defclass Defclass dc = new Defclass(typeof(TestBean2)); // create deftemplate Deftemplate dtemp = dc.createDeftemplate("testBean2"); Assert.IsNotNull(dtemp); Binding[] binds = new Binding[1]; Binding b1 = new Binding(); b1.LeftIndex = (0); b1.IsObjectVar = (false); b1.LeftRow = (0); b1.RightIndex = (0); b1.VarName = ("var1"); binds[0] = b1; Binding[] binds2 = new Binding[1]; Binding b2 = new Binding(); b2.LeftIndex = (1); b2.IsObjectVar = (false); b2.LeftRow = (0); b2.RightIndex = (1); b2.VarName = ("var2"); binds2[0] = b2; // set the binding nj.Bindings = (binds); bn2.Bindings = (binds2); // now add the second Not to the first try { nj.addSuccessorNode(bn2, engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } int count = 10; ArrayList data = new ArrayList(); for (int idx = 0; idx < count; idx++) { TestBean2 bean = new TestBean2(); bean.Attr1 = ("random" + idx); bean.Attr2 = (101 + idx); short s = 10001; bean.Attr3 = (s); long l = 10101018 + idx; bean.Attr4 = (l); bean.Attr5 = (1010101); bean.Attr6 = (1001.1001); IFact fact = dtemp.createFact(bean, dc, engine.nextFactId()); data.Add(fact); } IEnumerator itr = data.GetEnumerator(); while (itr.MoveNext()) { try { IFact f1 = (IFact)itr.Current; nj.assertLeft(new Index(new IFact[] { f1 }), engine, engine.WorkingMemory); nj.assertRight(f1, engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } } IGenericMap <IFact, IFact> rbmem = (IGenericMap <IFact, IFact>)engine.WorkingMemory.getBetaRightMemory(nj); Assert.AreEqual(count, rbmem.Count); IGenericMap <Object, Object> lbmem = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(nj); Assert.AreEqual(count, lbmem.Count); // now check the BetaMemory has matches Console.WriteLine(nj.toPPString()); IEnumerator mitr = lbmem.Values.GetEnumerator(); while (mitr.MoveNext()) { IBetaMemory btm = (IBetaMemory)mitr.Current; Assert.AreEqual(0, btm.matchCount()); Console.WriteLine("match count=" + btm.matchCount() + " - " + btm.toPPString()); } IGenericMap <Object, Object> lbmem2 = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(bn2); Assert.AreEqual(count, lbmem2.Count); Console.WriteLine(bn2.toPPString()); IEnumerator mitr2 = lbmem2.Values.GetEnumerator(); engine.close(); // TODO need to update the test to check the match count // by getting the right memory }
public void testPropogateChange() { Console.WriteLine("testPropogateChange"); // first create a rule engine instance Rete engine = new Rete(); NotJoin nj = new NotJoin(engine.nextNodeId()); HashedEqBNode bn2 = new HashedEqBNode(engine.nextNodeId()); Assert.IsNotNull(nj); // create a defclass Defclass dc = new Defclass(typeof(TestBean2)); // create deftemplate Deftemplate dtemp = dc.createDeftemplate("testBean2"); Assert.IsNotNull(dtemp); Binding[] binds = new Binding[1]; Binding b1 = new Binding(); b1.LeftIndex = (0); b1.IsObjectVar = (false); b1.LeftRow = (0); b1.RightIndex = (0); b1.VarName = ("var1"); binds[0] = b1; Binding[] binds2 = new Binding[1]; Binding b2 = new Binding(); b2.LeftIndex = (1); b2.IsObjectVar = (false); b2.LeftRow = (0); b2.RightIndex = (1); b2.VarName = ("var2"); binds2[0] = b2; // set the binding nj.Bindings = (binds); bn2.Bindings = (binds2); // now add the second Not to the first try { nj.addSuccessorNode(bn2, engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } int count = 2; ArrayList data = new ArrayList(); for (int idx = 0; idx < count; idx++) { TestBean2 bean = new TestBean2(); bean.Attr1 = ("random"); bean.Attr2 = (101 + idx); short s = 10001; bean.Attr3 = (s); long l = 10101018 + idx; bean.Attr4 = (l); bean.Attr5 = (1010101); bean.Attr6 = (1001.1001); IFact fact = dtemp.createFact(bean, dc, engine.nextFactId()); data.Add(fact); } IEnumerator itr = data.GetEnumerator(); while (itr.MoveNext()) { try { IFact f1 = (IFact)itr.Current; nj.assertLeft(new Index(new IFact[] { f1 }), engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } } IGenericMap <Object, Object> lbmem = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(nj); Assert.AreEqual(count, lbmem.Count); IGenericMap <Object, Object> lbmem2 = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(bn2); Assert.AreEqual(2, lbmem2.Count); itr = data.GetEnumerator(); while (itr.MoveNext()) { try { IFact f1 = (IFact)itr.Current; nj.assertRight(f1, engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } } IGenericMap <IFact, IFact> rbmem = (IGenericMap <IFact, IFact>)engine.WorkingMemory.getBetaRightMemory(nj); Assert.AreEqual(count, rbmem.Count); // once the facts are asserted to the right, there should be no // facts in successor. this makes sure that assertRight correctly // results in a retract. lbmem2 = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(bn2); Assert.AreEqual(0, lbmem2.Count); engine.close(); }
public void testMatch() { // first create a rule engine instance Rete engine = new Rete(); NotJoin bn = new NotJoin(engine.nextNodeId()); Assert.IsNotNull(bn); // create a defclass Defclass dc = new Defclass(typeof(TestBean2)); // create deftemplate Deftemplate dtemp = dc.createDeftemplate("testBean2"); Assert.IsNotNull(dtemp); Binding[] binds = new Binding[1]; Binding b1 = new Binding(); b1.LeftIndex = (0); b1.IsObjectVar = (false); b1.LeftRow = (0); b1.RightIndex = (0); b1.VarName = ("var1"); binds[0] = b1; // set the binding bn.Bindings = (binds); int count = 10; ArrayList data = new ArrayList(); for (int idx = 0; idx < count; idx++) { TestBean2 bean = new TestBean2(); bean.Attr1 = ("random"); bean.Attr2 = (101); short s = 10001; bean.Attr3 = (s); long l = 10101018; bean.Attr4 = (l); bean.Attr5 = (1010101); bean.Attr6 = (1001.1001); IFact fact = dtemp.createFact(bean, dc, engine.nextFactId()); data.Add(fact); } IEnumerator itr = data.GetEnumerator(); while (itr.MoveNext()) { try { IFact f1 = (IFact)itr.Current; bn.assertLeft(new Index(new IFact[] { f1 }), engine, engine.WorkingMemory); bn.assertRight(f1, engine, engine.WorkingMemory); } catch (AssertException e) { Console.WriteLine(e.Message); } } IGenericMap <IFact, IFact> rbmem = (IGenericMap <IFact, IFact>)engine.WorkingMemory.getBetaRightMemory(bn); Assert.AreEqual(count, rbmem.Count); IGenericMap <Object, Object> lbmem = (IGenericMap <Object, Object>)engine.WorkingMemory.getBetaLeftMemory(bn); Assert.AreEqual(count, lbmem.Count); // now check the BetaMemory has matches Console.WriteLine(bn.toPPString()); IEnumerator mitr = lbmem.Values.GetEnumerator(); while (mitr.MoveNext()) { IBetaMemory btm = (IBetaMemory)mitr.Current; Assert.AreEqual(9, btm.matchCount()); Console.WriteLine("match count=" + btm.matchCount() + " - " + btm.toPPString()); } engine.close(); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { DefaultReturnVector rv = new DefaultReturnVector(); bool loaded = true; if (params_Renamed != null && params_Renamed.Length > 0) { for (int idx = 0; idx < params_Renamed.Length; idx++) { String input = null; if (params_Renamed[idx] is ValueParam) { input = ((ValueParam)params_Renamed[idx]).StringValue; } else if (params_Renamed[idx] is BoundParam) { } if (input.IndexOf((Char)'\\') > -1) { input.Replace("\\", "/"); } // check to see if the path is an absolute windows path // or absolute unix path if (input.IndexOf(":") < 0 && !input.StartsWith("/") && !input.StartsWith("./")) { input = "./" + input; } try { Stream inStream = null; if (Regex.IsMatch(input, "^[a-zA-Z]+://.*")) { Uri url = new Uri(input); inStream = ((HttpWebRequest)WebRequest.Create(url)).GetResponse().GetResponseStream(); // Otherwise treat it as normal file on the Filesystem } else { inStream = new FileStream(new FileInfo(input).FullName, FileMode.Open, FileAccess.Read); } CLIPSParser parser = new CLIPSParser(inStream); IList data = parser.loadExpr(); IEnumerator itr = data.GetEnumerator(); while (itr.MoveNext()) { Object val = itr.Current; ValueParam[] vp = (ValueParam[])val; Deftemplate tmpl = (Deftemplate)engine.CurrentFocus.getTemplate(vp[0].StringValue); Deffact fact = (Deffact)tmpl.createFact((Object[])vp[1].Value, -1); engine.assertFact(fact); } } catch (FileNotFoundException e) { loaded = false; engine.writeMessage(e.Message + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } catch (ParseException e) { loaded = false; engine.writeMessage(e.Message + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } catch (AssertException e) { loaded = false; engine.writeMessage(e.Message + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } catch (IOException e) { loaded = false; engine.writeMessage(e.Message + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } } } else { loaded = false; } DefaultReturnValue drv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, loaded); rv.addReturnValue(drv); return(rv); }
public void testHashMapIndex() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); bean.Attr1 = "testString"; bean.Attr2 = 1; short a3 = 3; bean.Attr3 = a3; long a4 = 101; bean.Attr4 = a4; float a5 = 10101; bean.Attr5 = a5; double a6 = 101.101; bean.Attr6 = a6; TestBean2 bean2 = new TestBean2(); bean2.Attr1 = "testString2"; bean2.Attr2 = 12; short a32 = 32; bean2.Attr3 = a32; long a42 = 1012; bean2.Attr4 = a42; float a52 = 101012; bean2.Attr5 = a52; double a62 = 101.1012; bean2.Attr6 = a62; TestBean2 bean3 = new TestBean2(); bean3.Attr1 = "testString3"; bean3.Attr2 = 13; short a33 = 33; bean3.Attr3 = a33; long a43 = 1013; bean3.Attr4 = a43; float a53 = 101013; bean3.Attr5 = a53; double a63 = 101.1013; bean3.Attr6 = a63; TestBean2 bean4 = new TestBean2(); bean4.Attr1 = "testString4"; bean4.Attr2 = 14; short a34 = 34; bean4.Attr3 = a34; long a44 = 1014; bean4.Attr4 = a44; float a54 = 101014; bean4.Attr5 = a54; double a64 = 101.1014; bean4.Attr6 = a64; TestBean2 bean5 = new TestBean2(); bean5.Attr1 = "testString5"; bean5.Attr2 = 15; short a35 = 35; bean5.Attr3 = a35; long a45 = 1015; bean5.Attr4 = a45; float a55 = 101015; bean5.Attr5 = a55; double a65 = 101.1015; bean5.Attr6 = a65; IFact fact = dtemp.createFact(bean, dc, 1); IFact fact2 = dtemp.createFact(bean2, dc, 1); IFact fact3 = dtemp.createFact(bean3, dc, 1); IFact fact4 = dtemp.createFact(bean4, dc, 1); IFact fact5 = dtemp.createFact(bean5, dc, 1); IFact[] list1 = new IFact[] { fact, fact2, fact3, fact4, fact5 }; IFact[] list2 = new IFact[] { fact, fact2, fact3, fact4, fact5 }; Index in1 = new Index(list1); Index in2 = new Index(list2); Assert.AreEqual(true, in1.Equals(in2)); GenericHashMap <object, object> map = new GenericHashMap <object, object>(); map.Put(in1, list1); // simple test to see if HashMap.ContainsKey(in1) works Assert.AreEqual(true, map.ContainsKey(in1)); // now test with the second instance of index, this should return // true, since Index class overrides Equals() and GetHashCode(). Assert.AreEqual(true, map.ContainsKey(in2)); }
/// <summary> the paramList should be clean and /// other codes surrounding this method in subclass may be removed into this method. /// Houzhanbin 10/16/2007 /// </summary> /// <param name="">condition /// </param> /// <param name="">rule /// </param> /// <param name="">Constraints /// </param> /// <param name="">position /// </param> /// <param name="">hasNotEqual /// </param> /// <param name="">hasPredicateJoin /// </param> /// <returns> /// /// </returns> internal Binding[] getBindings(ICondition condition, Rule.IRule rule, int position) { ObjectCondition oc = getObjectCondition(condition); IList Constraints = oc.BindConstraints; Deftemplate tmpl = oc.Deftemplate; Binding[] binds = new Binding[Constraints.Count]; for (int idz = 0; idz < Constraints.Count; idz++) { Object cst = Constraints[idz]; if (cst is BoundConstraint) { BoundConstraint bc = (BoundConstraint)cst; Binding cpy = rule.copyBinding(bc.VariableName); if (cpy.LeftRow >= position) { binds = new Binding[0]; break; } else { binds[idz] = cpy; int rinx = tmpl.getColumnIndex(bc.Name); // we increment the count to make sure the // template isn't removed if it is being used tmpl.incrementColumnUseCount(bc.Name); binds[idz].RightIndex = rinx; binds[idz].Negated = bc.Negated; if (bc.Negated) { oc.HasNotEqual = true; } } } else if (cst is PredicateConstraint) { PredicateConstraint pc = (PredicateConstraint)cst; if (pc.Value is BoundParam) { oc.HasPredicateJoin = true; BoundParam bpm = (BoundParam)pc.Value; String var = bpm.VariableName; int op = ConversionUtils.getOperatorCode(pc.FunctionName); // check and make sure the function isn't user defined if (op != Constants.USERDEFINED) { // if the first binding in the function is from the object type // we reverse the operator if (pc.Parameters[0] != bpm) { op = ConversionUtils.getOppositeOperatorCode(op); } binds[idz] = rule.copyPredicateBinding(var, op); ((Binding2)binds[idz]).RightVariable = pc.VariableName; } else { binds[idz] = rule.copyPredicateBinding(var, op); } binds[idz].PredJoin = true; int rinx = tmpl.getColumnIndex(pc.Name); // we increment the count to make sure the // template isn't removed if it is being used tmpl.incrementColumnUseCount(pc.Name); binds[idz].RightIndex = rinx; } else if (pc.Value is FunctionParam) { // this means there is a nested function } } } return(binds); }
public virtual int analyze(IRule rule) { int result = Analysis_Fields.VALIDATION_PASSED; error = new ErrorSummary(); warning = new WarningSummary(); checkForModule(rule); ICondition[] cnds = rule.Conditions; for (int idx = 0; idx < cnds.Length; idx++) { ICondition cnd = cnds[idx]; if (cnd is ObjectCondition) { ObjectCondition oc = (ObjectCondition)cnd; Deftemplate dft = oc.Deftemplate; if (dft != null) { IConstraint[] cntrs = oc.Constraints; for (int idy = 0; idy < cntrs.Length; idy++) { IConstraint cons = cntrs[idy]; if (cons is LiteralConstraint) { Slot sl = dft.getSlot(cons.Name); if (sl == null) { error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } else if (cons is BoundConstraint) { BoundConstraint bc = (BoundConstraint)cons; if (!bc.isObjectBinding) { Slot sl = dft.getSlot(bc.Name); if (sl == null) { error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } } else if (cons is PredicateConstraint) { PredicateConstraint pc = (PredicateConstraint)cons; IFunction f = engine.findFunction(pc.FunctionName); if (f == null) { addInvalidFunctionError(pc.FunctionName); } } } } else { error.addMessage(INVALID_TEMPLATE + " " + oc.TemplateName + " template does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } else if (cnd is TestCondition) { TestCondition tc = (TestCondition)cnd; if (tc.Function == null) { error.addMessage(NO_FUNCTION); result = Analysis_Fields.VALIDATION_FAILED; } else { IFunction f = tc.Function; if (engine.findFunction(f.Name) == null) { addInvalidFunctionError(f.Name); result = Analysis_Fields.VALIDATION_FAILED; } } } else if (cnd is ExistCondition) { } } // now we check the Right-hand side IAction[] acts = rule.Actions; for (int idx = 0; idx < acts.Length; idx++) { IAction act = acts[idx]; if (act is FunctionAction) { FunctionAction fa = (FunctionAction)act; if (engine.findFunction(fa.FunctionName) == null) { addInvalidFunctionError(fa.FunctionName); result = Analysis_Fields.VALIDATION_FAILED; } } } return(result); }