use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class JenaToOwlConvert method ModelJenaToOwlConvert.
// //////////////////////////////////////////////////////////////////////////////
// ////////////////////////////FUNCTIONS/////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts an ontology object from Jena to OWLapi
*
* @param jenamodel
* {An OntModel object}
* @param format
* {only in "RDF/XML"}
* @return {An OWLOntology that is an owl object}
*/
public synchronized OWLOntology ModelJenaToOwlConvert(Model jenamodel, String format) {
while (availablemain == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ModelJenaToOwlConvert::: " + e);
}
}
availablemain = false;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (!format.equals("RDF/XML")) {
System.err.println("The only format supported is RDF/XML. Please check the format!");
availablemain = true;
notifyAll();
return null;
} else {
jenamodel.write(out, format);
OWLOntologyManager owlmanager = OWLManager.createOWLOntologyManager();
OWLOntology owlmodel = owlmanager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(out.toByteArray()));
availablemain = true;
notifyAll();
return owlmodel;
}
} catch (OWLOntologyCreationException eoc) {
System.err.print("ModelJenaToOwlConvert::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class JenaToOwlConvert method AnnotationPropOwlToJena.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single OWLAnnotationProperty of OWL to an AnnotationProperty of Jena
*
* @param data
* {An OWLAnnotationProperty object}
* @param format
* {RDF/XML or TURTLE}
* @return {An AnnotationProperty object}
*/
public synchronized AnnotationProperty AnnotationPropOwlToJena(OWLAnnotationProperty data, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("AnnotationPropOwlToJena::: " + e);
}
}
available = false;
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
OWLDataFactory factory = manager.getOWLDataFactory();
OWLDeclarationAxiom declarationAxiom = factory.getOWLDeclarationAxiom(data);
manager.addAxiom(ontology, declarationAxiom);
OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
available = true;
notifyAll();
return jenamodel.getAnnotationProperty(data.getIRI().toString());
} catch (OWLOntologyCreationException eoc) {
System.err.print("AnnotationPropOwlToJena::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class OntologyManagerInputProvider 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 ReasoningServiceExecutor method executeOWLApiReasoningService.
/**
* Executes the OWLApiReasoingService
*
* @param task
* @param s
* @param input
* @param rules
* @param targetGraphID
* @param parameters
* @return
* @throws InconsistentInputException
* @throws ReasoningServiceException
* @throws UnsupportedTaskException
*/
private ReasoningServiceResult<OWLOntology> executeOWLApiReasoningService(String task, OWLApiReasoningService s, OWLOntology input, List<SWRLRule> rules, String targetGraphID, boolean filtered, Map<String, List<String>> parameters) throws InconsistentInputException, ReasoningServiceException, UnsupportedTaskException {
// Check task: this is managed directly by the endpoint
if (task.equals(ReasoningServiceExecutor.TASK_CHECK)) {
log.debug("Task is '{}'", ReasoningServiceExecutor.TASK_CHECK);
try {
boolean is = s.isConsistent(input);
return new ReasoningServiceResult<OWLOntology>(ReasoningServiceExecutor.TASK_CHECK, is);
} catch (ReasoningServiceException e) {
throw e;
}
}
// We get the manager from the input ontology
// XXX We must be aware of this.
OWLOntologyManager manager = input.getOWLOntologyManager();
try {
OWLOntology output = manager.createOntology();
Set<OWLAxiom> axioms = s.runTask(task, input, rules, filtered, parameters);
log.debug("Prepare output: {} axioms", axioms.size());
manager.addAxioms(output, axioms);
if (targetGraphID == null) {
return new ReasoningServiceResult<OWLOntology>(task, true, manager.getOntology(output.getOntologyID()));
} else {
save(output, targetGraphID);
return new ReasoningServiceResult<OWLOntology>(task, true);
}
} catch (InconsistentInputException e) {
log.warn("The input is not consistent");
return new ReasoningServiceResult<OWLOntology>(ReasoningServiceExecutor.TASK_CHECK, false);
} catch (ReasoningServiceException e) {
throw e;
} catch (OWLOntologyCreationException e) {
log.error("Error! \n", e);
throw new ReasoningServiceException(new IOException(e));
} catch (UnsupportedTaskException e) {
log.error("Error! \n", e);
throw e;
} catch (Throwable t) {
log.error("Error! \n", t);
throw new ReasoningServiceException(t);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class SessionManagerResource method listSessions.
@GET
@Produces(value = { RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN })
public Response listSessions(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
OWLOntologyManager ontMgr = OWLManager.createOWLOntologyManager();
OWLDataFactory df = ontMgr.getOWLDataFactory();
OWLClass cSession = df.getOWLClass(IRI.create("http://stanbol.apache.org/ontologies/meta/Session"));
OWLOntology o;
try {
o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri()));
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
for (String id : sessionManager.getRegisteredSessionIDs()) {
IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id);
OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid);
changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind)));
}
ontMgr.applyChanges(changes);
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
ResponseBuilder rb = Response.ok(o);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations