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();
}
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());
}
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;
}
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;
}
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);
}
Aggregations