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