use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RefactoringTest method setUp.
@Before
public void setUp() {
String separator = System.getProperty("line.separator");
rule = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . endsWith(str(?x), \"Person\") -> is(foaf:Person, ?x) ]";
InputStream inputStream = RefactoringTest.class.getResourceAsStream("/META-INF/test/testKReSOnt.owl");
Model jenaModel = ModelFactory.createDefaultModel();
jenaModel = jenaModel.read(inputStream, null);
tripleCollection = JenaToClerezzaConverter.jenaModelToClerezzaGraph(jenaModel);
Graph mGraph = tcm.createGraph(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/graph"));
mGraph.addAll(tripleCollection);
Recipe recipe;
try {
recipe = store.createRecipe(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/recipeA"), "Recipe for testing the Refactor.");
recipe = store.addRulesToRecipe(recipe, rule, "Test");
} catch (AlreadyExistingRecipeException e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RefactoringTest method refactoringTest.
@Test
public void refactoringTest() throws Exception {
Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/recipeA"));
Graph tc = refactorer.graphRefactoring(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/graph"), recipe.getRecipeID());
Assert.assertNotNull(tc);
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RefactoringTest method refactoringWithNonExistentRecipeTest.
@Test
public void refactoringWithNonExistentRecipeTest() throws Exception {
try {
refactorer.graphRefactoring(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/refactoredGraph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/graph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/recipeB"));
Assert.fail();
} catch (NoSuchRecipeException e) {
Assert.assertTrue(e.getMessage(), true);
}
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RefactoringTest method persistentRefactoringTest.
@Test
public void persistentRefactoringTest() throws Exception {
try {
refactorer.graphRefactoring(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/refactoredGraph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/graph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/recipeA"));
Graph tc = tcm.getGraph(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/refactoredGraph"));
Assert.assertNotNull(tc);
} catch (RefactoringException e) {
fail("Error while refactoring.");
}
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RefactorResource method performRefactoring.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(value = { TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, RDF_JSON, X_TURTLE })
public Response performRefactoring(MultiPartBody data, @Context HttpHeaders headers) {
String recipe = null;
InputStream input = null;
if (data.getTextParameterValues("recipe") != null) {
recipe = data.getTextParameterValues("recipe")[0];
}
if (data.getFormFileParameterValues("input") != null) {
input = new ByteArrayInputStream(data.getFormFileParameterValues("input")[0].getContent());
}
if (recipe == null || input == null) {
throw new WebApplicationException(BAD_REQUEST);
}
// Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
ResponseBuilder rb;
Recipe rcp;
try {
URI uri = new URI(recipe);
if (uri != null && uri.getScheme() == null) {
recipe = "urn:" + recipe;
log.info("The recipe ID is a URI without scheme. The ID is set to " + recipe);
}
IRI recipeID = new IRI(recipe);
rcp = ruleStore.getRecipe(recipeID);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology inputOntology = manager.loadOntologyFromOntologyDocument(input);
Graph tripleCollection = refactorer.graphRefactoring(OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(inputOntology), rcp);
OWLOntology outputOntology = OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(tripleCollection);
rb = Response.ok(outputOntology);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
} catch (NoSuchRecipeException e) {
rb = Response.status(NOT_FOUND);
log.error(e.getMessage(), e);
} catch (RecipeConstructionException e) {
rb = Response.status(NO_CONTENT);
log.error(e.getMessage(), e);
} catch (OWLOntologyCreationException e) {
rb = Response.status(PRECONDITION_FAILED);
log.error(e.getMessage(), e);
} catch (RefactoringException e) {
rb = Response.status(INTERNAL_SERVER_ERROR);
log.error(e.getMessage(), e);
} catch (URISyntaxException e) {
rb = Response.status(NOT_ACCEPTABLE);
log.error(e.getMessage(), e);
}
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations