Package org.plugtree.training.model

Examples of org.plugtree.training.model.Person


    ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
  }

  public void testExecution() {
    Vehicle car1 = new Vehicle(new Person(20), VehicleType.CAR, 2006, 35000f);
    Vehicle car2 = new Vehicle(new Person(60), VehicleType.CAR, 1960, 50000f);
    Vehicle car3 = new Vehicle(new Person(34), VehicleType.CAR, 1994, 4000f);
    Vehicle moto1 = new Vehicle(new Person(16), VehicleType.MOTORCYCLE, 1993, 3230F);
    Vehicle moto2 = new Vehicle(new Person(19), VehicleType.MOTORCYCLE, 2001, 8400F);
    Vehicle moto3 = new Vehicle(new Person(29), VehicleType.MOTORCYCLE, 2010, 10000F);

    ksession.insert(car1);
    ksession.insert(car2);
    ksession.insert(car3);
    ksession.insert(moto1);
View Full Code Here


        ksession = kbase.newStatefulKnowledgeSession();
        //KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    }
    @Test
    public void testExecution() {
        Person p1 = new Person(20);
        p1.setJob(new Job(2, 3000f));
        Person p2 = new Person(18);
        p2.setJob(new Job(0, 5000f));
        Person p3 = new Person(47);
        p3.setJob(new Job(10, 4500f));
        ksession.insert(p1);
        ksession.insert(p2);
        ksession.insert(p3);
        ksession.fireAllRules();
View Full Code Here

        kagent.applyChangeSet(ResourceFactory.newUrlResource(fxml.toURI().toURL()));
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();


        ksession.setGlobal("list", list);
        ksession.insert(new Person());
        ksession.fireAllRules();

        //The rule should be fired
        assertEquals(1, list.size());
        assertTrue(list.contains("Rule1"));

        list.clear();
        kbaseUpdated = false;
       
        Thread.sleep(2000);
        //the dsl is now modified.
        f1 = fileManager.newFile("myExpander.dsl");
        output = new BufferedWriter(new FileWriter(f1));
        output.write(this.createCommonDSL("name == \"John\""));
        output.close();

        //We also need to mark the dslr file as modified, so the rules could
        //be regenerated
        f1 = fileManager.newFile("rules.drl");
        output = new BufferedWriter(new FileWriter(f1));
        output.write(header);
        output.write(this.createCommonDSLRRule("Rule1"));
        output.close();


        this.waitUntilKBaseUpdate();

        ksession.insert(new Person());
        ksession.fireAllRules();

        //The rule was modified then no rule got fired.
        assertEquals(0, list.size());

        Person p = new Person();
        p.setName("John");
        ksession.insert(p);
        ksession.fireAllRules();

        //The new fact activated and fired the modified rule
        Thread.sleep(2000);
View Full Code Here

        this.kbaseUpdated = false;
        StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();


        ksession.setGlobal("list", list);
        ksession.insert(new Person());
        ksession.fireAllRules();

        //The rule should be fired
        assertEquals(1, list.size());
        assertTrue(list.contains("Rule1"));
        list.clear();

        ksession.dispose();

        Thread.sleep(2000);
        //Let's modify the dsl file
        f1 = fileManager.newFile("myExpander.dsl");
        output = new BufferedWriter(new FileWriter(f1));
        output.write(this.createCommonDSL("name == \"John\""));
        output.close();

        //We need to mark the dslr file as modified (even when it was not) so
        //the agent could recreate the rules it contains using the new dsl.
        f1 = fileManager.newFile("rules.drl");
        output = new BufferedWriter(new FileWriter(f1));
        output.write(header);
        output.write(this.createCommonDSLRRule("Rule1"));
        output.close();

        this.waitUntilKBaseUpdate();

        //get a new ksession
        ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();

        //A Person without name shouldn't fire any rule now (because it was
        //modified)
        ksession.setGlobal("list", list);
        ksession.insert(new Person());
        ksession.fireAllRules();

        assertEquals(0, list.size());

        //A "John" Person should fire the modified rule
        Person p = new Person();
        p.setName("John");
        ksession.insert(p);
        ksession.fireAllRules();

        assertEquals(1, list.size());
        assertTrue(list.contains("Rule1"));
View Full Code Here

TOP

Related Classes of org.plugtree.training.model.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.