Package org.mindswap.pellet

Examples of org.mindswap.pellet.KnowledgeBase


   * Test that an individual added to a complete ABox isn't discarded if
   * backtracking occurs in that ABox
   */
  @Test
  public void backtrackPreservesAssertedIndividuals() {
    KnowledgeBase kb = new KnowledgeBase();

    kb.addIndividual( term( "x" ) );

    kb.addClass( term( "C" ) );
    kb.addClass( term( "D" ) );

    kb.addDatatypeProperty( term( "p" ) );
    kb.addFunctionalProperty( term( "p" ) );

    kb.addSubClass( term( "C" ), ATermUtils.makeSomeValues( term( "p" ), ATermUtils
        .makeValue( ATermUtils.makePlainLiteral( "0" ) ) ) );
    kb.addSubClass( term( "D" ), ATermUtils.makeSomeValues( term( "p" ), ATermUtils
        .makeValue( ATermUtils.makePlainLiteral( "1" ) ) ) );

    kb.addType( term( "x" ), ATermUtils.makeOr( ATermUtils.makeList( new ATerm[] {
        term( "C" ), term( "D" ) } ) ) );

    /*
     * At this point we can get onto one of two branches. In one p(x,"0"),
     * in the other p(x,"1") The branch point is a concept disjunction and
     * we're provoking a datatype clash.
     */
    assertTrue( kb.isConsistent() );

    /*
     * Add the individual to the now completed ABox
     */
    kb.addIndividual( term( "y" ) );

    assertTrue( kb.isConsistent() );
    assertNotNull( kb.getABox().getIndividual( term( "y" ) ) );

    /*
     * This assertion causes a clash regardless of which branch we are on
     */
    kb.addPropertyValue( term( "p" ), term( "x" ), ATermUtils.makePlainLiteral( "2" ) );

    assertFalse( kb.isConsistent() );

    /*
     * In 2.0.0-rc5 (and perhaps earlier, this assertion fails)
     */
    assertNotNull( kb.getABox().getIndividual( term( "y" ) ) );
  }
View Full Code Here


    assertSubClass( kb, and( min( p, 2, c ), min( p, 2, not( c ) ) ), min( p, 4, TOP ) );
  }
 
  @Test
  public void testQualifiedCardinalityDataProperty() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl c = restrict( Datatypes.INTEGER, minInclusive( literal( 10 ) ) );
    ATermAppl d = restrict( Datatypes.INTEGER, maxInclusive( literal( 20 ) ) );

    ATermAppl p = term( "p" );
    ATermAppl f = term( "f" );
    ATermAppl sub = Datatypes.SHORT;
    ATermAppl sup = Datatypes.INTEGER;

    kb.addDatatype(sub);
    kb.addDatatype(sup);
    kb.addDatatypeProperty( p );
    kb.addDatatypeProperty( f );
    kb.addFunctionalProperty( f );

    assertSatisfiable( kb, and( min( p, 2, and( c, d ) ), max( p, 2, c ), some( p, or( and( c,
        not( d ) ), c ) ) ) );
    assertSubClass( kb, min( p, 4, TOP_LIT ), min( p, 2, TOP_LIT ) );
    assertNotSubClass( kb, min( p, 1, TOP_LIT ), min( p, 2, TOP_LIT ) );
View Full Code Here

    assertSubClass( kb, and( min( p, 2, c ), min( p, 2, not( c ) ) ), min( p, 4, TOP_LIT ) );
  }

  @Test
  public void testQualifiedCardinality3() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl c = term( "z" );
    ATermAppl d = term( "d" );
    ATermAppl e = term( "e" );
    ATermAppl notD = term( "notD" );

    ATermAppl p = term( "p" );

    ATermAppl x = term( "x" );
    ATermAppl y3 = term( "y3" );

    kb.addObjectProperty( p );
    kb.addClass( c );
    kb.addClass( d );
    kb.addClass( e );
    kb.addClass( notD );

    kb.addDisjointClass( d, notD );
    // kb.addSubClass( c, or(e,not(d)) );

    kb.addIndividual( x );
    kb.addIndividual( y3 );

    kb.addType( x, and( min( p, 2, and( d, e ) ), max( p, 2, d ) ) );
    kb.addType( y3, not( e ) );
    kb.addType( y3, some( inv( p ), value( x ) ) );
    kb.addType( y3, or( d, c ) );

    assertTrue( kb.isConsistent() );
  }
View Full Code Here

    assertTrue( kb.isConsistent() );
  }

  @Test
  public void testSelfRestrictions() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl c = term( "c" );
    ATermAppl d = term( "d" );

    ATermAppl p = term( "p" );

    kb.addClass( c );
    kb.addClass( d );

    kb.addObjectProperty( p );

    kb.addRange( p, d );

    kb.addSubClass( c, and( self( p ), some( p, TOP ) ) );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.isSatisfiable( c ) );
    assertTrue( kb.isSubClassOf( c, d ) );

  }
View Full Code Here

  @Test
  /**
   * Test for the enhancement required in #252
   */
  public void testBooleanDatatypeConstructors() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl nni = Datatypes.NON_NEGATIVE_INTEGER;
    ATermAppl npi = Datatypes.NON_POSITIVE_INTEGER;
    ATermAppl ni = Datatypes.NEGATIVE_INTEGER;
    ATermAppl pi = Datatypes.POSITIVE_INTEGER;
    ATermAppl f = Datatypes.FLOAT;
   
    ATermAppl s = term( "s" );
    kb.addDatatypeProperty( s );
   
    assertSatisfiable( kb, some( s, pi ) );
    assertSatisfiable( kb, some( s, not ( pi ) ) );
    assertUnsatisfiable( kb, some( s, and( pi, ni ) ) );
    assertUnsatisfiable( kb, some( s, and( f, or( pi, ni ) ) ) );
View Full Code Here

    assertSatisfiable( kb, some( s, and( nni, npi ) ) );
 

  @Test
  public void testSelfRestrictionRestore() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl C = term( "c" );
    ATermAppl D = term( "d" );

    ATermAppl p = term( "p" );
    ATermAppl q = term( "q" );
   
    ATermAppl a = term( "a" );

    kb.addClass( C );
    kb.addClass( D );

    kb.addObjectProperty( p );
    kb.addObjectProperty( q );

    kb.addSubClass( C, or( not( self( p ) ), not( self( q ) ) ) );

    kb.addIndividual( a );
    kb.addType( a, C );

    assertTrue( kb.isConsistent() );

    assertFalse( kb.isType( a, not( self( p ) ) ) );
    assertFalse( kb.isType( a, not( self( q ) ) ) );
 
View Full Code Here

    assertFalse( kb.isType( a, not( self( q ) ) ) );
 
 
  @Test
  public void testReflexive1() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl c = term( "c" );
    ATermAppl d = term( "d" );
    ATermAppl sub = term( "sub" );
    ATermAppl sup = term( "sup" );

    ATermAppl p = term( "p" );
    ATermAppl r = term( "r" );
    ATermAppl weakR = term( "weakR" );

    ATermAppl x = term( "x" );
    ATermAppl y = term( "y" );

    kb.addClass( c );
    kb.addClass( d );
    kb.addClass( sub );
    kb.addClass( sup );
    kb.addSubClass( sub, sup );
    kb.addSubClass( some( weakR, TOP ), self( weakR ) );

    kb.addObjectProperty( p );
    kb.addObjectProperty( r );
    kb.addObjectProperty( weakR );
    kb.addReflexiveProperty( r );
    kb.addRange( r, d );

    kb.addIndividual( x );
    kb.addType( x, self( p ) );
    kb.addType( x, not( some( weakR, value( x ) ) ) );
    kb.addIndividual( y );
    kb.addPropertyValue( weakR, y, x );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.isSubClassOf( and( c, self( p ) ), some( p, c ) ) );
    assertTrue( kb.isSubClassOf( and( c, min( r, 1, not( c ) ) ), min( r, 2, TOP ) ) );
    assertTrue( kb.isSubClassOf( min( r, 1, c ), d ) );
    assertTrue( kb.hasPropertyValue( x, p, x ) );
    assertTrue( kb.hasPropertyValue( y, weakR, y ) );
    assertTrue( kb.isDifferentFrom( x, y ) );
    assertTrue( kb.isDifferentFrom( y, x ) );
    assertTrue( kb.isType( x, some( r, value( x ) ) ) );
    assertTrue( kb.isSatisfiable( and( self( p ), self( inv( p ) ), max( p, 1, TOP ) ) ) );
  }
View Full Code Here

    assertTrue( kb.isSatisfiable( and( self( p ), self( inv( p ) ), max( p, 1, TOP ) ) ) );
  }

  @Test
  public void testReflexive2() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl a = term( "a" );
    ATermAppl c = term( "c" );
    ATermAppl r = term( "r" );

    kb.addIndividual( a );
    kb.addClass( c );
    kb.addSubClass( c, all( r, BOTTOM ) );
    kb.addSubClass( c, oneOf( a ) );

    kb.addObjectProperty( r );
    kb.addReflexiveProperty( r );

    assertSatisfiable( kb, c, false );
  }
View Full Code Here

 
  @Test
  public void testAsymmetry() {
    ATermAppl p = term( "p" );

    KnowledgeBase kb = new KnowledgeBase();
    kb.addObjectProperty( p );
    kb.addAsymmetricProperty( p );

    assertTrue( kb.isIrreflexiveProperty( p ) );
  }
View Full Code Here

  public void testResrictedDataRange() {
    byte MIN = 0;
    byte MAX = 127;
    int COUNT = MAX - MIN + 1;

    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl C = term( "C" );
    ATermAppl D = term( "D" );
    ATermAppl E = term( "E" );

    ATermAppl p = term( "p" );

    ATermAppl x = term( "x" );
    ATermAppl y = term( "y" );

    kb.addClass( C );
    kb.addClass( D );
    kb.addClass( E );

    kb.addDatatypeProperty( p );
    kb.addRange( p, ATermUtils.makeRestrictedDatatype( XSDInteger.getInstance().getName(), new ATermAppl[] {
      ATermUtils.makeFacetRestriction( Facet.XSD.MIN_INCLUSIVE.getName(), ATermUtils.makeTypedLiteral( Byte.toString( MIN ), XSDByte.getInstance().getName() ) ),
      ATermUtils.makeFacetRestriction( Facet.XSD.MAX_INCLUSIVE.getName(), ATermUtils.makeTypedLiteral( Byte.toString( MAX ), XSDByte.getInstance().getName() ) )
    }) );

    kb.addSubClass( C, card( p, COUNT + 1, ATermUtils.TOP_LIT ) );
    kb.addSubClass( D, card( p, COUNT, ATermUtils.TOP_LIT ) );
    kb.addSubClass( E, card( p, COUNT - 1, ATermUtils.TOP_LIT ) );

    kb.addIndividual( x );
    kb.addType( x, D );

    kb.addIndividual( y );
    kb.addType( y, E );

    assertFalse( kb.isSatisfiable( C ) );
    assertTrue( kb.isSatisfiable( D ) );
    assertTrue( kb.isSatisfiable( E ) );

    assertTrue( kb.hasPropertyValue( x, p, ATermUtils.makeTypedLiteral( "5",
        XSDInteger.getInstance().getName() ) ) );
    assertFalse( kb.hasPropertyValue( y, p, ATermUtils.makeTypedLiteral( "5",
        XSDDecimal.getInstance().getName() ) ) );
  }
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.KnowledgeBase

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.