List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
while (importedonto.hasNext()) {
OWLOntology auxonto = importedonto.next();
additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
.getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
}
if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);
for (int i = 0; i < recipe.size(); i++) {
OWLNamedIndividual ind = factory.getOWLNamedIndividual(recipe.get(i));
Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
}
// try {
// OWLManager.createOWLOntologyManager().saveOntology(
// newmodel,
// newmodel.getOWLOntologyManager()
// .getOntologyFormat(newmodel),
// System.out);
// } catch (OWLOntologyStorageException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
ResponseBuilder rb = Response.ok(newmodel);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
} else {
HashMap<IRI,String> recipe = rule.getRecipe(IRI.create(uri));
if (recipe == null) {
// The recipe deos not exists in the manager
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
// The recipe is retrieved (import declarations point to
// KReS Services)
OWLOntology onto = ruleStore.getOntology();
OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();
OWLObjectProperty prop = factory.getOWLObjectProperty(IRI
.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(uri));
Set<OWLIndividual> value = ind.getObjectPropertyValues(prop, onto);
Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
Iterator<OWLIndividual> iter = value.iterator();
OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
onto.getOntologyID());
Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
while (importedonto.hasNext()) {
OWLOntology auxonto = importedonto.next();
additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
.getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
}
if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);