Package org.drools.core.util

Examples of org.drools.core.util.HierarchyEncoder


                konst = cacheConstructor( key, core, trait );
            }
        }

        T proxy = null;
        HierarchyEncoder hier = ruleBase.getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
        try {
            switch ( mode ) {
                case MAP    :   proxy = konst.newInstance( core, core._getDynamicProperties(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                case TRIPLES:   proxy = konst.newInstance( core, ruleBase.getTripleStore(), getTripleFactory(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                default     :   throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
            }

            return proxy;
View Full Code Here


                core._setTraitMap( null );
                return thing;
            } else 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 );
            }

            removedTypes = new ArrayList<Thing<K>>( removedTypes );
            for ( Thing t : removedTypes ) {
View Full Code Here



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

        encoder.encode( "R", Collections.EMPTY_LIST );
        encoder.encode( "A1", Arrays.asList( "R" ) );
        encoder.encode( "A2", Arrays.asList( "R" ) );
        encoder.encode( "A3", Arrays.asList( "R" ) );
        encoder.encode( "B1", Arrays.asList( "R" ) );
        encoder.encode( "B2", Arrays.asList( "R" ) );
        encoder.encode( "B3", Arrays.asList( "R" ) );
        encoder.encode( "B4", Arrays.asList( "B1", "B2", "B3" ) );
        encoder.encode( "B5", Arrays.asList( "B1", "B2", "B3" ) );
        encoder.encode( "B6", Arrays.asList( "B1", "B2", "B3" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet( "0"), encoder.getCode("R"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "A1" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "A2" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "A3" ) );
        assertEqualsparseBitSet( "1000" ), encoder.getCode( "B1" ) );
        assertEqualsparseBitSet( "10000" ), encoder.getCode( "B2" ) );
        assertEqualsparseBitSet( "100000" ), encoder.getCode( "B3" ) );
        assertEqualsparseBitSet( "10111000" ), encoder.getCode( "B4" ) );
        assertEqualsparseBitSet( "1111000" ), encoder.getCode( "B5" ) );
        assertEqualsparseBitSet( "100111000" ), encoder.getCode( "B6" ) );
    }
View Full Code Here

    }


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

        encoder.encode( "R", Collections.EMPTY_LIST );

        encoder.encode( "B1", Arrays.asList( "R" ) );
        encoder.encode( "B2", Arrays.asList( "R" ) );
        encoder.encode( "B3", Arrays.asList( "R" ) );
        encoder.encode( "B4", Arrays.asList( "B1", "B2", "B3" ) );
        encoder.encode( "B5", Arrays.asList( "B1", "B2", "B3" ) );
        encoder.encode( "B6", Arrays.asList( "B1", "B2", "B3" ) );

        encoder.encode( "A1", Arrays.asList( "R" ) );
        encoder.encode( "A2", Arrays.asList( "R" ) );
        encoder.encode( "A3", Arrays.asList( "R" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet( "0"), encoder.getCode("R"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B1" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "B2" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "B3" ) );
        assertEqualsparseBitSet( "10111" ), encoder.getCode( "B4" ) );
        assertEqualsparseBitSet( "1111" ), encoder.getCode( "B5" ) );
        assertEqualsparseBitSet( "100111" ), encoder.getCode( "B6" ) );
        assertEqualsparseBitSet( "1000000" ), encoder.getCode( "A1" ) );
        assertEqualsparseBitSet( "10000000" ), encoder.getCode( "A2" ) );
        assertEqualsparseBitSet( "100000000" ), encoder.getCode( "A3" ) );
    }
View Full Code Here



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

        encoder.encode( "T", Collections.EMPTY_LIST );
        encoder.encode( "A", Arrays.asList( "T" ) );
        encoder.encode( "B", Arrays.asList( "T" ) );
        encoder.encode( "C", Arrays.asList( "A", "B" ) );
        encoder.encode( "D", Arrays.asList( "A", "B" ) );

        System.out.println( encoder );

        assertEqualsparseBitSet( "0" ), encoder.getCode( "T" ) );
        assertEqualsparseBitSet( "1" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "111" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "1011" ), encoder.getCode( "C" ) );


    }
View Full Code Here



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

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Arrays.asList( "A" ) );
        encoder.encode( "C", Arrays.asList( "A" ) );
        encoder.encode( "D", Arrays.asList( "B" ) );
        encoder.encode( "E", Arrays.asList( "B" ) );
        encoder.encode( "F", Arrays.asList( "C" ) );
        encoder.encode( "G", Arrays.asList( "C" ) );
        encoder.encode( "H", Arrays.asList( "E" ) );


        System.out.println( encoder );

        assertEqualsparseBitSet( "0" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "101" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "1001" ), encoder.getCode( "E" ) );
        assertEqualsparseBitSet( "110" ), encoder.getCode( "F" ) );
        assertEqualsparseBitSet( "1010" ), encoder.getCode( "G" ) );
        assertEqualsparseBitSet( "11001" ), encoder.getCode( "H" ) );

        encoder.encode( "I", Arrays.asList( "E", "F" ) );

        System.out.println( encoder );

        assertEqualsparseBitSet( "0" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "101" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "1000001" ), encoder.getCode( "E" ) );
        assertEqualsparseBitSet( "100010" ), encoder.getCode( "F" ) );
        assertEqualsparseBitSet( "1010" ), encoder.getCode( "G" ) );
        assertEqualsparseBitSet( "1010001" ), encoder.getCode( "H" ) );
        assertEqualsparseBitSet( "1100011" ), encoder.getCode( "I" ) );

        checkHier( encoder, 'I' );
    }
View Full Code Here



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

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Arrays.asList( "A" ) );
        encoder.encode( "C", Arrays.asList( "B" ) );
        encoder.encode( "D", Arrays.asList( "B", "C" ) );

        System.out.println( encoder );

        assertEqualsparseBitSet( "0" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "11" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "111" ), encoder.getCode( "D" ) );
    }
View Full Code Here

        assertEqualsparseBitSet( "111" ), encoder.getCode( "D" ) );
    }

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

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Collections.EMPTY_LIST );
        encoder.encode( "C", Collections.EMPTY_LIST );
        encoder.encode( "D", Collections.EMPTY_LIST );
        encoder.encode( "E", Collections.EMPTY_LIST );

        System.out.println( encoder );

        assertEqualsparseBitSet( "1" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "1000" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "10000" ), encoder.getCode( "E" ) );

        assertEquals( 5, encoder.size() );
        assertEquals( 5, encoder.getSortedMembers().size() );
        assertEquals( 5, encoder.getSortedMap().size() );

    }
View Full Code Here

    }


    @Test
    public void testHierALotOfClasses() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();
        int N = 1194;

        encoder.encode( "A", Collections.EMPTY_LIST );
        for ( int j = 1; j < N; j++ ) {
            encoder.encode( "X" + j, Arrays.asList( "A" ) );
        }

        assertEquals( N, encoder.size() );
        BitSet code = encoder.getCode( "X" + ( N -1 ) );
        assertEquals( 1, code.cardinality() );
        assertTrue( code.get( N - 2 ) );
    }
View Full Code Here



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

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Arrays.asList( "A" ) );
        encoder.encode( "C", Arrays.asList( "A" ) );
        encoder.encode( "D", Arrays.asList( "B" ) );
        encoder.encode( "E", Arrays.asList( "B" ) );
        encoder.encode( "F", Arrays.asList( "C" ) );
        encoder.encode( "G", Arrays.asList( "C" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet("0"), encoder.getCode("A"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "101" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "1001" ), encoder.getCode( "E" ) );
        assertEqualsparseBitSet( "110" ), encoder.getCode( "F" ) );
        assertEqualsparseBitSet( "1010" ), encoder.getCode( "G" ) );
    }
View Full Code Here

TOP

Related Classes of org.drools.core.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.