Search in sources :

Example 11 with Recipe

use of org.apache.stanbol.rules.base.api.Recipe in project stanbol by apache.

the class RuleStoreTest method getNotExistingRuleByNameInRecipeTest.

private void getNotExistingRuleByNameInRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/test/recipeA"));
    try {
        recipe.getRule("ruleX");
        Assert.fail();
    } catch (NoSuchRuleInRecipeException e) {
        Assert.assertTrue(true);
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe)

Example 12 with Recipe

use of org.apache.stanbol.rules.base.api.Recipe 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 13 with Recipe

use of org.apache.stanbol.rules.base.api.Recipe 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 14 with Recipe

use of org.apache.stanbol.rules.base.api.Recipe in project stanbol by apache.

the class RuleStoreTest method addRuleToRecipeTest.

private void addRuleToRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/test/recipeA"));
    String separator = System.getProperty("line.separator");
    String rule = "rule1[" + separator + "	is(<http://dbpedia.org/ontology/Person>, ?x) . " + separator + "	has(<http://dbpedia.org/ontology/playsInTeam>, ?x, ?y) . " + separator + "	is (<http://dbpedia.org/ontology/FootballTeam>, ?y) " + separator + "		-> " + separator + "	is(<http://dbpedia.org/ontology/FootballPlayer>, ?x)" + separator + "] . " + "rule2[" + separator + "	is(<http://dbpedia.org/ontology/Organisation>, ?x) . " + separator + "	has(<http://dbpedia.org/ontology/hasProduct>, ?x, ?y)" + separator + "		-> " + separator + "	is(<http://dbpedia.org/ontology/Company>, ?x)" + separator + "]";
    store.addRulesToRecipe(recipe, rule, "This is a test rule.");
    if (recipe == null) {
        Assert.fail();
    }
    log.debug("Got recipe with ID " + recipe.getRecipeID().toString());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Recipe(org.apache.stanbol.rules.base.api.Recipe)

Example 15 with Recipe

use of org.apache.stanbol.rules.base.api.Recipe in project stanbol by apache.

the class RefactorerImpl method graphRefactoring.

@SuppressWarnings("unchecked")
@Override
public void graphRefactoring(IRI refactoredOntologyID, IRI datasetID, IRI recipeID) throws RefactoringException, NoSuchRecipeException {
    Recipe recipe;
    try {
        try {
            recipe = ruleStore.getRecipe(recipeID);
            RuleAdapter ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
            List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
            Graph mGraph = tcManager.createGraph(refactoredOntologyID);
            for (ConstructQuery constructQuery : constructQueries) {
                mGraph.addAll(this.sparqlConstruct(constructQuery, datasetID));
            }
        } catch (RecipeConstructionException e) {
            throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
        } catch (UnavailableRuleObjectException e) {
            throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
        } catch (UnsupportedTypeForExportException e) {
            throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
        } catch (RuleAtomCallExeption e) {
            throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
        }
    } catch (NoSuchRecipeException e1) {
        log.error("No Such recipe in the Rule Store", e1);
        throw e1;
    }
}
Also used : ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) Recipe(org.apache.stanbol.rules.base.api.Recipe) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RefactoringException(org.apache.stanbol.rules.refactor.api.RefactoringException) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)

Aggregations

Recipe (org.apache.stanbol.rules.base.api.Recipe)35 IRI (org.apache.clerezza.commons.rdf.IRI)29 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)16 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)16 Graph (org.apache.clerezza.commons.rdf.Graph)11 NoSuchRuleInRecipeException (org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException)9 Rule (org.apache.stanbol.rules.base.api.Rule)9 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)6 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)6 RefactoringException (org.apache.stanbol.rules.refactor.api.RefactoringException)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RecipeImpl (org.apache.stanbol.rules.manager.RecipeImpl)5 InputStream (java.io.InputStream)4 RecipeEliminationException (org.apache.stanbol.rules.base.api.RecipeEliminationException)4 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)4 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)4 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)4