Package org.drools.core

Examples of org.drools.core.RuleBase


public class RuleBaseLoaderTest {

    @Test
    public void testLoadRuleBase() throws Exception {
        final InputStream in = DslTest.class.getResourceAsStream( "HelloWorld.drl" );
        final RuleBase rb = RuleBaseLoader.getInstance().loadFromReader( new InputStreamReader( in ) );
        assertNotNull( rb );
    }
View Full Code Here


    @Test
    public void testLoadRuleBaseWithDSL() throws Exception {
        final InputStream in = DslTest.class.getResourceAsStream( "rule_with_expander_dsl.dslr" );
        final InputStream inDSL = DslTest.class.getResourceAsStream( "test_expander.dsl" );
        final RuleBase rb = RuleBaseLoader.getInstance().loadFromReader( new InputStreamReader( in ),
                                                                         new InputStreamReader( inDSL ) );
        assertNotNull( rb );
    }
View Full Code Here

        // add the package to a rulebase
        RuleBaseConfiguration conf = new RuleBaseConfiguration();
        conf.setPhreakEnabled(true);
       
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
        ruleBase.addPackage(pkg);

//        for (ObjectTypeNode node : ((InternalRuleBase) ruleBase).getRete().getObjectTypeNodes()) {
//            CompiledNetwork compiledNetwork = ObjectTypeNodeCompiler.compile(builder, node);
//            node.setCompiledNetwork(compiledNetwork);
//        }

        String filename;
        if (args.length != 0) {
            String arg = args[0];
            filename = arg;
        } else {
            filename = "manners5.dat";
        }

        for (int i = 0; i < 3; ++i) {
            InputStream is = MannersBenchmark.class.getResourceAsStream(filename);
            List list = getInputObjects(is);
            StatefulSession session = ruleBase.newStatefulSession();

            for (Iterator it = list.iterator(); it.hasNext();) {
                Object object = it.next();
                session.insert(object);
            }
View Full Code Here

    org.drools.core.rule.Package pkg = builder.getPackage();
    pkg = SerializationHelper.serializeObject(pkg);

    // add the package to a rulebase
    RuleBase ruleBase = getSinglethreadRuleBase();
    ruleBase.addPackage(pkg);
    ruleBase = SerializationHelper.serializeObject(ruleBase);
    // load up the rulebase
    return ruleBase;
  }
View Full Code Here

    @Test
    public void testGetFactHandleIdentityBehavior() throws Exception {
        final RuleBaseConfiguration conf = new RuleBaseConfiguration();
        conf.setAssertBehaviour( RuleBaseConfiguration.AssertBehaviour.IDENTITY );
        RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);

        ruleBase = SerializationHelper.serializeObject( ruleBase );
        final StatefulSession session = ruleBase.newStatefulSession();

        CheeseEqual cheese = new CheeseEqual( "stilton",
                                              10 );
        session.insert( cheese );
        FactHandle fh1 = session.getFactHandle( new Cheese( "stilton",
View Full Code Here

        // add defined object types
        //FactTemplate ftEvent = new FactTemplateImpl();
        //pkg.addFactTemplate(ftEvent);

        // add the package to a rulebase (deploy the rule package).
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        try {
            ruleBase.addPackage (pkg);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        wm = ruleBase.newStatefulSession();
        // create a new Working Memory Logger, that logs to file.
        //logger = new WorkingMemoryFileLogger(wm);
        // an event.log file is created in the log dir (which must exist)
        // in the working directory
        //logger.setFileName(FILE_NAME_LOGGER);
View Full Code Here

        final org.drools.core.rule.Package pkg = builder.getPackage();

        RuleBaseConfiguration config = new RuleBaseConfiguration();
        config.setMultithreadEvaluation( true );

        RuleBase ruleBase = getRuleBase( config );
        ruleBase.addPackage( pkg );
        ruleBase = SerializationHelper.serializeObject(ruleBase);
        StatefulSession session = ruleBase.newStatefulSession();
        List result = new ArrayList();
        session.setGlobal( "results",
                           result );

        Cheese c1 = new Cheese( "stilton" );
View Full Code Here

        final Package pkg = SerializationHelper.serializeObject( builder.getPackage() );

        assertEquals( 0,
                      builder.getErrors().getErrors().length );

        RuleBase ruleBase = getRuleBase();// RuleBaseFactory.newRuleBase();

        StatefulSession session = ruleBase.newStatefulSession();

        Map map = new HashMap();
        map.put( "x",
                 ruleBase );
        map = SerializationHelper.serializeObject( map );
        ruleBase = (RuleBase) map.get( "x" );

        ruleBase.addPackage( pkg );

        session = SerializationHelper.getSerialisedStatefulSession( session,
                                                                    ruleBase );
        ruleBase = SerializationHelper.serializeObject( ruleBase );

        session.setGlobal( "list",
                           new ArrayList() );

        final Person bob = new Person( "bob" );
        session.insert( bob );

        final Rule[] rules = ruleBase.getPackages()[0].getRules();

        assertEquals( 4,
                      rules.length );

        assertEquals( "match Person 1",
View Full Code Here

        final Package pkg = SerializationHelper.serializeObject( builder.getPackage() );

        assertEquals( 0,
                      builder.getErrors().getErrors().length );

        RuleBase ruleBase = getRuleBase();// RuleBaseFactory.newRuleBase();

        // serialise a hashmap with the RuleBase as a key
        Map map = new HashMap();
        map.put( "x",
                 ruleBase );
        map = SerializationHelper.serializeObject( map );
        ruleBase = (RuleBase) map.get( "x" );

        StatefulSession session = ruleBase.newStatefulSession();

        // serialise the working memory before population
        session = SerializationHelper.getSerialisedStatefulSession( session,
                                                                    ruleBase );

        ruleBase.addPackage( pkg );

        session.setGlobal( "list",
                           new ArrayList() );

        final Person bob = new Person( "bob" );
        session.insert( bob );

        final Rule[] rules = ruleBase.getPackages()[0].getRules();

        assertEquals( 4,
                      rules.length );

        assertEquals( "match Person 1",
View Full Code Here

        final Package pkg = SerializationHelper.serializeObject( builder.getPackage() );

        assertEquals( 0,
                      builder.getErrors().getErrors().length );

        RuleBase ruleBase = getRuleBase();
        StatefulSession session = ruleBase.newStatefulSession();

        ruleBase.addPackage( pkg );

        session.setGlobal( "list",
                           new ArrayList() );

        final Person bob = new Person( "bob" );
        session.insert( bob );

        // serialise a hashmap with the RuleBase as a key, after WM population
        Map map = new HashMap();
        map.put( "x",
                 ruleBase );
        map = SerializationHelper.serializeObject( map );
        ruleBase = (RuleBase) map.get( "x" );

        // now try serialising with a fully populated wm from a serialised rulebase
        session = SerializationHelper.getSerialisedStatefulSession( session,
                                                                    ruleBase );

        final Rule[] rules = ruleBase.getPackages()[0].getRules();

        assertEquals( 4,
                      rules.length );

        assertEquals( "match Person 1",
View Full Code Here

TOP

Related Classes of org.drools.core.RuleBase

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.