use of com.github.jsonldjava.core.JsonLdTripleCallback in project jena by apache.
the class JsonLDReader method read$.
private void read$(Object jsonObject, String baseURI, ContentType ct, final StreamRDF output, Context context) {
output.start();
try {
JsonLdTripleCallback callback = new JsonLdTripleCallback() {
@Override
public Object call(RDFDataset dataset) {
// Copy across namespaces
for (Entry<String, String> namespace : dataset.getNamespaces().entrySet()) {
output.prefix(namespace.getKey(), namespace.getValue());
}
// Copy triples and quads
for (String gn : dataset.keySet()) {
Object x = dataset.get(gn);
if ("@default".equals(gn)) {
@SuppressWarnings("unchecked") List<Map<String, Object>> triples = (List<Map<String, Object>>) x;
for (Map<String, Object> t : triples) {
Node s = createNode(t, "subject");
Node p = createNode(t, "predicate");
Node o = createNode(t, "object");
Triple triple = profile.createTriple(s, p, o, -1, -1);
output.triple(triple);
}
} else {
@SuppressWarnings("unchecked") List<Map<String, Object>> quads = (List<Map<String, Object>>) x;
Node g = createURI(gn);
for (Map<String, Object> q : quads) {
Node s = createNode(q, "subject");
Node p = createNode(q, "predicate");
Node o = createNode(q, "object");
Quad quad = profile.createQuad(g, s, p, o, -1, -1);
output.quad(quad);
}
}
}
return null;
}
};
JsonLdOptions options = new JsonLdOptions(baseURI);
options.useNamespaces = true;
JsonLdProcessor.toRDF(jsonObject, callback, options);
} catch (JsonLdError e) {
errorHandler.error(e.getMessage(), -1, -1);
throw new RiotException(e);
}
output.finish();
}
Aggregations