use of com.github.jsonldjava.core.RDFDataset in project jena by apache.
the class JenaRDF2JSONLD method parse.
@Override
public RDFDataset parse(Object object) throws JsonLdError {
RDFDataset result = new RDFDataset();
if (object instanceof DatasetGraph) {
DatasetGraph dsg = (DatasetGraph) object;
Iterator<Quad> iter = dsg.find();
for (; iter.hasNext(); ) {
Quad q = iter.next();
Node s = q.getSubject();
Node p = q.getPredicate();
Node o = q.getObject();
Node g = q.getGraph();
String gq = null;
if (g != null && !Quad.isDefaultGraph(g)) {
gq = blankNodeOrIRIString(g);
if (gq == null)
throw new RiotException("Graph node is not a URI or a blank node");
}
String sq = blankNodeOrIRIString(s);
if (sq == null)
throw new RiotException("Subject node is not a URI or a blank node");
String pq = p.getURI();
if (o.isLiteral()) {
String lex = o.getLiteralLexicalForm();
String lang = o.getLiteralLanguage();
String dt = o.getLiteralDatatypeURI();
if (lang != null && lang.length() == 0) {
lang = null;
// dt = RDF.getURI()+"langString" ;
}
if (dt == null)
dt = XSDDatatype.XSDstring.getURI();
result.addQuad(sq, pq, lex, dt, lang, gq);
} else {
String oq = blankNodeOrIRIString(o);
result.addQuad(sq, pq, oq, gq);
}
}
} else
Log.warn(JenaRDF2JSONLD.class, "unknown");
return result;
}
Aggregations