Search in sources :

Example 1 with AutoIRIMapper

use of org.semanticweb.owlapi.util.AutoIRIMapper in project stanbol by apache.

the class TestOntologyRegistry method setupSources.

/**
     * Resets the virgin ontology manager for each test.
     * 
     * @throws Exception
     */
@Before
public void setupSources() throws Exception {
    virginOntologyManager = OWLManager.createOWLOntologyManager();
    // Add mappings for any ontologies found in ontologies/registry
    URL url = getClass().getResource("/ontologies/registry");
    assertNotNull(url);
    virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// Population is lazy; no need to add other mappers.
}
Also used : AutoIRIMapper(org.semanticweb.owlapi.util.AutoIRIMapper) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 2 with AutoIRIMapper

use of org.semanticweb.owlapi.util.AutoIRIMapper in project stanbol by apache.

the class TestOntologyLibrary method setup.

/**
     * Resets the {@link OWLOntologyManager} used for tests, since caching phenomena across tests could bias
     * the results.
     * 
     * @throws Exception
     *             if any error occurs;
     */
@Before
public void setup() throws Exception {
    virginOntologyManager = OWLManager.createOWLOntologyManager();
    URL url = getClass().getResource("/ontologies");
    virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
    url = getClass().getResource("/ontologies/registry");
    virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// *Not* adding mappers to empty resource directories.
// It seems the Maven surefire plugin won't copy them.
// url = getClass().getResource("/ontologies/odp");
// virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
}
Also used : AutoIRIMapper(org.semanticweb.owlapi.util.AutoIRIMapper) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 3 with AutoIRIMapper

use of org.semanticweb.owlapi.util.AutoIRIMapper 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)3 URL (java.net.URL)3 AutoIRIMapper (org.semanticweb.owlapi.util.AutoIRIMapper)3 Before (org.junit.Before)2 FileWriter (java.io.FileWriter)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