// behavior of Pellet. it is possible that this behavior will
// change in the future and this test case can be modified
// accordingly
KnowledgeBase kb = new KnowledgeBase();
Timer classifyTimer = kb.timers.createTimer( "classify" );
Timer realizeTimer = kb.timers.createTimer( "realize" );
ATermAppl a = term( "a" );
ATermAppl b = term( "b" );
ATermAppl C = term( "C" );
ATermAppl D = term( "D" );
ATermAppl E = term( "E" );
ATermAppl p = term( "p" );
ATermAppl q = term( "q" );
kb.addClass( C );
kb.addClass( D );
kb.addClass( E );
kb.addSubClass( C, D );
kb.addEquivalentClass( C, some( p, TOP ) );
kb.addEquivalentClass( E, some( q, TOP ) );
kb.addObjectProperty( p );
kb.addObjectProperty( q );
kb.addSubProperty( q, p );
kb.addIndividual( a );
kb.addIndividual( b );
kb.addType( a, C );
kb.addPropertyValue( p, a, b );
// do the first consistency test
// ABox: C(a), p(a, b)
// TBox: C = some(p, TOP), E = some(q, TOP)
// RBox: q [= p
assertTrue( kb.isConsistent() );
// no classification or realization yet
assertEquals( 0, classifyTimer.getCount() );
assertEquals( 0, realizeTimer.getCount() );
assertFalse( kb.isClassified() );
assertFalse( kb.isRealized() );
// force realization
kb.realize();
// make sure counts are ok
assertEquals( 1, classifyTimer.getCount() );
assertEquals( 1, realizeTimer.getCount() );
// make an ABox change
kb.addType( b, E );
// check consistency again
assertTrue( kb.isConsistent() );
// classification results should remain but realization
// results are invalidated
assertTrue( kb.isClassified() );
assertTrue( !kb.isRealized() );
// force classification with a query
assertEquals( emptySet(), kb.getEquivalentClasses( C ) );
// verify classification occurred
assertEquals( 1, classifyTimer.getCount() );
// perform instance retrieval
assertEquals( singleton( b ), kb.getInstances( E ) );
// verify instance retrieval did not trigger realization
assertEquals( 1, realizeTimer.getCount() );
// query direct instances to force realization
assertEquals( singleton( b ), kb.getInstances( E, true ) );
// verify realization occurred
assertEquals( 2, realizeTimer.getCount() );
// make an ABox change causing p = q and as a result C = E
kb.addSubProperty( p, q );
// check consistency again
assertTrue( kb.isConsistent() );
// both classification and realization results are invalidated
assertTrue( !kb.isClassified() );
assertTrue( !kb.isRealized() );
// verify new equivalent property inference
assertEquals( singleton( q ), kb.getEquivalentProperties( p ) );
// verify new property assertion inference
assertEquals( singletonList( b ), kb.getPropertyValues( q, a ) );
// nothing so far should have triggered classification or realization
assertTrue( !kb.isClassified() );
assertTrue( !kb.isRealized() );
// verify new equivalent class inference (trigger classification)
assertEquals( singleton( E ), kb.getEquivalentClasses( C ) );
// verify classification
assertEquals( 2, classifyTimer.getCount() );
// verify new instance relation (trigger realization)
assertEquals( SetUtils.create( a, b ), kb.getInstances( E, true ) );
// verify realization
assertEquals( 3, realizeTimer.getCount() );
}