use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class JenaToOwlConvert method ModelJenaToOwlConvert.
/**
* 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(IRI ontologyIRI, 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();
owlmanager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(out.toByteArray()));
OWLOntologyMerger merger = new OWLOntologyMerger(owlmanager);
OWLOntology ontology = merger.createMergedOntology(owlmanager, ontologyIRI);
availablemain = true;
notifyAll();
return ontology;
}
} catch (OWLOntologyCreationException eoc) {
System.err.print("ModelJenaToOwlConvert::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class JenaToOwlConvert method ClassOwlToJena.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single OWLClass of OWLAPI to an OntClass of Jena
*
* @param data
* {An OWLClass}
* @param format
* {RDF/XML or TURTLE}
* @return {An OntClass}
*/
public synchronized OntClass ClassOwlToJena(OWLClass data, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ClassOwlToJena::: " + 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.getOntClass(data.getIRI().toString());
} catch (OWLOntologyCreationException eoc) {
System.err.print("ClassOwlToJena::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class OWLAPIToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the OWL ontology for the test. Simply add the axioms: AndreaNuzzolese isA Person -> class
* assertion axiom EnricoDaga isA Person -> class assertion axiom AndreaNuzzolese knows EnricoDaga ->
* object property assertion axiom
*/
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
try {
ontology = manager.createOntology(org.semanticweb.owlapi.model.IRI.create(ns + "testOntology"));
} catch (OWLOntologyCreationException e) {
log.error(e.getMessage());
}
if (ontology != null) {
OWLClass personClass = factory.getOWLClass(org.semanticweb.owlapi.model.IRI.create(foaf + "Person"));
OWLNamedIndividual andreaNuzzoleseOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "AndreaNuzzolese"));
OWLNamedIndividual enricoDagaOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "EnricoDaga"));
OWLObjectProperty knowsOWL = factory.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(foaf + "knows"));
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(personClass, andreaNuzzoleseOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(personClass, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(knowsOWL, andreaNuzzoleseOWL, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
}
/*
* Set-up the Clerezza model for the test. As before simply add the triples: AndreaNuzzolese isA
* Person EnricoDaga isA Person AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class RootResource method storeOntology.
/**
* POSTs an ontology content as application/x-www-form-urlencoded
*
* @param content
* @param headers
* @return
*/
@POST
@Consumes(value = { RDF_XML, TURTLE, X_TURTLE, N3, N_TRIPLE, OWL_XML, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON })
public Response storeOntology(InputStream content, @Context HttpHeaders headers) {
long before = System.currentTimeMillis();
ResponseBuilder rb;
MediaType mt = headers.getMediaType();
if (RDF_XML_TYPE.equals(mt) || TURTLE_TYPE.equals(mt) || X_TURTLE_TYPE.equals(mt) || N3_TYPE.equals(mt) || N_TRIPLE_TYPE.equals(mt) || RDF_JSON_TYPE.equals(mt)) {
OWLOntologyID key = null;
try {
key = ontologyProvider.loadInStore(content, headers.getMediaType().toString(), true);
rb = Response.ok();
} catch (UnsupportedFormatException e) {
log.warn("POST method failed for media type {}. This should not happen (should fail earlier)", headers.getMediaType());
rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
} catch (IOException e) {
throw new WebApplicationException(e, BAD_REQUEST);
}
// An exception should have been thrown earlier, but just in case.
if (key == null || key.isAnonymous()) {
rb = Response.status(Status.INTERNAL_SERVER_ERROR);
}
} else if (OWL_XML_TYPE.equals(mt) || FUNCTIONAL_OWL_TYPE.equals(mt) || MANCHESTER_OWL_TYPE.equals(mt)) {
try {
OntologyInputSource<OWLOntology> src = new OntologyContentInputSource(content);
ontologyProvider.loadInStore(src.getRootOntology(), true);
rb = Response.ok();
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
} else {
rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
}
// addCORSOrigin(servletContext, rb, headers);
Response r = rb.build();
log.debug("POST request for ontology addition completed in {} ms with status {}.", (System.currentTimeMillis() - before), r.getStatus());
return r;
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class ScopeResource method registerScope.
/**
* At least one between corereg and coreont must be present. Registry iris supersede ontology iris.
*
* @param scopeid
* @param coreRegistry
* a. If it is a well-formed IRI it supersedes <code>coreOntology</code>.
* @param coreOntologies
* @param customRegistry
* a. If it is a well-formed IRI it supersedes <code>customOntology</code>.
* @param customOntologies
* @param activate
* if true, the new scope will be activated upon creation.
* @param uriInfo
* @param headers
* @return
*/
@PUT
@Consumes(MediaType.WILDCARD)
public Response registerScope(@PathParam("scopeid") String scopeid, @QueryParam("corereg") final List<String> coreRegistries, @QueryParam("coreont") final List<String> coreOntologies, @DefaultValue("false") @QueryParam("activate") boolean activate, @Context HttpHeaders headers) {
log.debug("Request URI {}", uriInfo.getRequestUri());
scope = onm.getScope(scopeid);
List<OntologyInputSource<?>> srcs = new ArrayList<OntologyInputSource<?>>(coreOntologies.size() + coreRegistries.size());
// First thing, check registry sources.
if (coreRegistries != null)
for (String reg : coreRegistries) if (reg != null && !reg.isEmpty())
try {
// Library IDs are sanitized differently
srcs.add(new LibrarySource(URIUtils.desanitize(IRI.create(reg)), regMgr));
} catch (Exception e1) {
throw new WebApplicationException(e1, BAD_REQUEST);
// Bad or not supplied core registry, try the ontology.
}
// Then ontology sources
if (coreOntologies != null)
for (String ont : coreOntologies) if (ont != null && !ont.isEmpty())
try {
srcs.add(new RootOntologySource(IRI.create(ont)));
} catch (OWLOntologyCreationException e2) {
// If this fails too, throw a bad request.
throw new WebApplicationException(e2, BAD_REQUEST);
}
// Now the creation.
try {
// Expand core sources
List<OntologyInputSource<?>> expanded = new ArrayList<OntologyInputSource<?>>();
for (OntologyInputSource<?> coreSrc : srcs) if (coreSrc != null) {
if (coreSrc instanceof SetInputSource) {
for (Object o : ((SetInputSource<?>) coreSrc).getOntologies()) {
OntologyInputSource<?> src = null;
if (o instanceof OWLOntology)
src = new RootOntologySource((OWLOntology) o);
else if (o instanceof Graph)
src = new GraphSource((Graph) o);
if (src != null)
expanded.add(src);
}
} else
// Must be denoting a single ontology
expanded.add(coreSrc);
}
scope = onm.createOntologyScope(scopeid, expanded.toArray(new OntologyInputSource[0]));
// Setup and register the scope. If no custom space was set, it will
// still be open for modification.
scope.setUp();
onm.setScopeActive(scopeid, activate);
} catch (DuplicateIDException e) {
throw new WebApplicationException(e, CONFLICT);
} catch (Exception ex) {
throw new WebApplicationException(ex, INTERNAL_SERVER_ERROR);
}
ResponseBuilder rb = Response.created(uriInfo.getAbsolutePath());
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations