use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace 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.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ScopeResource method getCustomSpaceOWL.
@GET
@Path("/custom")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getCustomSpaceOWL(@PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
scope = onm.getScope(scopeid);
OntologySpace space = scope.getCustomSpace();
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.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ScopeResource method managedOntologyGetGraph.
/**
* Gets the ontology with the given identifier in its version managed by the session.
*
* @param sessionId
* the session identifier.
* @param ontologyId
* the ontology identifier.
* @param uriInfo
* @param headers
* @return the requested managed ontology, or {@link Status#NOT_FOUND} if either the sessionn does not
* exist, or the if the ontology either does not exist or is not managed.
*/
@GET
@Path("/{ontologyId:.+}")
@Produces(value = { APPLICATION_JSON, N3, N_TRIPLE, RDF_JSON })
public Response managedOntologyGetGraph(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
log.debug("Absolute URL Path {}", uriInfo.getRequestUri());
log.debug("Ontology ID {}", ontologyId);
ResponseBuilder rb;
scope = onm.getScope(scopeid);
if (scope == null)
rb = Response.status(NOT_FOUND);
else {
IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
ImmutableGraph o = null;
OWLOntologyID id = OntologyUtils.decode(ontologyId);
OntologySpace spc = scope.getCustomSpace();
if (spc != null && spc.hasOntology(id)) {
o = spc.getOntology(id, ImmutableGraph.class, merge, prefix);
} else {
spc = scope.getCoreSpace();
if (spc != null && spc.hasOntology(id))
o = spc.getOntology(id, ImmutableGraph.class, merge, prefix);
}
if (o == null)
rb = Response.status(NOT_FOUND);
else
rb = Response.ok(o);
}
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ScopeImpl method exportToOWLOntology.
/**
* Get an OWL API {@link OWLOntology} representation of the scope.
*
* @param merge
* if true the core and custom spaces will be recursively merged with the scope ontology,
* otherwise owl:imports statements will be added.
* @return the OWL representation of the scope.
*/
protected OWLOntology exportToOWLOntology(boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
// if (merge) throw new UnsupportedOperationException(
// "Ontology merging only implemented for managed ontologies, not for collectors. "
// + "Please set merge parameter to false.");
// Create an ontology manager on the fly. We don't really need a permanent one.
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLDataFactory df = mgr.getOWLDataFactory();
OWLOntology ont = null;
try {
if (merge) {
final Set<OWLOntology> set = new HashSet<OWLOntology>();
log.debug("Merging custom space of {}.", getID());
set.add(this.getCustomSpace().export(OWLOntology.class, merge));
log.debug("Merging core space of {}.", getID());
set.add(this.getCoreSpace().export(OWLOntology.class, merge));
OWLOntologySetProvider provider = new OWLOntologySetProvider() {
@Override
public Set<OWLOntology> getOntologies() {
return set;
}
};
OWLOntologyMerger merger = new OWLOntologyMerger(provider);
try {
ont = merger.createMergedOntology(OWLManager.createOWLOntologyManager(), org.semanticweb.owlapi.model.IRI.create(getDefaultNamespace() + getID()));
} catch (OWLOntologyCreationException e) {
log.error("Failed to merge imports for ontology.", e);
ont = null;
}
} else {
// The root ontology ID is in the form [namespace][scopeId]
ont = mgr.createOntology(org.semanticweb.owlapi.model.IRI.create(universalPrefix + getID()));
List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
// Add the import statement for the custom space, if existing and not empty
OntologySpace spc = getCustomSpace();
if (spc != null && spc.listManagedOntologies().size() > 0) {
org.semanticweb.owlapi.model.IRI spaceIri = org.semanticweb.owlapi.model.IRI.create(universalPrefix + spc.getID());
additions.add(new AddImport(ont, df.getOWLImportsDeclaration(spaceIri)));
}
// Add the import statement for the core space, if existing and not empty
spc = getCoreSpace();
if (spc != null && spc.listManagedOntologies().size() > 0) {
org.semanticweb.owlapi.model.IRI spaceIri = org.semanticweb.owlapi.model.IRI.create(universalPrefix + spc.getID());
additions.add(new AddImport(ont, df.getOWLImportsDeclaration(spaceIri)));
}
mgr.applyChanges(additions);
}
} catch (OWLOntologyCreationException e) {
log.error("Failed to generate an OWL form of scope " + getID(), e);
ont = null;
}
return ont;
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ScopeManagerImpl method rebuildScopes.
private void rebuildScopes() {
OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
for (String scopeId : struct.getScopeIDs()) {
long before = System.currentTimeMillis();
log.debug("Rebuilding scope with ID \"{}\".", scopeId);
Collection<OWLOntologyID> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
OntologyInputSource<?>[] srcs = new OntologyInputSource<?>[coreOnts.size()];
int i = 0;
for (OWLOntologyID coreOnt : coreOnts) {
log.debug("Core ontology key : {}", coreOnts);
srcs[i++] = new StoredOntologySource(coreOnt);
}
Scope scope;
try {
scope = createOntologyScope(scopeId, srcs);
} catch (DuplicateIDException e) {
String dupe = e.getDuplicateID();
log.warn("Scope \"{}\" already exists and will be reused.", dupe);
scope = getScope(dupe);
}
OntologySpace custom = scope.getCustomSpace();
// Register even if some ontologies were to fail to be restored afterwards.
scopeMap.put(scopeId, scope);
for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId)) try {
log.debug("Custom ontology key : {}", key);
custom.addOntology(new StoredOntologySource(key));
} catch (MissingOntologyException ex) {
log.error("Could not find an ontology with public key {} to be managed by scope \"{}\". Proceeding to next ontology.", key, scopeId);
continue;
} catch (Exception ex) {
log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt scope \"" + scopeId + "\". proceeding to next ontology", ex);
continue;
}
log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
}
}
Aggregations