use of org.apache.stanbol.rules.base.api.util.RecipeList in project stanbol by apache.
the class ClerezzaRuleStore method findRecipesByDescription.
@Override
public RecipeList findRecipesByDescription(String term) {
String sparql = "SELECT ?recipe " + "WHERE { ?recipe a " + Symbols.Recipe.toString() + " . " + "?recipe " + Symbols.description + " ?description . " + "FILTER (regex(?description, \"" + term + "\", \"i\"))" + "}";
Graph tripleCollection = tcManager.getGraph(new IRI(recipeIndexLocation));
RecipeList matchingRecipes = new RecipeList();
try {
SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql);
ResultSet resultSet = tcManager.executeSparqlQuery(query, tripleCollection);
while (resultSet.hasNext()) {
SolutionMapping solutionMapping = resultSet.next();
IRI recipeID = (IRI) solutionMapping.get("recipe");
try {
Recipe recipe = getRecipe(recipeID);
log.info("Found recipe {}.", recipeID.toString());
matchingRecipes.add(recipe);
log.info("Found {} matching recipes.", matchingRecipes.size());
} 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 (ParseException e) {
log.error("The sparql query contains errors: ", e);
}
return matchingRecipes;
}
use of org.apache.stanbol.rules.base.api.util.RecipeList in project stanbol by apache.
the class ClerezzaRuleStore method listRecipes.
@Override
public RecipeList listRecipes() throws NoSuchRecipeException, RecipeConstructionException {
RecipeList recipeList = new RecipeList();
for (IRI recipeID : recipes) {
Recipe recipe;
try {
recipe = getRecipe(recipeID);
} catch (NoSuchRecipeException e) {
throw e;
} catch (RecipeConstructionException e) {
throw e;
}
recipeList.add(recipe);
}
log.info("The Clerezza rule store contains {} recipes", recipeList.size());
return recipeList;
}
use of org.apache.stanbol.rules.base.api.util.RecipeList in project stanbol by apache.
the class RulesResource method listRecipes.
@GET
@Path("/recipe")
@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL })
public Response listRecipes(@Context HttpHeaders headers) {
ResponseBuilder responseBuilder = null;
try {
RecipeList recipeList = getListRecipes();
responseBuilder = Response.ok(recipeList);
} catch (NoSuchRecipeException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.NOT_FOUND);
} catch (RecipeConstructionException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.INTERNAL_SERVER_ERROR);
}
// addCORSOrigin(servletContext, responseBuilder, headers);
return responseBuilder.build();
}
use of org.apache.stanbol.rules.base.api.util.RecipeList 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);
}
use of org.apache.stanbol.rules.base.api.util.RecipeList in project stanbol by apache.
the class RulesResource method findRecipes.
/**
* It returns the list of recipes whose descriptions match the string passed in the description parameter.<br>
* If some recipe matches the description passed a 200 code with the list of recipes is returned.
* Otherwise a 404 status code is returned.
*
* @param description
* {@link String}
* @return <ul>
* <li>200: The list of recipe matching the description provided is returned</li>
* <li>404: No recipe matches the description provided</li>
* </ul>
*/
@GET
@Produces(value = { MediaType.APPLICATION_JSON, KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, MediaType.TEXT_PLAIN })
@Path("/find/recipes")
public Response findRecipes(@QueryParam("description") String description) {
log.info("Searching for recipes with description like to {}.", description);
RecipeList recipes = ruleStore.findRecipesByDescription(description);
log.info("The recipe list is emplty? {} ", recipes.isEmpty());
if (recipes.isEmpty()) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(recipes).build();
}
Aggregations