Search in sources :

Example 1 with GraphNode

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

the class RdfSerializingWriter method getRecipe.

private GraphNode getRecipe(String templatePath) {
    Graph rg = recipesGraphProvider.getRecipesGraph();
    GraphNode literalNode = new GraphNode(new PlainLiteralImpl(templatePath), rg);
    Iterator<GraphNode> recipes = literalNode.getSubjectNodes(RECIPES.recipeDomain);
    if (recipes.hasNext()) {
        return recipes.next();
    } else {
        return null;
    }
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 2 with GraphNode

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

the class RdfSerializingWriter method writeTo.

@Override
public void writeTo(RdfViewable v, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    GraphNode node = v.getGraphNode();
    GraphNode recipe = getRecipe(v.getRenderingSpecification());
    serializer.serialize(entityStream, getExpandedContext(node, recipe), mediaType.toString());
}
Also used : GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 3 with GraphNode

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

the class RdfSerializingWriter method getObjectExpansionProperties.

private Set<IRI> getObjectExpansionProperties(GraphNode recipe) {
    final MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(true);
    final List<String> paramValues = queryParams.get(OBJ_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.ingredientProperty);
            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 4 with GraphNode

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

the class XmpExtractorEngine method computeEnhancements.

@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
    InputStream in = ci.getBlob().getStream();
    XMPPacketScanner scanner = new XMPPacketScanner();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        scanner.parse(in, baos);
    } catch (IOException e) {
        throw new EngineException(e);
    }
    byte[] bytes = baos.toByteArray();
    if (bytes.length > 0) {
        Graph model = new IndexedGraph();
        parser.parse(model, new ByteArrayInputStream(bytes), "application/rdf+xml");
        GraphNode gn = new GraphNode(new IRI("http://relative-uri.fake/"), model);
        gn.replaceWith(ci.getUri());
        ci.getLock().writeLock().lock();
        try {
            LOG.info("Model: {}", model);
            ci.getMetadata().addAll(model);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) XMPPacketScanner(org.apache.tika.parser.image.xmp.XMPPacketScanner) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 5 with GraphNode

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

the class TestStorage method storageOnScopeCreation.

@Test
public void storageOnScopeCreation() throws Exception {
    assertEquals(1, ontologyProvider.getStore().listGraphs().size());
    // This one has an import that we want to hijack locally, so we use the ParentPathInputSource.
    OntologyInputSource<?> ois = new ParentPathInputSource(new File(getClass().getResource("/ontologies/minorcharacters.owl").toURI()));
    Scope sc = onManager.createOntologyScope(scopeId, ois);
    Set<Triple> triples = new HashSet<Triple>();
    for (IRI iri : ontologyProvider.getStore().listGraphs()) {
        log.info("{}", iri.toString());
        IRI entity = new IRI(Constants.PEANUTS_MINOR_BASE + "#" + Constants.truffles);
        ImmutableGraph ctx = new GraphNode(entity, ontologyProvider.getStore().getGraph(iri)).getNodeContext();
        Iterator<Triple> it = ctx.iterator();
        while (it.hasNext()) triples.add(it.next());
    }
    assertFalse(ontologyProvider.getStore().listGraphs().isEmpty());
    assertEquals(3, triples.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) File(java.io.File) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

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