Search in sources :

Example 26 with Recipe

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

the class RuleStoreTest method removeRecipeTest.

private void removeRecipeTest() throws Exception {
    RecipeList recipeListInitial = store.listRecipes();
    Recipe[] initialRecipes = new Recipe[recipeListInitial.size()];
    initialRecipes = recipeListInitial.toArray(initialRecipes);
    Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/test/recipeA"));
    store.removeRecipe(recipe);
    RecipeList recipeListFinal = store.listRecipes();
    Recipe[] finalRecipes = new Recipe[recipeListInitial.size()];
    finalRecipes = recipeListFinal.toArray(finalRecipes);
    Assert.assertNotSame(initialRecipes, finalRecipes);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Recipe(org.apache.stanbol.rules.base.api.Recipe) RecipeList(org.apache.stanbol.rules.base.api.util.RecipeList)

Example 27 with Recipe

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

the class RuleStoreTest method getExistingRuleByIdInRecipeTest.

private void getExistingRuleByIdInRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/test/recipeA"));
    try {
        Rule rule = recipe.getRule(recipe.listRuleIDs().get(0));
        Assert.assertNotNull(rule);
    } catch (NoSuchRuleInRecipeException e) {
        Assert.fail();
    }
}
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) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 28 with Recipe

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

the class RuleStoreTest method getExistingRuleByNameInRecipeTest.

private void getExistingRuleByNameInRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("http://incubator.apache.com/stanbol/rules/test/recipeA"));
    try {
        Rule rule = recipe.getRule(recipe.listRuleNames().get(0));
        Assert.assertNotNull(rule);
    } catch (NoSuchRuleInRecipeException e) {
        Assert.fail();
    }
}
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) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 29 with Recipe

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

the class ClerezzaRuleStore method findRulesByDescription.

@Override
public RuleList findRulesByDescription(String term) {
    String sparql = "SELECT ?recipe ?rule ?description " + "WHERE { " + "?recipe " + Symbols.hasRule + " ?rule . " + "?rule " + Symbols.description + " ?description . " + "FILTER (regex(?description, \"" + term + "\", \"i\"))" + "}";
    List<IRI> recipeIDs = listRecipeIDs();
    Graph[] tripleCollections = new Graph[recipeIDs.size()];
    for (int i = 0; i < tripleCollections.length; i++) {
        tripleCollections[i] = tcManager.getGraph(recipeIDs.get(i));
    }
    UnionGraph unionGraph = new UnionGraph(tripleCollections);
    RuleList matchingRules = new RuleList();
    try {
        SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql);
        ResultSet resultSet = tcManager.executeSparqlQuery(query, unionGraph);
        while (resultSet.hasNext()) {
            SolutionMapping solutionMapping = resultSet.next();
            IRI recipeID = (IRI) solutionMapping.get("recipe");
            IRI ruleID = (IRI) solutionMapping.get("rule");
            Literal description = (Literal) solutionMapping.get("description");
            try {
                Recipe recipe = getRecipe(recipeID);
                Rule rule = new RecipeRule(recipe, getRule(recipe, ruleID));
                if (description != null) {
                    rule.setDescription(description.getLexicalForm());
                }
                matchingRules.add(rule);
            } catch (NoSuchRecipeException e) {
            // in this case go on in the iteration by fetching other matching recipes
            } catch (RecipeConstructionException e) {
            // in this case go on in the iteration by fetching other matching recipes
            } catch (NoSuchRuleInRecipeException e) {
            // in this case go on in the iteration by fetching other matching recipes
            }
        }
    } catch (ParseException e) {
        log.error("The sparql query contains errors: ", e);
    }
    return matchingRules;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RuleList(org.apache.stanbol.rules.base.api.util.RuleList) SolutionMapping(org.apache.clerezza.rdf.core.sparql.SolutionMapping) Recipe(org.apache.stanbol.rules.base.api.Recipe) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) SelectQuery(org.apache.clerezza.rdf.core.sparql.query.SelectQuery) UnionGraph(org.apache.clerezza.rdf.utils.UnionGraph) Graph(org.apache.clerezza.commons.rdf.Graph) UnionGraph(org.apache.clerezza.rdf.utils.UnionGraph) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Literal(org.apache.clerezza.commons.rdf.Literal) ResultSet(org.apache.clerezza.rdf.core.sparql.ResultSet) Rule(org.apache.stanbol.rules.base.api.Rule) ParseException(org.apache.clerezza.rdf.core.sparql.ParseException)

Example 30 with Recipe

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

the class RecipeIterator method next.

public Recipe next() {
    Recipe recipe = recipes[currentIndex];
    currentIndex++;
    return recipe;
}
Also used : Recipe(org.apache.stanbol.rules.base.api.Recipe)

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