public String toString() { return uri.toString(); };
public String toString() { return uri.toString(); };
@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()); }
@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()); }
private void appendDataSet(StringBuffer s, SimpleQuery q) { DataSet dataSet = q.getDataSet(); if (dataSet != null) { for (IRI dg : dataSet.getDefaultGraphs()) { s.append("FROM ").append(dg.toString()).append("\n"); } for (IRI ng : dataSet.getNamedGraphs()) { s.append("FROM NAMED ").append(ng.toString()).append("\n"); } } }
private void appendDataSet(StringBuffer s, SimpleQuery q) { DataSet dataSet = q.getDataSet(); if (dataSet != null) { for (IRI dg : dataSet.getDefaultGraphs()) { s.append("FROM ").append(dg.toString()).append("\n"); } for (IRI ng : dataSet.getNamedGraphs()) { s.append("FROM NAMED ").append(ng.toString()).append("\n"); } } }
/** * * @param recipeIRI * the IRI of the recipe * @param stanbolRule * the rule in Rule syntax */ @Override public Recipe addRulesToRecipe(Recipe recipe, String stanbolRule, String description) { IRI recipeID = recipe.getRecipeID(); String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; RuleList ruleList = RuleParserImpl.parse(namespace, stanbolRule).getRuleList(); for (Rule rule : ruleList) { recipe = addRuleToRecipe(recipe, rule, description); } return recipe; }
/** * * @param recipeIRI * the IRI of the recipe * @param stanbolRule * the rule in Rule syntax */ @Override public Recipe addRulesToRecipe(Recipe recipe, String stanbolRule, String description) { IRI recipeID = recipe.getRecipeID(); String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; RuleList ruleList = RuleParserImpl.parse(namespace, stanbolRule).getRuleList(); for (Rule rule : ruleList) { recipe = addRuleToRecipe(recipe, rule, description); } return recipe; }
/** * * Parse the set of rules provided by the rulesStream parameter as Stanbol syntax rules and add them to * the Recipe in the store.<br/> * The recipe is a {@link Graph} managed by the {@link TcManager}. * * * @param recipe * {@link Recipe} the recipe * @param rulesStream * {@link InputStream} the rule in Stanbol syntax * * @return the recipe with the new rule. */ @Override public Recipe addRulesToRecipe(Recipe recipe, InputStream rulesStream, String description) { log.debug("Adding rule to recipe " + recipe); IRI recipeID = recipe.getRecipeID(); String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; log.info("Rule Namespace is " + namespace); RuleList ruleList = RuleParserImpl.parse(namespace, rulesStream).getRuleList(); for (Rule rule : ruleList) { recipe = addRuleToRecipe(recipe, rule, description); } return recipe; }
@Override public boolean equals(Object obj) { if (obj instanceof Recipe) { Recipe recipe = (Recipe) obj; if (recipe.getRecipeID().toString().equals(this.getRecipeID().toString())) { if (recipe.getRecipeDescription().equals(this.getRecipeDescription())) { if (recipe.toString().equals(this.toString())) { return true; } else { return false; } } else { return false; } } else { return false; } } return false; } }
/** * * Parse the set of rules provided by the rulesStream parameter as Stanbol syntax rules and add them to * the Recipe in the store.<br/> * The recipe is a {@link Graph} managed by the {@link TcManager}. * * * @param recipe * {@link Recipe} the recipe * @param rulesStream * {@link InputStream} the rule in Stanbol syntax * * @return the recipe with the new rule. */ @Override public Recipe addRulesToRecipe(Recipe recipe, InputStream rulesStream, String description) { log.debug("Adding rule to recipe " + recipe); IRI recipeID = recipe.getRecipeID(); String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; log.info("Rule Namespace is " + namespace); RuleList ruleList = RuleParserImpl.parse(namespace, rulesStream).getRuleList(); for (Rule rule : ruleList) { recipe = addRuleToRecipe(recipe, rule, description); } return recipe; }
@Override public boolean equals(Object obj) { if (obj instanceof Recipe) { Recipe recipe = (Recipe) obj; if (recipe.getRecipeID().toString().equals(this.getRecipeID().toString())) { if (recipe.getRecipeDescription().equals(this.getRecipeDescription())) { if (recipe.toString().equals(this.toString())) { return true; } else { return false; } } else { return false; } } else { return false; } } return false; } }
recipeGraph = tcManager.getGraph(recipeID); } catch (NoSuchEntityException e) { throw new NoSuchRecipeException(recipeID.toString()); String query = "SELECT ?rule ?ruleName ?ruleBody ?ruleHead " + "WHERE { " + " " + recipeID.toString() + " " + Symbols.hasRule.toString() + " ?rule . " + " ?rule " + Symbols.ruleName.toString() + " ?ruleName . " + " ?rule " + Symbols.ruleBody.toString() + " ?ruleBody . " + " ?rule " + Symbols.ruleHead.toString() + " ?ruleHead . " + "}"; String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; ruleList = RuleParserImpl.parse(namespace, stanbolSyntax).getRuleList();
recipeGraph = tcManager.getGraph(recipeID); } catch (NoSuchEntityException e) { throw new NoSuchRecipeException(recipeID.toString()); String query = "SELECT ?rule ?ruleName ?ruleBody ?ruleHead " + "WHERE { " + " " + recipeID.toString() + " " + Symbols.hasRule.toString() + " ?rule . " + " ?rule " + Symbols.ruleName.toString() + " ?ruleName . " + " ?rule " + Symbols.ruleBody.toString() + " ?ruleBody . " + " ?rule " + Symbols.ruleHead.toString() + " ?ruleHead . " + "}"; String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/"; ruleList = RuleParserImpl.parse(namespace, stanbolSyntax).getRuleList();
os.write((t.getPredicate().toString() + " ").getBytes());
jsonObject.put("recipe", rcp.getRecipeID().toString()); jsonObject.put("adaptedTo", format); jsonObject.put("result", adaptedRecipe.toString());
private void appendExpression(StringBuffer s, Expression e) { if (e instanceof Variable) { appendVariable(s, (Variable) e); } else if (e instanceof BinaryOperation) { BinaryOperation bo = (BinaryOperation) e; s.append("("); appendExpression(s, bo.getLhsOperand()); s.append(") ").append(bo.getOperatorString()).append(" ("); appendExpression(s, bo.getRhsOperand()); s.append(")"); } else if (e instanceof UnaryOperation) { UnaryOperation uo = (UnaryOperation) e; s.append(uo.getOperatorString()).append(" ("); appendExpression(s, uo.getOperand()); s.append(")"); } else if (e instanceof BuiltInCall) { BuiltInCall b = (BuiltInCall) e; appendCall(s, b.getName(), b.getArguements()); } else if (e instanceof FunctionCall) { FunctionCall f = (FunctionCall) e; appendCall(s, f.getName().getUnicodeString(), f.getArguements()); } else if (e instanceof LiteralExpression) { appendLiteralExpression(s, (LiteralExpression) e); } else if (e instanceof UriRefExpression) { s.append(((UriRefExpression) e).getUriRef().toString()); } }
@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; }
private void appendExpression(StringBuffer s, Expression e) { if (e instanceof Variable) { appendVariable(s, (Variable) e); } else if (e instanceof BinaryOperation) { BinaryOperation bo = (BinaryOperation) e; s.append("("); appendExpression(s, bo.getLhsOperand()); s.append(") ").append(bo.getOperatorString()).append(" ("); appendExpression(s, bo.getRhsOperand()); s.append(")"); } else if (e instanceof UnaryOperation) { UnaryOperation uo = (UnaryOperation) e; s.append(uo.getOperatorString()).append(" ("); appendExpression(s, uo.getOperand()); s.append(")"); } else if (e instanceof BuiltInCall) { BuiltInCall b = (BuiltInCall) e; appendCall(s, b.getName(), b.getArguements()); } else if (e instanceof FunctionCall) { FunctionCall f = (FunctionCall) e; appendCall(s, f.getName().getUnicodeString(), f.getArguements()); } else if (e instanceof LiteralExpression) { appendLiteralExpression(s, (LiteralExpression) e); } else if (e instanceof UriRefExpression) { s.append(((UriRefExpression) e).getUriRef().toString()); } }