Search in sources :

Example 16 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method addUser.

/**
     * Endpoint-style user creation takes a little bunch of Turtle e.g. [] a
     * foaf:Agent ; cz:userName "Hugo Ball" .
     *
     * [has test]
     *
     * @TODO check for password
     *
     * @param userData
     * @return HTTP/1.1 204 No Content
     */
@POST
@Consumes(SupportedFormat.TURTLE)
@Path("add-user")
public Response addUser(@Context UriInfo uriInfo, ImmutableGraph inputGraph) {
    Iterator<Triple> agents = inputGraph.filter(null, null, FOAF.Agent);
    BlankNodeOrIRI userNode = agents.next().getSubject();
    Iterator<Triple> userTriples = inputGraph.filter(userNode, null, null);
    String userName = "";
    Triple userTriple = null;
    Lock writeLock = systemGraph.getLock().writeLock();
    writeLock.lock();
    try {
        GraphNode systemUserNode = new GraphNode(userNode, systemGraph);
        addRole(systemUserNode, "BasePermissionsRole");
        while (userTriples.hasNext()) {
            userTriple = userTriples.next();
            systemGraph.add(userTriple);
        }
        userName = ((Literal) userTriple.getObject()).getLexicalForm();
    } finally {
        writeLock.unlock();
    }
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
    return Response.created(createdResource).build();
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Lock(java.util.concurrent.locks.Lock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 17 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method createUser.

/**
     * Creates a new user withe the specified user name
     *
     * @param newUserName
     * @return user node in system graph
     */
private GraphNode createUser(String newUserName) {
    BlankNode subject = new BlankNode();
    GraphNode userNode = new GraphNode(subject, systemGraph);
    userNode.addProperty(RDF.type, FOAF.Agent);
    userNode.addProperty(PLATFORM.userName, new PlainLiteralImpl(newUserName));
    addRole(userNode, "BasePermissionsRole");
    return userNode;
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 18 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class RdfSerializingWriter method getExpandedContext.

private Graph getExpandedContext(GraphNode node, GraphNode recipe) {
    final Graph result = new SimpleGraph(node.getNodeContext());
    final Set<RDFTerm> expandedResources = new HashSet<RDFTerm>();
    expandedResources.add(node.getNode());
    while (true) {
        Set<RDFTerm> additionalExpansionRes = getAdditionalExpansionResources(result, recipe);
        additionalExpansionRes.removeAll(expandedResources);
        if (additionalExpansionRes.size() == 0) {
            return result;
        }
        for (RDFTerm resource : additionalExpansionRes) {
            final GraphNode additionalNode = new GraphNode(resource, node.getGraph());
            result.addAll(additionalNode.getNodeContext());
            expandedResources.add(resource);
        }
    }
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) HashSet(java.util.HashSet)

Example 19 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class RdfSerializingWriter method getSubjectExpansionProperties.

private Set<IRI> getSubjectExpansionProperties(GraphNode recipe) {
    final MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(true);
    final List<String> paramValues = queryParams.get(SUBJ_EXP_PARAM);
    final Set<IRI> result = new HashSet<IRI>();
    if (paramValues != null) {
        for (String uriString : paramValues) {
            result.add(new IRI(uriString));
        }
    }
    if (recipe != null) {
        Iterator<GraphNode> ingredients = recipe.getObjectNodes(RECIPES.ingredient);
        while (ingredients.hasNext()) {
            Iterator<RDFTerm> properties = ingredients.next().getObjects(RECIPES.ingredientInverseProperty);
            while (properties.hasNext()) {
                result.add((IRI) properties.next());
            }
        }
    }
    return result;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 20 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class TopicClassificationEngine method importConceptsFromGraph.

@Override
public int importConceptsFromGraph(ImmutableGraph graph, IRI conceptClass, IRI broaderProperty) throws ClassifierException {
    int importedCount = 0;
    Iterator<Triple> conceptIterator = graph.filter(null, org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDF_TYPE, conceptClass);
    while (conceptIterator.hasNext()) {
        Triple conceptTriple = conceptIterator.next();
        if (!(conceptTriple.getSubject() instanceof IRI)) {
            continue;
        }
        IRI conceptUri = (IRI) conceptTriple.getSubject();
        GraphNode node = new GraphNode(conceptUri, graph);
        List<String> broaderConcepts = new ArrayList<String>();
        // TODO: use OWL property inference on sub-properties here instead of explicit
        // property filter
        Iterator<GraphNode> broaderIterator = node.getObjectNodes(broaderProperty);
        while (broaderIterator.hasNext()) {
            RDFTerm node2 = broaderIterator.next().getNode();
            if (node2 instanceof IRI) {
                broaderConcepts.add(((IRI) node2).getUnicodeString());
            }
        }
        addConcept(conceptUri.getUnicodeString(), broaderConcepts);
        importedCount++;
    }
    return importedCount;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) ArrayList(java.util.ArrayList) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Aggregations

GraphNode (org.apache.clerezza.rdf.utils.GraphNode)20 Triple (org.apache.clerezza.commons.rdf.Triple)8 IRI (org.apache.clerezza.commons.rdf.IRI)6 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)6 HashSet (java.util.HashSet)5 Lock (java.util.concurrent.locks.Lock)5 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)5 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)5 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)4 Graph (org.apache.clerezza.commons.rdf.Graph)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)3 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)3 Literal (org.apache.clerezza.commons.rdf.Literal)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1