Package org.drools.util

Examples of org.drools.util.HierarchyEncoder


    }


    @Test
    public void testHierEncoderDecoderLower() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "Thing", Collections.EMPTY_LIST );
        encoder.encode( "A", Arrays.asList( "Thing" ) );
        encoder.encode( "Z", Arrays.asList( "Thing" ) );
        encoder.encode( "B", Arrays.asList( "A", "Z" ) );
        encoder.encode( "C", Arrays.asList( "A", "Z" ) );
        encoder.encode( "N", Arrays.asList( "B", "C" ) );
        encoder.encode( "P", Arrays.asList( "Thing" ) );
        encoder.encode( "Q", Arrays.asList( "Thing" ) );
        encoder.encode( "R", Arrays.asList( "Thing" ) );
        encoder.encode( "S", Arrays.asList( "R" ) );
        encoder.encode( "T", Arrays.asList( "C", "Q" ) );
        encoder.encode( "M", Arrays.asList( "R", "Q" ) );
        encoder.encode( "O", Arrays.asList( "M", "P" ) );

        System.out.println( encoder );

        Collection x;

        x = encoder.lowerBorder( encoder.metMembersCode( Arrays.asList( "B" ) ) );
        System.out.println( "GCS " + x );
        assertEquals( 1, x.size() );
        assertTrue( x.contains( "B" ) );

        x = encoder.immediateChildren( encoder.metMembersCode( Arrays.asList( "B" ) ) );
        System.out.println( "GCS " + x );
        assertEquals( 1, x.size() );
        assertTrue( x.contains( "N" ) );



        x = encoder.lowerBorder( encoder.metMembersCode( Arrays.asList( "Z", "Q" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "T" ) );

        x = encoder.immediateChildren( encoder.metMembersCode( Arrays.asList( "Z", "Q" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "T" ) );




        x = encoder.lowerBorder( encoder.metMembersCode( Arrays.asList( "A", "Z" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 2, x.size() );
        assertTrue( x.contains( "B" ) );
        assertTrue( x.contains( "C" ) );

        x = encoder.immediateChildren( encoder.metMembersCode( Arrays.asList( "A", "Z" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 2, x.size() );
        assertTrue( x.contains( "B" ) );
        assertTrue( x.contains( "C" ) );




        x = encoder.lowerBorder( encoder.metMembersCode( Arrays.asList( "Thing" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "Thing" ) );

        x = encoder.immediateChildren( encoder.metMembersCode( Arrays.asList( "Thing" ) ) );
        System.out.println( "GCS " + x );

        assertEquals( 5, x.size() );
        assertTrue( x.contains( "A" ) );
        assertTrue( x.contains( "Z" ) );
View Full Code Here


        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        HierarchyEncoder hier = ((ReteooRuleBase) ((KnowledgeBaseImpl) ksession.getKnowledgeBase()).getRuleBase()).getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
        System.out.println( hier );

        ksession.insert( trig );
        ksession.fireAllRules();
View Full Code Here

                case TRIPLES:   proxy = konst.newInstance( core, ruleBase.getTripleStore(), getTripleFactory() );
                    break;
                default     :   throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
            }

            HierarchyEncoder hier = ruleBase.getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();

            ((TraitProxy) proxy).setTypeCode( hier.getCode( trait.getName() ) );
            core._setBottomTypeCode( hier.getBottom() );

            core.addTrait( traitName, proxy );

            return proxy;
        } catch (InstantiationException e) {
View Full Code Here

        } else {
            Collection<Thing<K>> removedTypes;
            if ( core.hasTrait( trait.getName() ) ) {
                removedTypes = core.removeTrait( trait.getName() );
            } else {
                HierarchyEncoder hier = ((ReteooRuleBase) this.workingMemory.getRuleBase()).getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
                BitSet code = hier.getCode( trait.getName() );
                removedTypes = core.removeTrait( code );
            }

            for ( Thing t : removedTypes ) {
                if ( ! ((TraitType) t).isVirtual() ) {
View Full Code Here



    @Test
    public void testHierEncoderDecoderUpper() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "Thing", Collections.EMPTY_LIST );
        encoder.encode( "A", Arrays.asList( "Thing" ) );
        encoder.encode( "Z", Arrays.asList( "Thing" ) );
        encoder.encode( "B", Arrays.asList( "A", "Z" ) );
        encoder.encode( "C", Arrays.asList( "A", "Z" ) );
        encoder.encode( "N", Arrays.asList( "B", "C" ) );
        encoder.encode( "P", Arrays.asList( "Thing" ) );
        encoder.encode( "Q", Arrays.asList( "Thing" ) );
        encoder.encode( "R", Arrays.asList( "Thing" ) );
        encoder.encode( "S", Arrays.asList( "R" ) );
        encoder.encode( "T", Arrays.asList( "C", "Q" ) );
        encoder.encode( "M", Arrays.asList( "R", "Q" ) );
        encoder.encode( "O", Arrays.asList( "M", "P" ) );

        System.out.println( encoder );

        Collection x;

        x = encoder.upperBorder( encoder.metMembersCode( Arrays.asList( "B" ) ) );
        System.out.println( "LCS " + x );
        assertEquals( 1, x.size() );
        assertTrue( x.contains( "B" ) );

        x = encoder.immediateParents( encoder.metMembersCode( Arrays.asList( "B" ) ) );
        System.out.println( "LCS " + x );
        assertEquals( 2, x.size() );
        assertTrue( x.contains( "A" ) );
        assertTrue( x.contains( "Z" ) );



        x = encoder.upperBorder( encoder.jointMembersCode( Arrays.asList( "Z", "Q" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "Thing" ) );

        x = encoder.immediateParents( encoder.jointMembersCode( Arrays.asList( "Z", "Q" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "Thing" ) );



        x = encoder.upperBorder( encoder.jointMembersCode( Arrays.asList( "B", "C" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 2, x.size() );
        assertTrue( x.contains( "A" ) );
        assertTrue( x.contains( "Z" ) );

        x = encoder.immediateParents( encoder.jointMembersCode( Arrays.asList( "B", "C" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 2, x.size() );
        assertTrue( x.contains( "A" ) );
        assertTrue( x.contains( "Z" ) );


        x = encoder.upperBorder( encoder.jointMembersCode( Arrays.asList( "T" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 1, x.size() );
        assertTrue( x.contains( "T" ) );

        x = encoder.immediateParents( encoder.jointMembersCode( Arrays.asList( "T" ) ) );
        System.out.println( "LCS " + x );

        assertEquals( 2, x.size() );
        assertTrue( x.contains( "C" ) );
        assertTrue( x.contains( "Q" ) );
View Full Code Here

TOP

Related Classes of org.drools.util.HierarchyEncoder

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.