Package org.mindswap.pellet.owlapi

Examples of org.mindswap.pellet.owlapi.Reasoner


  @Test
  public void testInfiniteChain() throws Exception {
    OWLOntology ont = loadOntology( base + "infiniteChain.owl" );

    Reasoner reasoner = new Reasoner( OWL.manager );
    reasoner.setOntology( ont );

    assertTrue( !reasoner.isConsistent() );
  }
View Full Code Here


  public void testRemoveLiteral() throws Exception {
    String ns = "http://www.example.org/test#";

    OWLOntology ont = loadOntology( base + "RemoveLiteral.owl" );

    Reasoner reasoner = new Reasoner( OWL.manager );
    reasoner.setOntology( ont );

    OWLDataProperty pInt = DataProperty( ns + "pInt" );
    OWLDataProperty pDouble = DataProperty( ns + "pDouble" );
    OWLDataProperty pBoolean = DataProperty( ns + "pBoolean" );

    OWLIndividual ind = Individual( ns + "ind1" );

    OWLConstant valDouble = ind.getDataPropertyValues( ont ).get(pDouble).iterator().next();
    OWLConstant valInt = ind.getDataPropertyValues( ont ).get(pInt).iterator().next();
    OWLConstant valBoolean = ind.getDataPropertyValues( ont ).get( pBoolean ).iterator().next();

    assertTrue( reasoner.isConsistent() );

    removeAxioms(ont, propertyAssertion( ind, pDouble, valDouble ) );
    reasoner.refresh();
    assertTrue( reasoner.getRelatedValues( ind, pDouble ).isEmpty() );

    removeAxioms( ont, propertyAssertion( ind, pInt, valInt ) );
    reasoner.refresh();
    assertTrue( reasoner.getRelatedValues( ind, pInt ).isEmpty() );

    removeAxioms( ont, propertyAssertion( ind, pBoolean, valBoolean ) );
    reasoner.refresh();
    assertTrue( reasoner.getRelatedValues( ind, pBoolean ).isEmpty() );

    assertTrue( reasoner.getDataPropertyRelationships( ind ).isEmpty() );

    OWLConstant newVal = constant( "0.0", XSD.DOUBLE );
    addAxioms( ont, propertyAssertion( ind, pDouble, newVal ) );
    reasoner.refresh();

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

  public void testFamily() throws OWLException {
    String ns = "http://www.example.org/family#";

    OWLOntology ont = loadOntology( base + "family.owl" );

    Reasoner reasoner = new Reasoner( OWL.manager );
    reasoner.setOntology( ont );

    OWLObjectProperty hasBrother = ObjectProperty( ns + "hasBrother" );
    OWLObjectProperty hasSon = ObjectProperty( ns + "hasSon" );
    OWLObjectProperty hasFather = ObjectProperty( ns + "hasFather" );
    OWLObjectProperty hasParent = ObjectProperty( ns + "hasParent" );
    OWLObjectProperty hasChild = ObjectProperty( ns + "hasChild" );
    OWLObjectProperty hasMother = ObjectProperty( ns + "hasMother" );
    OWLObjectProperty hasDaughter = ObjectProperty( ns + "hasDaughter" );
    OWLObjectProperty hasAncestor = ObjectProperty( ns + "hasAncestor" );
    OWLObjectProperty likes = ObjectProperty( ns + "likes" );
    OWLObjectProperty isMarriedTo = ObjectProperty( ns + "isMarriedTo" );
    OWLObjectProperty dislikes = ObjectProperty( ns + "dislikes" );
    OWLObjectProperty hasSister = ObjectProperty( ns + "hasSister" );
    OWLObjectProperty hasDescendant = ObjectProperty( ns + "hasDescendant" );
    OWLObjectProperty hasSibling = ObjectProperty( ns + "hasSibling" );
    OWLClass Child = Class( ns + "Child" );
    OWLClass Person = Class( ns + "Person" );
    OWLClass PersonWithAtLeastTwoMaleChildren = Class( ns + "PersonWithAtLeastTwoMaleChildren" );
    OWLClass PersonWithAtLeastTwoFemaleChildren = Class( ns
        + "PersonWithAtLeastTwoFemaleChildren" );
    OWLClass PersonWithAtLeastTwoChildren = Class( ns + "PersonWithAtLeastTwoChildren" );
    OWLClass PersonWithAtLeastFourChildren = Class( ns + "PersonWithAtLeastFourChildren" );
    OWLClass Teen = Class( ns + "Teen" );
    OWLClass Teenager = Class( ns + "Teenager" );
    OWLClass Male = Class( ns + "Male" );
    OWLClass Adult = Class( ns + "Adult" );
    OWLClass Female = Class( ns + "Female" );
    OWLClass Senior = Class( ns + "Senior" );
    OWLIndividual grandmother = Individual( ns + "grandmother" );
    OWLIndividual grandfather = Individual( ns + "grandfather" );
    OWLIndividual father = Individual( ns + "father" );
    OWLIndividual son = Individual( ns + "son" );
    OWLIndividual mother = Individual( ns + "mother" );
    OWLIndividual daughter = Individual( ns + "daughter" );
    OWLIndividual personX = Individual( ns + "personX" );
    OWLIndividual personY = Individual( ns + "personY" );
    OWLIndividual personZ = Individual( ns + "personZ" );

    assertTrue( reasoner.isConsistent() );

    KnowledgeBase kb = reasoner.getKB();

    for( int test = 0; test < 2; test++ ) {
      if( test != 0 )
        kb.realize();

      assertTrue( reasoner.isTransitive( hasAncestor ) );
      assertFalse( reasoner.isFunctional( hasAncestor ) );

      assertTrue( reasoner.isTransitive( hasDescendant ) );
      assertFalse( reasoner.isFunctional( hasDescendant ) );

      assertTrue( reasoner.isSymmetric( isMarriedTo ) );
      assertTrue( reasoner.isIrreflexive( isMarriedTo ) );

      assertTrue( reasoner.isSubPropertyOf( hasParent, hasAncestor ) );
      assertTrue( reasoner.isSubPropertyOf( hasFather, hasAncestor ) );
      assertTrue( reasoner.isSubPropertyOf( hasMother, hasAncestor ) );
      assertTrue( reasoner.isSubPropertyOf( hasChild, hasDescendant ) );

      assertTrue( reasoner.isDisjointWith( likes, dislikes ) );
      assertTrue( reasoner.isDisjointWith( dislikes, likes ) );
      assertTrue( reasoner.isDisjointWith( hasFather, hasMother ) );
      assertTrue( reasoner.isDisjointWith( hasMother, hasFather ) );

      assertTrue( reasoner.hasType( grandfather, Person ) );
      assertTrue( reasoner.hasType( grandfather, PersonWithAtLeastTwoChildren ) );
      assertTrue( reasoner.hasType( grandfather, PersonWithAtLeastTwoMaleChildren ) );
      assertTrue( reasoner.hasType( grandfather, Male ) );
      assertTrue( reasoner.hasType( grandfather, Senior ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( grandfather, isMarriedTo,
          grandmother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( grandfather, hasChild, father ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( grandfather, hasSon, father ) );
      assertTrue( reasoner.isDifferentFrom( grandfather, grandmother ) );
      assertTrue( reasoner.isDifferentFrom( grandfather, father ) );
      assertTrue( reasoner.isDifferentFrom( grandfather, mother ) );
      assertTrue( reasoner.isDifferentFrom( grandfather, son ) );
      assertTrue( reasoner.isDifferentFrom( grandfather, daughter ) );

      assertTrue( reasoner.hasType( grandmother, Person ) );
      assertTrue( reasoner.hasType( grandmother, Female ) );
      assertTrue( reasoner.hasType( grandmother, Senior ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( grandmother, isMarriedTo,
          grandfather ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( grandmother, hasChild, father ) );
      assertFalse( reasoner.hasObjectPropertyRelationship( grandmother, hasSon, father ) );

      assertTrue( reasoner.hasType( father, Person ) );
      assertTrue( reasoner.hasType( father, Male ) );
      assertTrue( reasoner.hasType( father, Adult ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasParent, grandfather ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasParent, grandmother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasFather, grandfather ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasMother, grandmother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasChild, son ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasSon, son ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( father, hasChild, daughter ) );
      assertFalse( reasoner.hasObjectPropertyRelationship( father, hasDaughter, daughter ) );

      assertTrue( reasoner.hasType( mother, Person ) );
      assertTrue( reasoner.hasType( mother, Female ) );

      assertTrue( reasoner.hasType( son, Male ) );
      assertTrue( reasoner.hasType( son, Teenager ) );
//      assertTrue( reasoner.hasType( son, Teen ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( son, hasParent, father ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( son, hasFather, father ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( son, hasSibling, daughter ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( son, hasSister, daughter ) );

      assertTrue( reasoner.hasType( daughter, Female ) );
      assertTrue( reasoner.hasType( daughter, Child ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasAncestor, grandfather ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasAncestor, grandmother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasParent, father ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasFather, father ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasParent, mother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasMother, mother ) );
      assertTrue( reasoner.hasObjectPropertyRelationship( daughter, hasSibling, son ) );
      assertFalse( reasoner.hasObjectPropertyRelationship( daughter, hasBrother, son ) );

      assertTrue( reasoner.isDifferentFrom( personX, personY ) );
      assertTrue( reasoner.isDifferentFrom( personX, personZ ) );
      assertTrue( reasoner.isDifferentFrom( personY, personZ ) );

//      assertTrue( reasoner.isEquivalentClass( Teen, Teenager ) );
      assertTrue( reasoner.isSubClassOf( Senior, Adult ) );

      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastTwoMaleChildren, Person ) );
      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastTwoFemaleChildren, Person ) );
      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastTwoChildren, Person ) );
      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastFourChildren, Person ) );

      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastFourChildren,
          PersonWithAtLeastTwoChildren ) );
      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastTwoMaleChildren,
          PersonWithAtLeastTwoChildren ) );
      assertTrue( reasoner.isSubClassOf( PersonWithAtLeastTwoFemaleChildren,
          PersonWithAtLeastTwoChildren ) );

      assertFalse( reasoner.isSubClassOf( PersonWithAtLeastTwoFemaleChildren,
          PersonWithAtLeastTwoMaleChildren ) );
      assertFalse( reasoner.isSubClassOf( PersonWithAtLeastTwoMaleChildren,
          PersonWithAtLeastTwoFemaleChildren ) );
    }

    // kb.timers.print();
  }
View Full Code Here

      OWLOntology ont = manager.createOntology( uri );

      manager.applyChange( new AddAxiom( ont, axiom ) );

      Reasoner reasoner = new Reasoner( manager );
      reasoner.getKB().setDoExplanation( true );
      reasoner.loadOntology( ont );

      assertTrue( "Entailment failed", reasoner.isEntailed( axiom ) );

      Set<OWLAxiom> explanation = reasoner.getExplanation();
      assertEquals( "Unexpected explanation", SetUtils.create( axiom ), explanation );
    } catch( Exception e ) {
      e.printStackTrace();

      fail( "Explanation failed" );
View Full Code Here

  public void setInputOntology(String inputFileURI) {
    try {
      manager.addURIMapper( mapper );
      OWLOntology ont = manager.loadOntology( getInputSource( inputFileURI ) );
      reasoner = new Reasoner( manager );
      reasoner.setOntology( ont );
    } catch( OWLException e ) {
      throw new RuntimeException( e );
    }
  }
View Full Code Here

    }
  }

  private void testOWLAPI(String premiseURI, String conclusionURI) {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    Reasoner reasoner = new Reasoner(manager);
   
    try {
      OWLOntology premise = manager.loadOntology(URI.create(premiseURI));
      OWLOntology conclusion = manager.loadOntology(URI
          .create(conclusionURI));

      reasoner.loadOntology(premise);
     
      assertTrue(reasoner.isEntailed(conclusion));
    } catch (OWLOntologyCreationException e) {
      throw new RuntimeException( e );
    }
  }
View Full Code Here

    OWLSubClassAxiom sc = factory.getOWLSubClassAxiom(c,
        dataSomeRestriction);

    manager.addAxiom(ontology, sc);
   
    Reasoner reasoner = new Reasoner(manager);

    reasoner.loadOntology(ontology);
    assertTrue(reasoner.isConsistent());
   
    KnowledgeBase kb = reasoner.getKB();
    assertTrue(kb.isClass(term("http://example#c")));
   
    // check for complex class that refers to a user-defined datatype
    ATermAppl term = reasoner.getLoader().term( dataSomeRestriction );
    term = ATermUtils.normalize( term );
    assertTrue( kb.isClass( term ) );   
  }
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.owlapi.Reasoner

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.