Exemplo n.º 1
0
  /** Test setup. */
  protected void setUp() throws Exception {
    state = OAVStateFactory.createOAVState(Blocks.blocksworld_type_model);
    blocks = new ArrayList();

    // ?block <- (Block (color ?color))
    // (Ball (color ?color))

    // Matches a block with a color
    ObjectCondition cblock = new ObjectCondition(Blocks.block_type);
    cblock.addConstraint(new BoundConstraint(null, new Variable("block", Blocks.block_type)));
    cblock.addConstraint(
        new BoundConstraint(
            Blocks.block_has_color, new Variable("color", OAVJavaType.java_string_type)));

    // Matches a ball with the same color
    ObjectCondition samecolor = new ObjectCondition(Blocks.ball_type);
    samecolor.addConstraint(
        new BoundConstraint(
            Blocks.ball_has_color, new Variable("color", OAVJavaType.java_string_type)));

    // Add block of triggered condition to list.
    ICondition cond = new AndCondition(new ICondition[] {cblock, samecolor});
    IRule rule =
        new Rule(
            "block",
            cond,
            new IAction() {
              public void execute(IOAVState state, IVariableAssignments assigments) {
                blocks.add(assigments.getVariableValue("block"));
              }
            });

    // Create rule system.
    Rulebase rb = new Rulebase();
    system = new RuleSystem(state, rb, new RetePatternMatcherFunctionality(rb));
    system.getRulebase().addRule(rule);
    system.init();

    /*RetePanel.createReteFrame("Equal Join Test",
    	((RetePatternMatcherFunctionality)system.getMatcherFunctionality()).getReteNode(),
    	((RetePatternMatcherState)system.getMatcherState()).getReteMemory(),
    	system.getAgenda(), new Object());
    synchronized(system){system.wait();}*/

    // Add red block and green ball.
    block = state.createRootObject(Blocks.block_type);
    state.setAttributeValue(block, Blocks.block_has_color, "red");
    ball = state.createRootObject(Blocks.ball_type);
    state.setAttributeValue(ball, Blocks.ball_has_color, "green");
  }
Exemplo n.º 2
0
  /** Test setup. */
  protected void setUp() throws Exception {
    state = OAVStateFactory.createOAVState(OAVJavaType.java_type_model);
    triggered = new ArrayList();

    // test for two beans with same name:
    // (TestBean (toString () ?string))
    // (TestBean2 (toString () ?string))

    OAVJavaType clazz = OAVJavaType.java_type_model.getJavaType(TestBean.class);
    MethodCall method = new MethodCall(clazz, TestBean.class.getMethod("toString", new Class[0]));
    ObjectCondition cobject = new ObjectCondition(clazz);
    cobject.addConstraint(
        new BoundConstraint(method, new Variable("?string", OAVJavaType.java_string_type)));

    OAVJavaType clazz2 = OAVJavaType.java_type_model.getJavaType(TestBean2.class);
    MethodCall method2 =
        new MethodCall(clazz2, TestBean2.class.getMethod("toString", new Class[0]));
    ObjectCondition cobject2 = new ObjectCondition(clazz2);
    cobject2.addConstraint(
        new BoundConstraint(method2, new Variable("?string", OAVJavaType.java_string_type)));

    // Add string of triggered bean to list.
    IRule rule =
        new Rule(
            "collect_rule",
            new AndCondition(new ICondition[] {cobject, cobject2}),
            new IAction() {
              public void execute(IOAVState state, IVariableAssignments assigments) {
                Object string = assigments.getVariableValue("?string");
                triggered.add(string);
              }
            });

    // Create rule system.
    Rulebase rb = new Rulebase();
    system = new RuleSystem(state, rb, new RetePatternMatcherFunctionality(rb));
    system.getRulebase().addRule(rule);
    system.init();

    //		state.notifyEventListeners();
    //		RetePanel.createReteFrame("Collect Node Test", system, new Object());
    //		synchronized(system){system.wait();}

    bean1 = new TestBean("A");
    state.addJavaRootObject(bean1);
    bean2 = new TestBean2("B");
    state.addJavaRootObject(bean2);
  }