use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException 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();
}
}
use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException 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();
}
}
use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException 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;
}
use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException in project stanbol by apache.
the class RecipeImpl method getRule.
@Override
public Rule getRule(IRI ruleID) throws NoSuchRuleInRecipeException {
for (Rule rule : ruleList) {
if (rule.getRuleID().toString().equals(ruleID.toString())) {
return rule;
}
}
StringBuilder message = new StringBuilder();
message.append("No rule with ID ");
message.append(ruleID.toString());
message.append(" exists in recipe ");
message.append(this.getRecipeID());
throw new NoSuchRuleInRecipeException(message.toString());
}
use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException in project stanbol by apache.
the class RecipeImpl method getRule.
public Rule getRule(String ruleName) throws NoSuchRuleInRecipeException {
for (Rule rule : ruleList) {
if (rule.getRuleName().equals(ruleName)) {
return rule;
}
}
StringBuilder message = new StringBuilder();
message.append("No rule named ");
message.append(ruleName);
message.append(" exists in recipe ");
message.append(this.getRecipeID());
throw new NoSuchRuleInRecipeException(message.toString());
}
Aggregations