Search in sources :

Example 26 with IRI

use of org.apache.clerezza.commons.rdf.IRI 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;
}
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) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException)

Example 27 with IRI

use of org.apache.clerezza.commons.rdf.IRI 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;
}
Also used : SelectQuery(org.apache.clerezza.rdf.core.sparql.query.SelectQuery) IRI(org.apache.clerezza.commons.rdf.IRI) SolutionMapping(org.apache.clerezza.rdf.core.sparql.SolutionMapping) UnionGraph(org.apache.clerezza.rdf.utils.UnionGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Recipe(org.apache.stanbol.rules.base.api.Recipe) RecipeList(org.apache.stanbol.rules.base.api.util.RecipeList) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) ResultSet(org.apache.clerezza.rdf.core.sparql.ResultSet) ParseException(org.apache.clerezza.rdf.core.sparql.ParseException) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException)

Example 28 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ClerezzaRuleStore method findRulesByName.

@Override
public RuleList findRulesByName(String term) {
    String sparql = "SELECT ?recipe ?rule ?description " + "WHERE { " + "?recipe " + Symbols.hasRule + " ?rule . " + "?rule " + Symbols.ruleName + " ?name . " + "?rule " + Symbols.description + " ?description . " + "FILTER (regex(?name, \"" + 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 29 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ClerezzaRuleStore method removeRecipe.

@Override
public boolean removeRecipe(IRI recipeID) throws RecipeEliminationException {
    // remove the recipe from the TcManager
    try {
        tcManager.deleteGraph(recipeID);
    } catch (NoSuchEntityException e) {
        throw new RecipeEliminationException(e);
    }
    Graph recipeIndexGraph = tcManager.getGraph(new IRI(recipeIndexLocation));
    Triple triple = new TripleImpl(recipeID, RDF.type, Symbols.Recipe);
    recipeIndexGraph.remove(triple);
    // System.out.println("Recipes: " +recipes.size());
    // remove the recipe ID from in-memory list
    recipes.remove(recipeID);
    return true;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) RecipeEliminationException(org.apache.stanbol.rules.base.api.RecipeEliminationException) UnionGraph(org.apache.clerezza.rdf.utils.UnionGraph) Graph(org.apache.clerezza.commons.rdf.Graph) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) NoSuchEntityException(org.apache.clerezza.rdf.core.access.NoSuchEntityException)

Example 30 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class UserResource method store.

// **********************************
// ****** ADD PERMISSION TO USER ****
// **********************************
// **************************************
// ****** REMOVE PERMISSION FROM USER ***
// **************************************
// ************************************
// ****** ADD PERMISSION TO ROLE ******
// ************************************
// **************************************
// ****** REMOVE PERMISSION FROM ROLE ***
// **************************************
// //////////////////////////////////////////////////////////////
/**
 * Pushes user data into system graph
 *
 * @param userNode
 * @param uriInfo
 * @param currentUserName
 * @param newUserName
 * @param fullName
 * @param email
 * @param password
 * @param roles
 * @param permissions
 * @return
 */
private Response store(GraphNode userNode, UriInfo uriInfo, String currentUserName, String newUserName, String fullName, String email, String password, List<String> roles, List<String> permissions) {
    if (newUserName != null && !newUserName.equals("")) {
        changeLiteral(userNode, PLATFORM.userName, newUserName);
    }
    if (fullName != null && !fullName.equals("")) {
        changeLiteral(userNode, FOAF.name, fullName);
    }
    if (password != null && !password.equals("")) {
        String passwordSha1 = PasswordUtil.convertPassword(password);
        changeLiteral(userNode, PERMISSION.passwordSha1, passwordSha1);
    }
    if (email != null && !email.equals("")) {
        changeResource(userNode, FOAF.mbox, new IRI("mailto:" + email));
    }
    BlankNodeOrIRI userResource = (BlankNodeOrIRI) userNode.getNode();
    if (roles != null) {
        clearRoles(userResource);
        Lock writeLock = systemGraph.getLock().writeLock();
        writeLock.lock();
        try {
            for (int i = 0; i < roles.size(); i++) {
                roles.set(i, roles.get(i).trim());
                if (!roles.get(i).equals("")) {
                    addRole(userNode, roles.get(i));
                }
            }
        } finally {
            writeLock.unlock();
        }
    }
    if (permissions != null) {
        clearPermissions(userResource);
        Lock writeLock = systemGraph.getLock().writeLock();
        writeLock.lock();
        try {
            for (int i = 0; i < permissions.size(); i++) {
                permissions.set(i, permissions.get(i).trim());
                if (!permissions.get(i).equals("")) {
                    addPermission(userNode, permissions.get(i));
                }
            }
        } finally {
            writeLock.unlock();
        }
    }
    URI pageUri = uriInfo.getBaseUriBuilder().path("system/console/usermanagement").build();
    // header Cache-control: no-cache, just in case intermediaries are
    // holding onto old stuff
    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    // the jax-rs things available
    return Response.seeOther(pageUri).cacheControl(cc).build();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) CacheControl(javax.ws.rs.core.CacheControl) URI(java.net.URI) Lock(java.util.concurrent.locks.Lock)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24