Search in sources :

Example 1 with WriterDocumentTarget

use of org.semanticweb.owlapi.io.WriterDocumentTarget in project stanbol by apache.

the class TestOWLAPIInputSources method testAutoIRIMapper.

@Test
public void testAutoIRIMapper() throws Exception {
    URL url = getClass().getResource("/ontologies");
    assertNotNull(url);
    File file = new File(url.toURI());
    assertTrue(file.exists());
    assertTrue(file.isDirectory());
    OWLOntologyIRIMapper mapper = new AutoIRIMapper(file, true);
    IRI dummyiri = IRI.create("http://stanbol.apache.org/ontologies/peanuts/dummycharacters.owl");
    // Cleanup may be required if previous tests have failed.
    if (mapper.getDocumentIRI(dummyiri) != null) {
        new File(mapper.getDocumentIRI(dummyiri).toURI()).delete();
        ((AutoIRIMapper) mapper).update();
    }
    assertFalse(dummyiri.equals(mapper.getDocumentIRI(dummyiri)));
    // Create a new ontology in the test resources.
    OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(null);
    OWLOntology o = mgr.createOntology(dummyiri);
    File f = new File(URI.create(url.toString() + "/dummycharacters.owl"));
    mgr.saveOntology(o, new WriterDocumentTarget(new FileWriter(f)));
    assertTrue(f.exists());
    ((AutoIRIMapper) mapper).update();
    // The old mapper should be able to locate the new ontology.
    assertFalse(dummyiri.equals(mapper.getDocumentIRI(dummyiri)));
    // A new mapper too
    OWLOntologyIRIMapper mapper2 = new AutoIRIMapper(new File(url.toURI()), true);
    assertFalse(dummyiri.equals(mapper2.getDocumentIRI(dummyiri)));
    // cleanup
    f.delete();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) WriterDocumentTarget(org.semanticweb.owlapi.io.WriterDocumentTarget) OWLOntologyIRIMapper(org.semanticweb.owlapi.model.OWLOntologyIRIMapper) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) FileWriter(java.io.FileWriter) AutoIRIMapper(org.semanticweb.owlapi.util.AutoIRIMapper) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 URL (java.net.URL)1 Test (org.junit.Test)1 WriterDocumentTarget (org.semanticweb.owlapi.io.WriterDocumentTarget)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyIRIMapper (org.semanticweb.owlapi.model.OWLOntologyIRIMapper)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1 AutoIRIMapper (org.semanticweb.owlapi.util.AutoIRIMapper)1