Package org.drools.core.common

Examples of org.drools.core.common.EqualityKey


        assertEquals( 1, count );
       
        ObjectHashMap equalityMap =  ep.getTruthMaintenanceSystem().getEqualityKeyMap();
        assertEquals( 1, equalityMap.size() ); // Only Person type is logical
        org.drools.core.util.Iterator it = equalityMap.iterator();
        EqualityKey key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }
             
        assertEquals( 3, key.getBeliefSet().size() );       
        assertEquals( new Integer(1), ((Person)key.getBeliefSet().getFactHandle().getObject()).getNotInEqualTestObject() );
       
        kSession.retract( fhGo1 );
        kSession.fireAllRules();
        it = equalityMap.iterator();
        key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }
             
        assertEquals( 2, key.getBeliefSet().size() );       
        assertEquals( new Integer(3), ((Person)key.getBeliefSet().getFactHandle().getObject()).getNotInEqualTestObject() );
       
        kSession.retract( fhGo3 );
        kSession.fireAllRules();
        it = equalityMap.iterator();
        key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }
             
        assertEquals( 1, key.getBeliefSet().size() );       
        assertEquals( new Integer(2), ((Person)key.getBeliefSet().getFactHandle().getObject()).getNotInEqualTestObject() );
    }   
View Full Code Here


        assertEquals( 1, count );
       
        ObjectHashMap equalityMap =  ep.getTruthMaintenanceSystem().getEqualityKeyMap();
        assertEquals( 1, equalityMap.size() ); // Only Person type is logical
        org.drools.core.util.Iterator it = equalityMap.iterator();
        EqualityKey key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }
             
        assertEquals( 3, key.getBeliefSet().size() );       
        assertEquals( new Integer(1), ((Person)((JTMSBeliefSetImpl)key.getBeliefSet()).getNegativeFactHandle().getObject()).getNotInEqualTestObject() );
       
        kSession.retract( fhGo1 );
        kSession.fireAllRules();
        it = equalityMap.iterator();
        key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }

        assertEquals( 2, key.getBeliefSet().size() );       
        assertEquals( new Integer(3), ((Person)((JTMSBeliefSetImpl)key.getBeliefSet()).getNegativeFactHandle().getObject()).getNotInEqualTestObject() );

        kSession.retract( fhGo3 );
        kSession.fireAllRules();
        it = equalityMap.iterator();
        key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }

        assertEquals( 1, key.getBeliefSet().size() );       
        assertEquals( new Integer(2), ((Person)((JTMSBeliefSetImpl)key.getBeliefSet()).getNegativeFactHandle().getObject()).getNotInEqualTestObject() );
    }
View Full Code Here

       
        NamedEntryPoint ep = ( NamedEntryPoint ) ((StatefulKnowledgeSessionImpl)kSession).getEntryPoint( "DEFAULT" );
        ObjectHashMap equalityMap =  ep.getTruthMaintenanceSystem().getEqualityKeyMap();
        assertEquals( 2, equalityMap.size() ); // go1, neg are two different strings.
        org.drools.core.util.Iterator it = equalityMap.iterator();
        EqualityKey key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        while ( !key.getFactHandle().getObject().equals( "neg") ) {
            key = ( EqualityKey  ) (( ObjectEntry ) it.next() ).getValue();
        }
       
        assertEquals( 3, key.getBeliefSet().size() );       
        kSession.retract( key.getBeliefSet().getFactHandle() )
        assertEquals( 0, key.getBeliefSet().size() );    

        assertEquals( 1, kSession.getEntryPoint( "DEFAULT" ).getObjects().size() ); //just go1
        assertEquals( 0, kSession.getEntryPoint( "neg" ).getObjects().size() ); // neg
        assertEquals( 0, key.getBeliefSet().size() );
        assertEquals( 1, ep.getTruthMaintenanceSystem().getEqualityKeyMap().size() );
   
View Full Code Here

        FactHandle fd = workingMemory.insertLogical( string );

        assertEquals( 1,
                      tms.getEqualityKeyMap().size() );

        EqualityKey key = tms.get( string );
        assertSame( fd,
                    key.getFactHandle() );
        assertEquals( 1, key.size() );

        workingMemory.update( fd,
                                    string );

        assertEquals( 1,
                      tms.getEqualityKeyMap().size() );
        key = tms.get( string );
        assertSame( fd,
                    key.getFactHandle() );
        assertEquals( 1, key.size() );

        workingMemory.retract( fd );

        assertEquals( 0,
                      tms.getEqualityKeyMap().size() );
        key = tms.get( string );
        assertNull( key );

        fd = workingMemory.insert( string );

        assertEquals( 1,
                      tms.getEqualityKeyMap().size() );

        assertEquals( 1,
                      tms.getEqualityKeyMap().size() );
        key = tms.get( string );
        assertSame( fd,
                    key.getFactHandle() );
        assertEquals( 1, key.size() );
    }
View Full Code Here

        if ( !justifiedMap.isEmpty() ) {
            EqualityKey[] keys = new EqualityKey[justifiedMap.size()];
            org.drools.core.util.Iterator it = justifiedMap.iterator();
            int i = 0;
            for ( org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next() ) {
                EqualityKey key = (EqualityKey) entry.getKey();
                keys[i++] = key;
            }

            Arrays.sort( keys,
                         EqualityKeySorter.instance );

            ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder();

            // write the assert map of Equality keys
            for ( EqualityKey key : keys ) {
                ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder();
                _key.setStatus( key.getStatus() );
                _key.setHandleId( key.getFactHandle().getId() );

                if ( key.size() > 1 ) {
                    // add all the other key's if they exist
                    FastIterator keyIter = key.fastIterator();
                    for ( DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next( handle ) ) {
                        _key.addOtherHandle( handle.getId() );
                    }
                }

                if ( key.getBeliefSet() != null ) {
                    writeBeliefSet( context, key.getBeliefSet(), _key );
                }

                _tms.addKey( _key.build() );
            }
View Full Code Here

                                                                                                         handle.getObject() );
            if ( !typeConf.isTMSEnabled() && (!wasOTCSerialized || tmsEnabled.contains(typeConf.getTypeName()) ) ) {
                typeConf.enableTMS();
            }

            EqualityKey key = new EqualityKey( handle,
                                               _key.getStatus() );
            handle.setEqualityKey( key );

            if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
                // not yet added to the object stores
                ((NamedEntryPoint) handle.getEntryPoint()).getObjectStore().addHandle( handle,
                                                                                       handle.getObject() );
                // add handle to object type node
                assertHandleIntoOTN( context,
                                     context.wm,
                                     handle,
                                     pctxs );
            }

            for ( Integer factHandleId : _key.getOtherHandleList() ) {
                handle = (InternalFactHandle) context.handles.get( factHandleId.intValue() );
                key.addFactHandle( handle );
                handle.setEqualityKey( key );
            }
            tms.put( key );

            readBeliefSet( context, tms, key, _key );
View Full Code Here

        if ( !justifiedMap.isEmpty() ) {
            EqualityKey[] keys = new EqualityKey[justifiedMap.size()];
            org.drools.core.util.Iterator it = justifiedMap.iterator();
            int i = 0;
            for ( org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next() ) {
                EqualityKey key = (EqualityKey) entry.getKey();
                keys[i++] = key;
            }

            Arrays.sort( keys,
                         EqualityKeySorter.instance );

            ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder();

            // write the assert map of Equality keys
            for ( EqualityKey key : keys ) {
                ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder();
                _key.setStatus( key.getStatus() );
                _key.setHandleId( key.getFactHandle().getId() );

                if ( key.size() > 1 ) {
                    // add all the other key's if they exist
                    FastIterator keyIter = key.fastIterator();
                    for ( DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next( handle ) ) {
                        _key.addOtherHandle( handle.getId() );
                    }
                }

                if ( key.getBeliefSet() != null ) {
                    writeBeliefSet( context, key.getBeliefSet(), _key );
                }

                _tms.addKey( _key.build() );
            }
View Full Code Here

                        objects[ j ] = dquery.getElements()[ j ];
                    }
                }
                Object abduced = aq.abduce( Arrays.copyOfRange( objects, 0, numArgs - 1 ) );
                if ( abduced != null ) {
                    EqualityKey key = ( (NamedEntryPoint) workingMemory.getEntryPoint( workingMemory.getEntryPointId() ) ).getTruthMaintenanceSystem().get( abduced );
                    InternalFactHandle handle;
                    if ( key != null ) {
                        handle = key.getFactHandle();
                        abduced = handle.getObject();
                    } else {
                        handle = (InternalFactHandle) ((InternalWorkingMemoryActions) workingMemory).insert( abduced,
                                                                                                             MODE.POSITIVE.getId(),
                                                                                                             false,
View Full Code Here

        if ( !justifiedMap.isEmpty() ) {
            EqualityKey[] keys = new EqualityKey[justifiedMap.size()];
            org.drools.core.util.Iterator it = justifiedMap.iterator();
            int i = 0;
            for ( org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next() ) {
                EqualityKey key = (EqualityKey) entry.getKey();
                keys[i++] = key;
            }

            Arrays.sort( keys,
                         EqualityKeySorter.instance );

            ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder();

            // write the assert map of Equality keys
            for ( EqualityKey key : keys ) {
                ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder();
                _key.setStatus( key.getStatus() );
                _key.setHandleId( key.getFactHandle().getId() );

                if ( key.size() > 1 ) {
                    // add all the other key's if they exist
                    FastIterator keyIter = key.fastIterator();
                    for ( DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next( handle ) ) {
                        _key.addOtherHandle( handle.getId() );
                    }
                }

                if ( key.getBeliefSet() != null ) {
                    writeBeliefSet( context, key.getBeliefSet(), _key );
                }

                _tms.addKey( _key.build() );
            }
View Full Code Here

                                                                                                         handle.getObject() );
            if ( !typeConf.isTMSEnabled() ) {
                typeConf.enableTMS();
            }

            EqualityKey key = new EqualityKey( handle,
                                               _key.getStatus() );
            handle.setEqualityKey( key );

            if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
                // not yet added to the object stores
                ((NamedEntryPoint) handle.getEntryPoint()).getObjectStore().addHandle( handle,
                                                                                       handle.getObject() );
                // add handle to object type node
                assertHandleIntoOTN( context,
                                     context.wm,
                                     handle,
                                     pctxs );
            }

            for ( Integer factHandleId : _key.getOtherHandleList() ) {
                handle = (InternalFactHandle) context.handles.get( factHandleId.intValue() );
                key.addFactHandle( handle );
                handle.setEqualityKey( key );
            }
            tms.put( key );

            readBeliefSet( context, tms, key, _key );
View Full Code Here

TOP

Related Classes of org.drools.core.common.EqualityKey

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.