@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; }
public boolean retainAll(Collection<?> c) { Recipe[] recipesCopy = null; Recipe[] recipesTMP = null; for (Object o : c) { if (o instanceof Recipe) { if (contains(o)) { if (recipesCopy == null) { recipesCopy = new Recipe[1]; recipesCopy[0] = (Recipe) o; } else { recipesTMP = new Recipe[recipesCopy.length + 1]; System.arraycopy(recipesCopy, 0, recipesTMP, 0, recipesCopy.length); recipesTMP[recipesTMP.length - 1] = (Recipe) o; recipesCopy = recipesTMP; } } } } recipes = recipesCopy; return true; }
RecipeList classObject = new RecipeList(); classObject.updateList(editedRecipe); selectedRecipe = editedRecipe; this.loadActivity(editedRecipe);
/** * 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(); }
@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; }
public boolean removeAll(Collection<?> c) { if (contains(c)) { for (Object o : c) { boolean removed = false; for (int i = 0; i < recipes.length && !removed; i++) { Recipe recipe = recipes[i]; if (recipe.equals(o)) { Recipe[] recipesCopy = new Recipe[recipes.length - 1]; System.arraycopy(recipes, 0, recipesCopy, 0, i); System.arraycopy(recipes, i + 1, recipesCopy, 0, recipesCopy.length - i); recipes = recipesCopy; removed = true; } } } return true; } else { return false; } }
@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; }
@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; }