use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class TestOntologyReconciliation method versionedOnlyFromStream.
/*
* If an ontology has no ontology IRI but does have a version IRI, it should still be possible to load it,
* but the version IRI must be erased.
*/
@Test
public void versionedOnlyFromStream() throws Exception {
String location = "/ontologies/naming/versionedonly.owl";
InputStream in = getClass().getResourceAsStream(location);
in.mark(Integer.MAX_VALUE);
OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
// Ensure that the OWL API erases the version IRI.
assertTrue(o1.isAnonymous());
assertNull(o1.getOntologyID().getVersionIRI());
in.reset();
// in = getClass().getResourceAsStream(location); // use if stream cannot be reset
// The public key must be non-anonymous nonetheless.
OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
assertNotNull(key);
assertFalse(key.isAnonymous());
assertNull(key.getVersionIRI());
log.info("Wrongly versioned ontology loaded with public key {}", key);
assertFalse(o1.equals(key));
OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
assertNotNull(o1_1);
assertTrue(o1_1.isAnonymous());
assertNull(o1_1.getOntologyID().getVersionIRI());
// Cannot equal two OWLOntology objects, especially if anonymous.
// Check that they match axiom-wise.
log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
assertEquals(o1.getTBoxAxioms(false), o1_1.getTBoxAxioms(false));
log.info(" -- TBox axiom check successful.");
assertEquals(o1.getABoxAxioms(false), o1_1.getABoxAxioms(false));
log.info(" -- ABox axiom check successful.");
// No aliases should have been created.
assertSame(0, ontologyProvider.listAliases(key).size());
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class ScopeResource method getCoreSpaceOWL.
@GET
@Path("/core")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getCoreSpaceOWL(@PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
scope = onm.getScope(scopeid);
OntologySpace space = scope.getCoreSpace();
IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
OWLOntology o = space.export(OWLOntology.class, merge, prefix);
ResponseBuilder rb = Response.ok(o);
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.semanticweb.owlapi.model.OWLOntology 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();
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class TestOntologyRegistry method testLoopInLibrary.
@Test
public void testLoopInLibrary() throws Exception {
// Create the model from the looping registry.
OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_LOOP);
Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
// There has to be a single registry, with the expected number of children (one).
assertEquals(1, rs.size());
Registry r = rs.iterator().next();
assertTrue(r.hasChildren());
int count = 1;
assertEquals(count, r.getChildren().length);
// There are no libreries without ontologies in the test registry.
for (RegistryItem child : r.getChildren()) {
assertTrue(child instanceof Library);
// Check both parent-child relations.
assertTrue(child.hasChildren());
for (RegistryItem grandchild : child.getChildren()) {
assertTrue(grandchild instanceof RegistryOntology);
assertTrue(grandchild.hasParents());
assertTrue(Arrays.asList(grandchild.getParents()).contains(child));
}
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class TestOntologyRegistry method testRegistryUnion.
/**
* Verifies that, when loading multiple registries that add library information to each other, the overall
* model reflects the union of these registries.
*
* @throws Exception
*/
@Test
public void testRegistryUnion() throws Exception {
// Create the model from two overlapping registries.
Set<OWLOntology> regs = new HashSet<OWLOntology>();
regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
Set<Registry> rs = regman.createModel(regs);
for (Registry r : rs) {
// The nonexistent library should also be included, if using the more powerful algorithm.
// set to 2 if using the less powerful algorithm.
int count = 3;
if (Locations._REGISTRY_TEST.equals(r.getIRI()))
assertEquals(count, r.getChildren().length);
else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI()))
assertEquals(1, r.getChildren().length);
// Check that we find the expected ontology in the expected library.
for (RegistryItem lib : r.getChildren()) {
if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
boolean found = false;
for (RegistryItem child : lib.getChildren()) {
if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
found = true;
break;
}
}
assertTrue(found);
break;
}
}
}
}
Aggregations