Search in sources :

Example 76 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager 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)

Example 77 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.

the class OntologyImportUtils method printOntology.

@Deprecated
public static void printOntology(OWLOntology o, PrintStream printer) {
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    StringDocumentTarget tgt = new StringDocumentTarget();
    try {
        mgr.saveOntology(o, new RDFXMLOntologyFormat(), tgt);
    } catch (OWLOntologyStorageException e) {
        e.printStackTrace(printer);
    }
    printer.println(tgt.toString());
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) StringDocumentTarget(org.semanticweb.owlapi.io.StringDocumentTarget) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 78 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.

the class ByteArrayInputProvider method createOWLOntologyManager.

@SuppressWarnings("deprecation")
private OWLOntologyManager createOWLOntologyManager() {
    // We isolate here the creation of the temporary manager
    // TODO How to behave when resolving owl:imports?
    // We should set the manager to use a service to lookup for ontologies,
    // instead of trying on the web
    // directly/only
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    // FIXME Which is the other way of doing this?
    // Maybe -> OWLOntologyManagerProperties();
    manager.setSilentMissingImportsHandling(true);
    // Listening for missing imports
    manager.addMissingImportListener(new MissingImportListener() {

        @Override
        public void importMissing(MissingImportEvent arg0) {
            log.warn("Missing import {} ", arg0.getImportedOntologyURI());
        }
    });
    manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {

        @Override
        public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
            log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
        }

        @Override
        public void startedLoadingOntology(LoadingStartedEvent arg0) {
            log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
            log.info(" ... from {}", arg0.getDocumentIRI().toString());
        }
    });
    return manager;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 79 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.

the class UrlInputProvider method createOWLOntologyManager.

@SuppressWarnings("deprecation")
private OWLOntologyManager createOWLOntologyManager() {
    // We isolate here the creation of the temporary manager
    // TODO How to behave when resolving owl:imports?
    // We should set the manager to use a service to lookup for ontologies,
    // instead of trying on the web
    // directly
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    // FIXME Which is the other way of doing this?
    // Maybe -> OWLOntologyManagerProperties();
    manager.setSilentMissingImportsHandling(true);
    // Listening for missing imports
    manager.addMissingImportListener(new MissingImportListener() {

        @Override
        public void importMissing(MissingImportEvent arg0) {
            log.warn("Missing import {} ", arg0.getImportedOntologyURI());
        }
    });
    manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {

        @Override
        public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
            log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
        }

        @Override
        public void startedLoadingOntology(LoadingStartedEvent arg0) {
            log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
            log.info(" ... from {}", arg0.getDocumentIRI().toString());
        }
    });
    return manager;
}
Also used : MissingImportListener(org.semanticweb.owlapi.model.MissingImportListener) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) MissingImportEvent(org.semanticweb.owlapi.model.MissingImportEvent) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 80 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.

the class AbstractOWLApiReasoningService method run.

/**
 * Merges the SWRL rules in the input ontology, then calls run(OWLOntology,List<InferredAxiomGenerator<?
 * extends OWLAxiom>>)
 *
 * @param ontology
 * @param rules
 * @param generators
 * @return
 */
@Override
public Set<OWLAxiom> run(OWLOntology ontology, List<SWRLRule> rules, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException, InconsistentInputException {
    log.debug("Called method run(OWLOntology,List<SWRLRule>,List)");
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    log.debug("Adding SWRL rules to the input ontology.");
    Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
    ruleSet.addAll(rules);
    manager.addAxioms(ontology, ruleSet);
    if (log.isDebugEnabled())
        for (OWLAxiom a : ontology.getAxioms()) {
            log.debug("Axiom {}", a);
        }
    log.debug("Calling the run method.");
    return run(ontology, generators);
}
Also used : SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) HashSet(java.util.HashSet)

Aggregations

OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)83 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)52 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)42 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)23 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)21 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)17 IRI (org.semanticweb.owlapi.model.IRI)14 HashSet (java.util.HashSet)13 AddImport (org.semanticweb.owlapi.model.AddImport)12 OWLClass (org.semanticweb.owlapi.model.OWLClass)12 Test (org.junit.Test)11 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)10 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)10 OntModel (com.hp.hpl.jena.ontology.OntModel)9 InputStream (java.io.InputStream)9 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)9 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)9 ArrayList (java.util.ArrayList)8 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)8 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)8