Search in sources :

Example 81 with IRI

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());
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) Recipe(org.apache.stanbol.rules.base.api.Recipe) InputStream(java.io.InputStream) Model(com.hp.hpl.jena.rdf.model.Model) AlreadyExistingRecipeException(org.apache.stanbol.rules.base.api.AlreadyExistingRecipeException) Before(org.junit.Before)

Example 82 with IRI

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);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) Recipe(org.apache.stanbol.rules.base.api.Recipe) Test(org.junit.Test)

Example 83 with IRI

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);
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) Test(org.junit.Test)

Example 84 with IRI

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.");
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) RefactoringException(org.apache.stanbol.rules.refactor.api.RefactoringException) Test(org.junit.Test)

Example 85 with IRI

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();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) WebApplicationException(javax.ws.rs.WebApplicationException) Recipe(org.apache.stanbol.rules.base.api.Recipe) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) Graph(org.apache.clerezza.commons.rdf.Graph) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ByteArrayInputStream(java.io.ByteArrayInputStream) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) MediaType(javax.ws.rs.core.MediaType) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RefactoringException(org.apache.stanbol.rules.refactor.api.RefactoringException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24