Package org.mindswap.pellet

Examples of org.mindswap.pellet.KnowledgeBase


    // load the model to the reasoner
    model.prepare();

    // Get the KnolwedgeBase object
    KnowledgeBase kb = ((PelletInfGraph) model.getGraph()).getKB();

    // perform initial consistency check
    long s = System.currentTimeMillis();
    boolean consistent = kb.isConsistent();
    long e = System.currentTimeMillis();
    System.out.println( "Consistent? " + consistent + " (" + (e - s) + "ms)" );

    // peform ABox addition which results in a consistent KB
    ATermAppl concept = ATermUtils.makeTermAppl( mindswap + "GraduateStudent" );
    ATermAppl individual = ATermUtils.makeTermAppl( mindswappers + "JohnDoe" );
    kb.addIndividual( individual );
    kb.addType( individual, concept );

    // perform incremental consistency check
    s = System.currentTimeMillis();
    consistent = kb.isConsistent();
    e = System.currentTimeMillis();
    System.out.println( "Consistent? " + consistent + " (" + (e - s) + "ms)" );

    // peform ABox addition which results in an inconsistent KB
    ATermAppl role = ATermUtils.makeTermAppl( foaf + "mbox" );
    individual = ATermUtils.makeTermAppl( mindswappers + "Christian.Halaschek" );
    ATermAppl mbox = ATermUtils.makeTermAppl( "mailto:kolovski@cs.umd.edu" );
    kb.addPropertyValue( role, individual, mbox );

    // perform incremental consistency check
    s = System.currentTimeMillis();
    consistent = kb.isConsistent();
    e = System.currentTimeMillis();
    System.out.println( "Consistent? " + consistent + " (" + (e - s) + "ms)" );
  }
View Full Code Here


  @Test
  public void testSubPropertyRestore() {
    // This test case is to test the restoring of edges with
    // subproperties (see ticket 109)

    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 q = term( "q" );
    ATermAppl invP = term( "invP" );
    ATermAppl invQ = term( "invQ" );

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

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

    // first add the ABox assertions to make sure none is ignored
    kb.addPropertyValue( p, a, b );
    kb.addPropertyValue( q, a, b );

    // add the subproperty axiom later
    kb.addSubProperty( p, q );
    kb.addInverseProperty( p, invP );
    kb.addInverseProperty( q, invQ );

    // force b to be merged to one of c or d
    kb.addType( b, or( value( c ), value( d ) ) );

    assertTrue( kb.isConsistent() );

    // ask a query that will force the merge to be restored. with the bug
    // the q would not be restored causing either an internal exception or
    // the query to fail
    assertTrue( kb.isType( b, and( some( invP, value( a ) ), some( invQ, value( a ) ) ) ) );
  }
View Full Code Here

  @Test
  public void testInverseProperty() {
    // This test case is to test the retrieval of inverse
    // properties (see ticket 117)

    KnowledgeBase kb = new KnowledgeBase();

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

    kb.addObjectProperty( p );
    kb.addObjectProperty( q );
    kb.addObjectProperty( invP );
    kb.addObjectProperty( invQ );
    kb.addInverseProperty( p, invP );
    kb.addInverseProperty( q, invQ );

    assertEquals( Collections.singleton( invP ), kb.getInverses( p ) );
    assertEquals( Collections.singleton( invQ ), kb.getInverses( q ) );
    assertEquals( Collections.singleton( p ), kb.getInverses( invP ) );
    assertEquals( Collections.singleton( q ), kb.getInverses( invQ ) );
  }
View Full Code Here

  @Test
  public void testUndefinedTerms() {
    // This test case is to test the retrieval of equivalences
    // for undefined classes/properties (see ticket 90)

    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl C = term( "C" );
    kb.addClass( C );

    ATermAppl p = term( "p" );
    kb.addObjectProperty( p );

    ATermAppl undef = term( "undef" );

    assertEquals( Collections.singleton( p ), kb.getAllEquivalentProperties( p ) );
    assertEquals( Collections.emptySet(), kb.getEquivalentProperties( p ) );
    assertEquals( Collections.singleton( Collections.singleton( TermFactory.BOTTOM_OBJECT_PROPERTY ) ), kb.getSubProperties( p ) );
    assertEquals( Collections.singleton( Collections.singleton( TermFactory.TOP_OBJECT_PROPERTY ) ), kb.getSuperProperties( p ) );

    assertEquals( Collections.singleton( C ), kb.getAllEquivalentClasses( C ) );
    assertEquals( Collections.emptySet(), kb.getEquivalentClasses( C ) );
    assertEquals( Collections.emptySet(), kb.getSubClasses( p ) );
    assertEquals( Collections.emptySet(), kb.getSuperClasses( p ) );

    assertEquals( Collections.emptySet(), kb.getAllEquivalentProperties( undef ) );
    assertEquals( Collections.emptySet(), kb.getEquivalentProperties( undef ) );
    assertEquals( Collections.emptySet(), kb.getSubProperties( undef ) );
    assertEquals( Collections.emptySet(), kb.getSuperProperties( undef ) );

    assertEquals( Collections.emptySet(), kb.getAllEquivalentClasses( undef ) );
    assertEquals( Collections.emptySet(), kb.getEquivalentClasses( undef ) );
    assertEquals( Collections.emptySet(), kb.getSubClasses( undef ) );
    assertEquals( Collections.emptySet(), kb.getSuperClasses( undef ) );
  }
View Full Code Here

    Properties newOptions = new PropertiesBuilder().set( "SILENT_UNDEFINED_ENTITY_HANDLING",
        "false" ).build();
    Properties savedOptions = PelletOptions.setOptions( newOptions );

    try {
      KnowledgeBase kb = new KnowledgeBase();

      ATermAppl p = term( "p" );
      ATermAppl c = and( all( p, value( literal( "s" ) ) ), min( p, 2, value( literal( "l" ) ) ) );

      kb.addDatatypeProperty( p );

      assertFalse( kb.isSatisfiable( c ) );
    }
    finally {
      PelletOptions.setOptions( savedOptions );
    }
  }
View Full Code Here

  @Test
  public void testInvalidTransitivity2() {
    KBLoader[] loaders = { new JenaLoader() };
    for( KBLoader loader : loaders ) {
      KnowledgeBase kb = loader.createKB( base + "invalidTransitivity.owl" );

      for( Role r : kb.getRBox().getRoles() ) {
        if ( !ATermUtils.isBuiltinProperty( r.getName() ) ) {
          assertTrue(r.toString(), r.isSimple());
          assertFalse(r.toString(), r.isTransitive());
        }
      }

      for( ATermAppl p : kb.getObjectProperties() ) {
        if ( !ATermUtils.isBuiltinProperty( p ) ) {
          assertFalse( p.toString(), kb.isTransitiveProperty( p ) );
        }
      }
    }
  }
View Full Code Here

  }


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

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

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

    kb.addSubClass( TOP, and( or( B, not( A ) ), or( C, not( B ) ) ) );

    assertSubClass( kb, A, B );

    assertSubClass( kb, B, C );

    kb.classify();
  }
View Full Code Here

    // this case tests isMergable check and specifically the correctness of
    // ConceptCache.isIndependent value. concept C below will be merged to
    // either a or b with a dependency. if that dependency is not recorded
    // isMergable returns incorrect results

    KnowledgeBase kb = new KnowledgeBase();

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

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

    kb.addSubClass( C, oneOf( a, b ) );
    kb.addEquivalentClass( A, oneOf( a ) );
    kb.addEquivalentClass( B, oneOf( b ) );
    kb.addDisjointClass( A, B );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.isSatisfiable( C ) );

    assertNotSubClass( kb, C, A );
    assertNotSubClass( kb, C, B );

    assertNotSubClass( kb, A, C );
    assertNotSubClass( kb, B, C );
    assertFalse( kb.isType( a, C ) );
    assertFalse( kb.isType( b, C ) );
    assertFalse( kb.isType( a, not( C ) ) );
    assertFalse( kb.isType( b, not( C ) ) );
  }
View Full Code Here

  private void loadInput() {
    try {
      loader = (JenaLoader) getLoader( "Jena" );
     
      KnowledgeBase kb = getKB( loader );
           
      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" );
     
View Full Code Here

  /*
   * From bug #312
   */
  @Test
  public void testNominalValueInteraction() {
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl t1 = term("T1");
    ATermAppl p = term("p");
    ATermAppl i1 = term("i1");
    ATermAppl i21 = term("i21");
    ATermAppl i22 = term("i22");
    ATermAppl t1eq = ATermUtils.makeAnd( ATermUtils.makeHasValue( p, i21 ), ATermUtils.makeHasValue( p, i22 ) );
    ATermAppl test = term("test");

    kb.addClass( t1 );
    kb.addObjectProperty( p );
    kb.addIndividual( i1 );
    kb.addIndividual( i21 );
    kb.addIndividual( i22 );
    kb.addIndividual( test );

    kb.addEquivalentClass( t1, t1eq );
    kb.addSame( i1, i21 );
    kb.addSame( i21, i1 );

    kb.addPropertyValue( p, test, i21 );
    kb.addPropertyValue( p, test, i22 );

    Set<ATermAppl> t1inds = kb.retrieve( t1eq, kb.getIndividuals() );
    assertEquals( "Individual test should be of type T1. ", Collections.singleton( test ), t1inds);

  }
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.