Package org.mindswap.pellet

Examples of org.mindswap.pellet.KnowledgeBase


  }

  @Test
  public void testLiteralMerge() {
    // Tests the issue described in #250
    KnowledgeBase kb = new KnowledgeBase();

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

    kb.addIndividual( a );
    kb.addIndividual( b );

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

    // a has a p-successor which is an integer
    kb.addType( a, some( p, XSDInteger.getInstance().getName() ) );
    // bogus axiom to force full datatype reasoning
    kb.addType( a, max( p, 2, TOP_LIT ) );

    // b has an asserted p value which is a string
    kb.addPropertyValue( p, b, literal( "b" ) );

    // check consistency whihc
    assertTrue( kb.isConsistent() );

    // this query will force a and b to be merged which will cause
    // their p values to be merged
    assertTrue( kb.isDifferentFrom( a, b ) );
  }
View Full Code Here


    // test where a fresh datatype is used. If the property in question
    // has a range the intersection of defined range with the fresh
    // datatype returned to be empty causing the reasoner to conclude
    // subproperty relation hols even though it does not

    KnowledgeBase kb = new KnowledgeBase();

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

    ATermAppl[] ranges = {
      null, XSDInteger.getInstance().getName(), XSDString.getInstance().getName()
    };

    for( ATermAppl rangeP : ranges ) {
      for( ATermAppl rangeQ : ranges ) {
        kb.clear();

        kb.addDatatypeProperty( p );
        kb.addDatatypeProperty( q );

        if( rangeP != null ) {
          kb.addRange( p, rangeP );
        }
        if( rangeQ != null ) {
          kb.addRange( q, rangeQ );
        }

        assertTrue( kb.isConsistent() );

        assertFalse( kb.isSubPropertyOf( p, q ) );
        assertFalse( kb.isSubPropertyOf( q, p ) );

        assertFalse( kb.isEquivalentProperty( p, q ) );
        assertFalse( kb.isEquivalentProperty( q, p ) );
      }
    }
  }
View Full Code Here

  @Test
  public void testDatatypeSubProperty1b() {
    // Another variation of testDatatypeSubProperty1 where super
    // property has a range but not the sub property

    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl C = term( "C" );

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

    kb.addClass( C );

    kb.addDatatypeProperty( p );
    kb.addDatatypeProperty( q );

    kb.addDomain( p, C );

    kb.addRange( q, XSDInteger.getInstance().getName() );

    kb.addSubClass( C, some( q, TOP_LIT ) );

    assertTrue( kb.isConsistent() );

    assertFalse( kb.isSubPropertyOf( p, q ) );
    assertFalse( kb.isSubPropertyOf( q, p ) );

    assertFalse( kb.isEquivalentProperty( p, q ) );
    assertFalse( kb.isEquivalentProperty( q, p ) );
  }
View Full Code Here

    assertFalse( kb.isEquivalentProperty( q, p ) );
  }

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

    ATermAppl A = term( "A" );
    ATermAppl B = term( "B" );
    ATermAppl C = term( "C" );
    ATermAppl D = term( "D" );

    ATermAppl p = term( "p" );

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

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

    kb.addObjectProperty( p );

    kb.addIndividual( b );
    kb.addIndividual( c );

    kb.addEquivalentClass( A, oneOf( b, c ) );
    kb.addEquivalentClass( B, hasValue( p, b ) );
    kb.addEquivalentClass( C, hasValue( p, c ) );
    kb.addEquivalentClass( D, and( some( p, A ), min( p, 1, value(b) ), min( p, 1, value(c) ), max( p, 1,
        TOP ) ) );

    assertTrue( kb.isConsistent() );

    kb.classify();

    assertTrue( kb.isSubClassOf( D, B ) );
    assertTrue( kb.isSubClassOf( D, C ) );
  }
View Full Code Here

 
  /**
   * Performs classification using the non-incremental (classic) classifier
   */
  private void runClassicClassify() {
    KnowledgeBase kb = getKB();
   
    startTask( "consistency check" );
    boolean isConsistent = kb.isConsistent();   
    finishTask( "consistency check" );

    if( !isConsistent )
      throw new PelletCmdException( "Ontology is inconsistent, run \"pellet explain\" to get the reason" );

    startTask( "classification" );
    kb.classify();
    finishTask( "classification" );

    TaxonomyPrinter<ATermAppl> printer = new ClassTreePrinter();
    printer.print( kb.getTaxonomy() );
  }
View Full Code Here

  }


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

    ATermAppl A = term( "A" );
    ATermAppl B = term( "B" );
    ATermAppl C = term( "C" );
    ATermAppl D = term( "D" );

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

    kb.addSubClass( B, A );
    kb.addSubClass( D, C );
    kb.addComplementClass( B, C );

    assertTrue( kb.isConsistent() );

    assertIteratorValues( kb.getDisjointClasses( TOP ).iterator(),
        new Object[] { singleton( BOTTOM ) } );
    assertIteratorValues( kb.getDisjointClasses( A ).iterator(),
        new Object[] { singleton( BOTTOM ) } );
    assertIteratorValues( kb.getDisjointClasses( B ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( C ), singleton( D ) } );
    assertIteratorValues( kb.getDisjointClasses( C ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( B ) } );
    assertIteratorValues( kb.getDisjointClasses( D ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( B ) } );
    assertIteratorValues( kb.getDisjointClasses( BOTTOM ).iterator(), new Object[] {
      singleton( TOP ), singleton( A ), singleton( B ), singleton( C ), singleton( D ),
      singleton( BOTTOM ) } );

    assertIteratorValues( kb.getComplements( TOP ).iterator(), new Object[] { BOTTOM } );
    assertTrue( kb.getComplements( A ).isEmpty() );
    assertIteratorValues( kb.getComplements( B ).iterator(), new Object[] { C } );
    assertIteratorValues( kb.getComplements( C ).iterator(), new Object[] { B } );
    assertTrue( kb.getComplements( D ).isEmpty() );
    assertIteratorValues( kb.getComplements( BOTTOM ).iterator(), new Object[] { TOP } );

    assertIteratorValues( kb.getDisjointClasses( not( A ) ).iterator(),
        new Object[] { singleton( BOTTOM ), singleton( A ), singleton( B ) } );
    assertIteratorValues( kb.getDisjointClasses( not( B ) ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( B ) } );
    assertIteratorValues( kb.getDisjointClasses( not( C ) ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( C ), singleton( D ) } );
    assertIteratorValues( kb.getDisjointClasses( not( D ) ).iterator(), new Object[] {
        singleton( BOTTOM ), singleton( D ) } );

    assertIteratorValues( kb.getComplements( not( A ) ).iterator(), new Object[] { A } );
    assertIteratorValues( kb.getComplements( not( B ) ).iterator(), new Object[] { B } );
    assertIteratorValues( kb.getComplements( not( C ) ).iterator(), new Object[] { C } );
    assertIteratorValues( kb.getComplements( not( D ) ).iterator(), new Object[] { D } );
  }
View Full Code Here

  /**
   * But #305
   */
  @Test
  public void testDisjointDataProperties() {
    KnowledgeBase kb = new KnowledgeBase();

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

    kb.addDatatypeProperty( p );
    kb.addDatatypeProperty( q );
    kb.addRange( p, Datatypes.INT );
    kb.addRange( q, Datatypes.INT );

    assertFalse( "p and q should not be disjoint!", kb.isDisjointProperty( p, q ) );
  }
View Full Code Here

  }


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

    ATermAppl A = term( "A" );
    ATermAppl B = term( "B" );
    ATermAppl C = term( "C" );

    ATermAppl p = term( "p" );

    ATermAppl a = term( "a" );
    ATermAppl b = term( "b" );

    kb.addClass( A );
    kb.addClass( B );
    kb.addClass( C );

    kb.addObjectProperty( p );

    kb.addIndividual( a );
    kb.addIndividual( b );

    kb.addEquivalentClass( A, value( a ) );
    kb.addSubClass( A, all( inv(p), not( B ) ) );
    kb.addSubClass( B, or( some( p, A ), C ) );

    kb.addType( b, B );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.isType( b, C ) );
    assertFalse( kb.isType( a, C ) );
  }
View Full Code Here

    assertFalse( kb.isType( a, C ) );
  }

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

    ATermAppl A = term( "A" );

    ATermAppl p = term( "p" );

    ATermAppl a = term( "a" );

    ATermAppl oneDecimal = literal( "1", Datatypes.DECIMAL );
    ATermAppl oneInteger = literal( "1", Datatypes.INTEGER );
    ATermAppl oneByte = literal( "1", Datatypes.BYTE );
    ATermAppl oneFloat = literal( "1", Datatypes.FLOAT );

    kb.addClass( A );

    kb.addDatatypeProperty( p );

    kb.addIndividual( a );

    kb.addPropertyValue( p, a, oneInteger );
    assertTrue( kb.isConsistent() );

    assertTrue( kb.hasPropertyValue( a, p, oneDecimal ) );
    assertTrue( kb.hasPropertyValue( a, p, oneInteger ) );
    assertTrue( kb.hasPropertyValue( a, p, oneByte ) );
    assertFalse( kb.hasPropertyValue( a, p, oneFloat ) );
    assertEquals( singletonList( oneInteger ), kb.getDataPropertyValues( p, a ) );
  }
View Full Code Here

    assertEquals( singletonList( oneInteger ), kb.getDataPropertyValues( p, a ) );
  }

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

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

    ATermAppl zeroDecimal = literal( "0", Datatypes.DECIMAL );
    ATermAppl zeroInteger = literal( "0", Datatypes.INTEGER );
    ATermAppl zeroByte = literal( "0", Datatypes.BYTE );
    ATermAppl zeroFloat = literal( "0", Datatypes.FLOAT );

    kb.addClass( A );
    kb.addDatatypeProperty( p );
    kb.addIndividual( a );

    kb.addSubClass( A, some( p, Datatypes.NON_POSITIVE_INTEGER ) );
    kb.addSubClass( A, all( p, Datatypes.NON_NEGATIVE_INTEGER ) );

    kb.addType( a, A );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.hasPropertyValue( a, p, zeroDecimal ) );
    assertTrue( kb.hasPropertyValue( a, p, zeroInteger ) );
    assertTrue( kb.hasPropertyValue( a, p, zeroByte ) );
    assertFalse( kb.hasPropertyValue( a, p, zeroFloat ) );
    assertEquals( singletonList( zeroDecimal ), kb.getDataPropertyValues( p, a ) );
  }
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.