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();
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations