Package com.clarkparsia.pellet.owlapiv3

Examples of com.clarkparsia.pellet.owlapiv3.OWLAPILoader


   
    return new Pair<OWLClass, OWLClass>( sub, sup );
  }
 
  private Set<OWLAxiom> getCachedExplanation(OWLClassExpression unsatClass) {
    PelletReasoner pellet = getReasoner();

    if( !pellet.getKB().isClassified() )
      return null;

    Pair<OWLClass,OWLClass> pair = getSubClassAxiom( unsatClass );

    if( pair != null ) {
      Set<Set<ATermAppl>> exps = TaxonomyUtils.getSuperExplanations(
          pellet.getKB().getTaxonomy(),
          pellet.term( pair.first ),
          pellet.term( pair.second ) );

      if( exps != null ) {
        Set<OWLAxiom> result = convertExplanation( exps.iterator().next() );
        if( log.isLoggable( Level.FINE ) )
          log.fine( "Cached explanation: " + result );
View Full Code Here


    return result;
  }

  private Set<OWLAxiom> getPelletExplanation(OWLClassExpression unsatClass) {
    PelletReasoner pellet = getReasoner();
   
    pellet.getKB().prepare();
   
    // satisfiable if there is an undefined entity
    boolean sat = !getDefinitionTracker().isDefined( unsatClass );
       
    if( !sat ) {
      sat = isSatisfiable( pellet, unsatClass, true );
    }
    else if( log.isLoggable( Level.FINE ) )
      log.fine( "Undefined entity in " + unsatClass );
     

    if( sat ) {
      return Collections.emptySet();
    }
    else {
      Set<OWLAxiom> explanation = convertExplanation( pellet.getKB().getExplanationSet() );

      if( log.isLoggable( Level.FINE ) )
        log.fine( "Explanation " + explanation );

      Set<OWLAxiom> prunedExplanation = pruneExplanation( unsatClass, explanation, true );
View Full Code Here

      DefinitionTracker defTracker = new DefinitionTracker( debuggingOntology );

      // since explanation size is generally small we can create and use a
      // completely new reasoner rather than destroying the state on already
      // existing reasoner
      PelletReasoner reasoner = getReasonerFactory().createNonBufferingReasoner( debuggingOntology );
           
      if( !defTracker.isDefined( unsatClass ) ) {
        log.warning( "Some of the entities in " + unsatClass
            + " are not defined in the explanation " + explanation );
      }
     
      if( isSatisfiable( reasoner, unsatClass, true ) ) {
        log.warning( "Explanation incomplete: Concept " + unsatClass
            + " is satisfiable in the explanation " + explanation );
      }

      // simply remove axioms one at a time. If the unsatClass turns
      // satisfiable then we know that axiom cannot be a part of minimal
      // explanation
      for( OWLAxiom axiom : explanation ) {
        if( log.isLoggable( Level.FINER ) )
          log.finer( "Try pruning " + axiom );
       
        if( !incremental) {
          reasoner.dispose();
        }
       
        OntologyUtils.removeAxioms( debuggingOntology, axiom );
       
        if( !incremental) {
          reasoner = getReasonerFactory().createNonBufferingReasoner( debuggingOntology );
        }
       
        reasoner.getKB().prepare();

        if( defTracker.isDefined( unsatClass )
            && !isSatisfiable( reasoner, unsatClass, false ) ) {
          // does not affect satisfiability so remove from the results
          prunedExplanation.remove( axiom );
         
          if( log.isLoggable( Level.FINER ) )
            log.finer( "Pruned " + axiom );         
        }
        else {
          // affects satisfiability so add back to the ontology
          OntologyUtils.addAxioms( debuggingOntology, axiom );       
        }
      }
     
      if( incremental ) {
        // remove the listener and the ontology to avoid memory leaks
        reasoner.dispose();
      }
     
      OWL.manager.removeOntology( debuggingOntology );
      OWL.manager.removeOntologyChangeListener( defTracker );     
View Full Code Here

   
    // read the ontology
    OWLOntology ontology = manager.loadOntology( IRI.create(ont) );
   
    // load the ontology to the reasoner
    PelletReasoner reasoner = com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner( ontology );
   
    // create property and resources to query the reasoner
    OWLClass Person = factory.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Person"));
    OWLObjectProperty workHomepage = factory.getOWLObjectProperty(IRI.create("http://xmlns.com/foaf/0.1/workInfoHomepage"));
    OWLDataProperty foafName = factory.getOWLDataProperty(IRI.create("http://xmlns.com/foaf/0.1/name"));
   
    // get all instances of Person class
    Set<OWLNamedIndividual> individuals = reasoner.getInstances( Person, false ).getFlattened();
    for(OWLNamedIndividual ind : individuals) {     
        // get the info about this specific individual
      Set<OWLLiteral> names = reasoner.getDataPropertyValues( ind, foafName );                       
        NodeSet<OWLClass> types = reasoner.getTypes( ind, true );       
        NodeSet<OWLNamedIndividual> homepages = reasoner.getObjectPropertyValues( ind, workHomepage );
       
        // we know there is a single name for each person so we can get that value directly
        String name = names.iterator().next().getLiteral();
      System.out.println( "Name: " + name );
       
View Full Code Here

   
    System.out.print("Reading file " + file + "...");
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.loadOntology(IRI.create(file));

    PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner( ontology );
    System.out.println("done.");
   
    reasoner.getKB().realize();
    reasoner.getKB().printClassTree();
   
    // create property and resources to query the reasoner
    OWLClass Person = manager.getOWLDataFactory().getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Person"));
    OWLObjectProperty workHomepage = manager.getOWLDataFactory().getOWLObjectProperty(IRI.create("http://xmlns.com/foaf/0.1/workInfoHomepage"));
    OWLDataProperty foafName = manager.getOWLDataFactory().getOWLDataProperty(IRI.create("http://xmlns.com/foaf/0.1/name"));
   
    // get all instances of Person class
    NodeSet<OWLNamedIndividual> individuals = reasoner.getInstances( Person, false);
    for(Node<OWLNamedIndividual> sameInd : individuals) {
      // sameInd contains information about the individual (and all other individuals that were inferred to be the same)
      OWLNamedIndividual ind =  sameInd.getRepresentativeElement();
     
        // get the info about this specific individual
      Set<OWLLiteral> names = reasoner.getDataPropertyValues( ind, foafName );                       
        NodeSet<OWLClass> types = reasoner.getTypes( ind, true );       
        NodeSet<OWLNamedIndividual> homepages = reasoner.getObjectPropertyValues( ind, workHomepage );
       
        // we know there is a single name for each person so we can get that value directly
        String name = names.iterator().next().getLiteral();
      System.out.println( "Name: " + name );
       
View Full Code Here

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    OWLOntology ontology = manager.loadOntology( IRI.create( mindswappers ) );

    // we want a non-buffering reasoner here (a buffering reasoner would not process any additions, until manually refreshed)
    PelletReasoner reasoner = com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createNonBufferingReasoner( ontology );
    manager.addOntologyChangeListener( reasoner );

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

    // peform ABox addition which results in a consistent KB
    OWLClass concept = factory.getOWLClass( IRI.create( mindswap + "GraduateStudent" ) );
    OWLNamedIndividual individual = factory
        .getOWLNamedIndividual( IRI.create( mindswappers + "JohnDoe" ) );
    manager.applyChange( new AddAxiom( ontology, factory.getOWLClassAssertionAxiom( concept, individual ) ) );

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

    // peform ABox addition which results in an inconsistent KB
    OWLObjectProperty role = factory.getOWLObjectProperty( IRI.create( foaf + "mbox" ) );
    individual = factory.getOWLNamedIndividual( IRI.create( mindswappers + "Christian.Halaschek" ) );
    OWLNamedIndividual mbox = factory.getOWLNamedIndividual( IRI.create( "mailto:kolovski@cs.umd.edu" ) );
    manager.applyChange( new AddAxiom( ontology, factory.getOWLObjectPropertyAssertionAxiom(
        role, individual, mbox ) ) );

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

    // create OWLEntities
    OWLOntologyManager manager = OWL.manager;
    OWLOntology ontology = manager.loadOntology( IRI.create( file ) );

    // Create the reasoner and load the ontology
    PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner( ontology );

    // Create an explanation generator
    PelletExplanation expGen = new PelletExplanation( reasoner );

    // Create some concepts
View Full Code Here

  public void testClassification(String inputOnt, String classifiedOnt) throws OWLOntologyCreationException {
    OWLOntology premise = OWL.manager.loadOntology( IRI.create( inputOnt ) );
    OWLOntology conclusion = OWL.manager.loadOntology( IRI.create( classifiedOnt ) );
   
    try {
      PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner( premise );
      reasoner.getKB().classify();
 
      List<OWLAxiom> nonEntailments = new ArrayList<OWLAxiom>();
         
      for( OWLSubClassOfAxiom axiom : conclusion.getAxioms( AxiomType.SUBCLASS_OF ) ) {
        boolean entailed = reasoner.getSubClasses( axiom.getSuperClass(), true ).containsEntity( (OWLClass) axiom.getSubClass() );
       
        if( !entailed ) {
          if( AbstractClassificationTest.FAIL_AT_FIRST_ERROR )
            fail( "Not entailed: " + axiom );
          else
            nonEntailments.add( axiom );
        }
      }
 
      for( OWLEquivalentClassesAxiom axiom : conclusion
          .getAxioms( AxiomType.EQUIVALENT_CLASSES ) ) {
        boolean entailed = reasoner.isEntailed( axiom );
       
        if( !entailed ) {
          if( AbstractClassificationTest.FAIL_AT_FIRST_ERROR )
            fail( "Not entailed: " + axiom );
          else
            nonEntailments.add( axiom );
        }
      }
     
      for( OWLClassAssertionAxiom axiom : conclusion.getAxioms( AxiomType.CLASS_ASSERTION ) ) {
        boolean entailed = reasoner.getInstances( axiom.getClassExpression(), true ).containsEntity( (OWLNamedIndividual) axiom.getIndividual() );
       
        if( !entailed ) {
          if( AbstractClassificationTest.FAIL_AT_FIRST_ERROR )
            fail( "Not entailed: " + axiom );
          else
View Full Code Here

  public void testRealization(String inputOnt) throws IOException {
    File testFile = new File( TEST_FILE );
    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {
      PelletReasoner unified = PelletReasonerFactory.getInstance().createReasoner( ontology );
      ModuleExtractor moduleExtractor = createModuleExtractor();

      IncrementalClassifier modular = new IncrementalClassifier( unified, moduleExtractor );
      modular.classify();

      // first we only persist classified-but-not-realized classifier
      assertFalse( modular.isRealized() );

      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );

      fos.close();

      FileInputStream fis = new FileInputStream( testFile );

      IncrementalClassifier modular2 = IncrementalClassifierPersistence.load( fis );

      fis.close();
      assertTrue( testFile.delete() );

      // the classifier read from file should NOT be realized at this point
      assertFalse( modular.isRealized() );
     
      assertInstancesEquals( unified, modular2 );
      assertTypesEquals( unified, modular2 );
     
      // the previous tests should have triggered realization
      assertTrue( modular2.isRealized() );

      // save the classifier again and read it back
      fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular2, fos );

      fos.close();

      fis = new FileInputStream( testFile );

      IncrementalClassifier modular3 = IncrementalClassifierPersistence.load( fis );

      fis.close();
      assertTrue( testFile.delete() );

      // the classifier read from file should be realized at this point
      assertTrue( modular3.isRealized() );
     
      assertInstancesEquals( unified, modular3 );
      assertTypesEquals( unified, modular3 );
     
      unified.dispose();
      modular.dispose();
      modular2.dispose();
      modular3.dispose();
    }
    finally {
View Full Code Here

    axioms.addAll( familyRef.getAxioms() );
    axioms.addAll( familyRules.getAxioms() );
   
    OWLOntology mergedOntology = OWL.Ontology( axioms );
   
    PelletReasoner reasoner = com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner( mergedOntology );

    OWLIndividual nella = OWL.Individual( luigiFamily.resolve( "#Nella" ) );
    OWLObjectProperty hasUncle = OWL.ObjectProperty( luigiFamily.resolve( "#hasUncle" ) );
    OWLIndividual dino = OWL.Individual( luigiFamily.resolve( "#Dino" ) );

    assertFalse( reasoner.isEntailed( OWL.propertyAssertion( nella, hasUncle, dino ) ) );

  }
View Full Code Here

TOP

Related Classes of com.clarkparsia.pellet.owlapiv3.OWLAPILoader

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.