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();
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class ScopeResource method manageOntology.
/**
* Tells the session that it should manage the ontology obtained by dereferencing the supplied IRI.<br>
* <br>
* Note that the PUT method cannot be used, as it is not possible to predict what ID the ontology will
* have until it is parsed.
*
* @param content
* the ontology physical IRI
* @return {@link Status#OK} if the addition was successful, {@link Status#NOT_FOUND} if there is no such
* session at all, {@link Status#FORBIDDEN} if the session is locked or cannot modified for some
* other reason, {@link Status#INTERNAL_SERVER_ERROR} if some other error occurs.
*/
@POST
@Consumes(value = MediaType.TEXT_PLAIN)
public Response manageOntology(String iri, @PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
ResponseBuilder rb;
scope = onm.getScope(scopeid);
if (scope == null)
rb = Response.status(NOT_FOUND);
else
try {
OWLOntologyID key = scope.getCustomSpace().addOntology(new RootOntologySource(IRI.create(iri)));
URI created = getCreatedResource(OntologyUtils.encode(key));
rb = Response.created(created);
} catch (UnmodifiableOntologyCollectorException e) {
throw new WebApplicationException(e, FORBIDDEN);
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class HermitReasoningServiceTest method testClassifyWithRules.
private void testClassifyWithRules(String testID, String rulesID, String testExpectedID) {
log.info("Testing the task CLASSIFY with rules");
OWLOntologyManager manager = TestData.manager;
// We prepare the input ontology
try {
OWLOntology testOntology = manager.createOntology();
OWLOntologyID testOntologyID = testOntology.getOntologyID();
log.debug("Created test ontology with ID: {}", testOntologyID);
OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
manager.applyChange(new AddImport(testOntology, importTest));
Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
// Maybe we want to see the list of rules
if (log.isDebugEnabled()) {
log.debug("List of {} rules: ", rules.size());
TestUtils.debug(rules, log);
}
log.debug("We add the rules to the ontology");
manager.addAxioms(manager.getOntology(testOntologyID), rules);
// Maybe we want to see what is in before
if (log.isDebugEnabled())
log.debug("Content of the input is:");
TestUtils.debug(manager.getOntology(testOntologyID), log);
// Now we test the method
log.debug("Running HermiT");
Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.CLASSIFY, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
log.debug("{} inferred axioms:", inferred.size());
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
// We consider here only two kind of axioms
if (expected instanceof OWLSubClassOfAxiom || expected instanceof OWLClassAssertionAxiom) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
}
assertTrue(missing.isEmpty());
// We want to remove the ontology from the manager
manager.removeOntology(testOntology);
} catch (OWLOntologyCreationException e) {
log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
assertTrue(false);
} catch (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
Aggregations