Package org.mindswap.pellet

Examples of org.mindswap.pellet.KnowledgeBase


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

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

    ATermAppl A = term( "A" );

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

    ATermAppl a = term( "a" );

    ATermAppl lit1 = literal( "test" );
    ATermAppl lit2 = literal( "1", Datatypes.DECIMAL );

    kb.addClass( A );

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

    kb.addIndividual( a );

    kb.addType( a, A );

    kb.addSubClass( A, min( p, 1, TOP_LIT ) );
    kb.addRange( p, oneOf( lit1 ) );

    kb.addSubClass( A, some( q, TOP_LIT ) );
    kb.addRange( q, oneOf( lit2 ) );

    assertTrue( kb.isConsistent() );


    assertEquals( singletonList( lit1 ), kb.getDataPropertyValues( p, a ) );
    assertEquals( singletonList( lit2 ), kb.getDataPropertyValues( q, a ) );
    assertTrue( kb.hasPropertyValue( a, p, lit1 ) );
    assertTrue( kb.hasPropertyValue( a, q, lit2 ) );
  }
View Full Code Here


  public void run() {
    propertyName = options.getOption( "property" ).getValueAsString();

    OWLAPILoader loader = new OWLAPILoader();
    KnowledgeBase kb = loader.createKB( getInputFiles() );

    OWLEntity entity = OntologyUtils.findEntity( propertyName, loader.getAllOntologies() );

    if( entity == null )
      throw new PelletCmdException( "Property not found: " + propertyName );

    if( !(entity instanceof OWLObjectProperty) )
      throw new PelletCmdException( "Not an object property: " + propertyName );

    if( !((OWLObjectProperty) entity).isTransitive( loader.getAllOntologies() ) )
      throw new PelletCmdException( "Not a transitive property: " + propertyName );

    ATermAppl p = ATermUtils.makeTermAppl( entity.getIRI().toString() );

    ATermAppl c = null;
    boolean filter = false;

    if(options.getOption( "filter" ).exists())
    {
      String filterName = options.getOption( "filter" ).getValueAsString();     
      OWLEntity filterClass = OntologyUtils.findEntity( filterName, loader.getAllOntologies() );
      if(filterClass == null)
        throw new PelletCmdException( "Filter class not found: " + filterName );     
      if(!(filterClass instanceof OWLClass))
        throw new PelletCmdException( "Not a class: " + filterName );

      c = ATermUtils.makeTermAppl( filterClass.getIRI().toString() );

      filter = true;
    }

    POTaxonomyBuilder builder = null;

    // Test first the individuals parameter, as per default the --classes
    // option is true
    if( options.getOption( "individuals" ).getValueAsBoolean() ) {
      // Parts for individuals
      builder = new POTaxonomyBuilder( kb, new PartIndividualsComparator( kb, p ) );
     
      Set<ATermAppl> individuals;     
      if(filter)
        individuals = kb.getInstances(c);
      else
        individuals = kb.getIndividuals()// Note: this is not an optimal solution 
     
      for( ATermAppl individual :  individuals)
        if (!ATermUtils.isBnode( individual ))
          builder.classify( individual );
    }
View Full Code Here

    assertTrue( kb.hasPropertyValue( a, q, lit2 ) );
  }

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

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

    kb.addClass( A );
    kb.addObjectProperty( p );

    kb.addDisjointClasses( Arrays.asList( A, self(p) ) );

    kb.classify();

    assertTrue( kb.isSatisfiable( A ) );
  }
View Full Code Here

  @Test
  public void testDisjointPropertiesCache() {
    // test case for issue #336 to verify AbstractConceptCache.isMergable does
    // not return incorrect results.
    KnowledgeBase kb = new KnowledgeBase();

    ATermAppl p1 = term( "p1" );
    ATermAppl p2 = term( "p2" );

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

    kb.addObjectProperty( p1 );
    kb.addObjectProperty( p2 );
    kb.addDisjointProperty( p1, p2 );

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

    kb.addPropertyValue( p1, a, c );
    kb.addPropertyValue( p2, b, a );

    ATermAppl notp1a = ATermUtils.makeNot( ATermUtils.makeHasValue( p1, a ) );

    // no caching so consistency checking will be used here
    assertFalse( kb.isType( a, notp1a ) );
    assertTrue( kb.isType( b, notp1a ) );

    // call getInstances so some caching will happen
    assertEquals( singleton( b ), kb.getInstances( notp1a, false ) );

    // now cached nodes will be used for mergable check
    assertFalse( kb.isType( a, notp1a ) );
    assertTrue( kb.isType( b, notp1a ) );

  }
View Full Code Here

  public void testSynoymClassification() {
    // Fixes the problem identified in #270. If there are two equivalent concepts
    // where one is primitive and the other is non-primitive CD classifier was
    // picking primitive flag and returning incorrect classification results.

    KnowledgeBase kb = new KnowledgeBase();

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

    ATermAppl p = term( "p" );

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

    kb.addDatatypeProperty( p );

    // B is completely defined except this equivalence
    kb.addEquivalentClass( A, B );
    // A is not primitive because of the domain axiom
    kb.addDomain( p, A );
    // C should be inferred to be a subclass of A and B
    kb.addSubClass( C, some(p, TOP_LIT ) );

    kb.classify();

    assertSubClass( kb, C, A );
    assertSubClass( kb, C, B );
  }
View Full Code Here

  @Test
  public void testUndefinedProperty() {
    // Test for #351. Calling getPropertyValues for an undefinde property should not throw NPE

    KnowledgeBase kb = new KnowledgeBase();

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

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

    kb.addObjectProperty( p );

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

    kb.addPropertyValue( p, a, b );

    kb.isConsistent();

    assertTrue( kb.getPropertyValues( q ).isEmpty() );
  }
View Full Code Here

    assertFalse(kb.isSatisfiable(some(p,some(q,all(p,BOTTOM)))));
  }

  @Test
  public void test553() {
    KnowledgeBase kb = new KnowledgeBase();
    KnowledgeBase copyKB = kb.copy();
    assertTrue(copyKB != kb);
    assertTrue(copyKB.getABox().getKB() == copyKB);
  }
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

        XSDDecimal.getInstance().getName() ) ) );
  }

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

    kb.addObjectProperty( term( "p" ) );
    kb.addObjectProperty( term( "q" ) );
    kb.addFunctionalProperty( term( "q" ) );

    kb.addClass( term( "C" ) );
    kb.addSubClass( term( "C" ), ATermUtils.makeMax( term( "p" ), 2, ATermUtils.TOP ) );

    kb.addClass( term( "D1" ) );
    kb.addClass( term( "D2" ) );
    kb.addClass( term( "D3" ) );
    kb.addClass( term( "D4" ) );
    kb.addClass( term( "E1" ) );
    kb.addClass( term( "E2" ) );
    kb.addClass( term( "E3" ) );
    kb.addClass( term( "E4" ) );
    kb.addSubClass( term( "D1" ), ATermUtils.makeSomeValues( term( "q" ), term( "E1" ) ) );
    kb.addSubClass( term( "D2" ), ATermUtils.makeSomeValues( term( "q" ), term( "E2" ) ) );
    kb.addSubClass( term( "D3" ), ATermUtils.makeSomeValues( term( "q" ), term( "E3" ) ) );
    kb.addSubClass( term( "D4" ), ATermUtils.makeSomeValues( term( "q" ), term( "E4" ) ) );

    kb.addIndividual( term( "x" ) );
    kb.addType( term( "x" ), term( "C" ) );
    kb.addIndividual( term( "x1" ) );
    kb.addType( term( "x1" ), term( "D1" ) );
    kb.addIndividual( term( "x2" ) );
    kb.addType( term( "x2" ), term( "D2" ) );
    kb.addIndividual( term( "x3" ) );
    kb.addType( term( "x3" ), term( "D3" ) );
    kb.addIndividual( term( "x4" ) );
    kb.addType( term( "x4" ), term( "D4" ) );

    kb.addPropertyValue( term( "p" ), term( "x" ), term( "x1" ) );
    kb.addPropertyValue( term( "p" ), term( "x" ), term( "x2" ) );
    kb.addPropertyValue( term( "p" ), term( "x" ), term( "x3" ) );
    kb.addPropertyValue( term( "p" ), term( "x" ), term( "x4" ) );

    kb.addDisjointClass( term( "E1" ), term( "E2" ) );
    kb.addDisjointClass( term( "E1" ), term( "E4" ) );
    kb.addDisjointClass( term( "E2" ), term( "E3" ) );

    assertTrue( kb.isConsistent() );

    assertTrue( kb.isSameAs( term( "x1" ), term( "x3" ) ) );
    assertTrue( kb.isSameAs( term( "x3" ), term( "x1" ) ) );
    assertTrue( kb.isSameAs( term( "x2" ), term( "x4" ) ) );

    assertTrue( kb.getSames( term( "x1" ) ).contains( term( "x3" ) ) );
    assertTrue( kb.getSames( term( "x2" ) ).contains( term( "x4" ) ) );
  }
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.