Package com.clarkparsia.modularity

Examples of com.clarkparsia.modularity.IncrementalClassifier


   
    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 {
      OWL.manager.removeOntology( ontology );
    }
  } 
View Full Code Here


   
    try {
      PelletReasoner unified = PelletReasonerFactory.getInstance().createReasoner( ontology );
      ModuleExtractor moduleExtractor = createModuleExtractor();

      IncrementalClassifier modular = new IncrementalClassifier( unified, moduleExtractor );

      modular.classify();

      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );

      fos.close();

      FileInputStream fis = new FileInputStream( testFile );
     
      IncrementalClassifier modular2 = IncrementalClassifierPersistence.load( fis );

      fis.close();

      assertClassificationEquals( unified, modular2 );

      assertTrue( testFile.delete() );
     
      unified.dispose();
      modular.dispose();
      modular2.dispose();
    }
    finally {
      OWL.manager.removeOntology( ontology );
    }
  } 
View Full Code Here

    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {   
      ModuleExtractor moduleExtractor = createModuleExtractor();

      IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, moduleExtractor );

      // first remove a random axiom
      List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

      for( OWLAxiom axiomToRemove : axiomsToRemove ) {
        OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
      }

      // classify (i.e., update)
      modular.classify();   

      // add the axiom back but do not classify (do not cause an update)

      for( OWLAxiom axiomToAdd : axiomsToRemove ) {
        OWL.manager.applyChange( new AddAxiom(ontology, axiomToAdd ) );
      }

      // at this point there should be a change to the ontology that is not applied yet to the classifier
      // this should cause the save operation to fail

      try {
        FileOutputStream fos = new FileOutputStream( testFile );

        IncrementalClassifierPersistence.save( modular, fos );
        fail( "The incremental classifer must not allow itself to be persisted if there are any unapplied changes to the ontology" );

        fos.close();
      } catch( IllegalStateException e ) {
        assertTrue( testFile.delete() );
        // correct behavior
      }    
     
      modular.dispose();
    } finally {
      if( ontology != null ) {
        OWL.manager.removeOntology( ontology );
      }
    }
View Full Code Here

    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {
      ModuleExtractor moduleExtractor = createModuleExtractor();

      IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, moduleExtractor );
      modular.classify();

      // first remove a random axiom
      List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

      for( OWLAxiom axiomToRemove : axiomsToRemove ) {
        OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
      }

      // add the axiom back but do not classify   
      for( OWLAxiom axiomToAdd : axiomsToRemove ) {
        OWL.manager.applyChange( new AddAxiom(ontology, axiomToAdd ) );
      }

      // remove another random axiom
      List<OWLAxiom> axiomsToRemove2 = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

      for( OWLAxiom axiomToRemove : axiomsToRemove2 ) {
        OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
      }

      // classify (i.e., update)
      modular.classify();

      // at this point, the ontology should be updated (despite the changes), and the save should succeed.   
      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );
View Full Code Here

    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {   
      ModuleExtractor moduleExtractor = createModuleExtractor();

      IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, moduleExtractor );
      modular.classify();

      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );

      fos.close();


      FileInputStream fis = new FileInputStream( testFile );

      modular = IncrementalClassifierPersistence.load( fis );

      fis.close();

      // first remove a random axiom
      List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

      for( OWLAxiom axiomToRemove : axiomsToRemove ) {
        OWL.manager.applyChange( new RemoveAxiom( modular.getRootOntology(), axiomToRemove) );
      }

      modular.classify();

      PelletReasoner expected = PelletReasonerFactory.getInstance().createReasoner( modular.getRootOntology() );   

      assertClassificationEquals( expected, modular );
    } finally {
      OWL.manager.removeOntology( ontology );
    }
View Full Code Here

  public void testUpdatesAfterPersistence2(String inputOnt) throws IOException {
    File testFile = new File( TEST_FILE );
    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {
      IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, createModuleExtractor() );   
      modular.classify();

      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );

      fos.close();

      FileInputStream fis = new FileInputStream( testFile );

      modular = IncrementalClassifierPersistence.load( fis, ontology );

      fis.close();

      // first remove a random axiom
      List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

      for( OWLAxiom axiomToRemove : axiomsToRemove ) {
        OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
      }

      modular.classify();

      PelletReasoner expected = PelletReasonerFactory.getInstance().createReasoner( ontology );

      assertClassificationEquals( expected, modular );
    } finally {
View Full Code Here

  public void testUpdatesWhenPersisted(String inputOnt) throws IOException {
    File testFile = new File( TEST_FILE );
    OWLOntology ontology = OntologyUtils.loadOntology( inputOnt );
   
    try {
      IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, createModuleExtractor() );   
      modular.classify();

      FileOutputStream fos = new FileOutputStream( testFile );

      IncrementalClassifierPersistence.save( modular, fos );
View Full Code Here

   
    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 {
      OWL.manager.removeOntology( ontology );
    }
  } 
View Full Code Here

    boolean realized = Boolean.valueOf( properties.getProperty( REALIZED_PROPERTY, "false" ) );
       
    IncrementalClassifier.PersistedState persistedState = new IncrementalClassifier.PersistedState( extractor, taxonomy, realized );
   
    if( loadedOntology !=null ) {
      return new IncrementalClassifier( persistedState, loadedOntology );
    } else {
      return new IncrementalClassifier( persistedState );
    }
  }
View Full Code Here

 
  private void testPersistence( OWLOntology ontology ) throws IOException {
    File testFile = new File( TEST_FILE );
    ModuleExtractor moduleExtractor = createModuleExtractor();
   
    IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, moduleExtractor )
    modular.classify();
   
    MultiValueMap<OWLEntity, OWLEntity> expectedModules = modular.getModules();
     
    FileOutputStream fos = new FileOutputStream( testFile );
 
    IncrementalClassifierPersistence.save( modular, fos );
   
    fos.close();
   
    modular.dispose();
   
    FileInputStream fis = new FileInputStream( testFile );
 
    modular = IncrementalClassifierPersistence.load( fis );
   
    fis.close();
   
    modular.dispose();

    MultiValueMap<OWLEntity, OWLEntity> actualModules = modular.getModules();
   
    Assert.assertEquals( expectedModules, actualModules );
   
    assertTrue( testFile.delete() );
  }
View Full Code Here

TOP

Related Classes of com.clarkparsia.modularity.IncrementalClassifier

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.