afs commented on code in PR #3502:
URL: https://github.com/apache/jena/pull/3502#discussion_r2413478393
##########
jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLD11Writer.java:
##########
@@ -116,29 +116,85 @@ public Lang getLang() {
FmtLog.warn(this.getClass(), "Output is not a JSON object
(%s)", writeThis.getClass().getSimpleName());
}
- JsonWriter jsonWriter = startWrite(output, writer, indented);
- jsonWriter.write(writeThis);
- finishWrite(output, writer, indented);
+ writeJson(writeThis, output, writer, indented);
} catch (Throwable ex) {
throw new JenaException("Exception while writing JSON-LD 1.1", ex);
}
}
+ /** Jena DatasetGraph to JSON(LD), Titanium QuadsToJsonld in version
1.7.0. */
+ private static JsonArray datasetToJSON(DatasetGraph dsg) throws
JsonLdError {
+ QuadsToJsonld consumer = JsonLd.fromRdf();
+ consumer.mode(JsonLdVersion.V1_1);
+ dsg.stream().forEach( quad->{
+ String s = resource(quad.getSubject());
+ String p = resource(quad.getPredicate());
+ String g = resourceGraphName(quad.getGraph());
+ Node obj = quad.getObject();
+
+ if ( obj.isURI() || obj.isBlank() ) {
+ String o = resource(obj);
+ try {
+ consumer.quad(s, p, o, null, null, null, g);
+ } catch (RdfConsumerException e) {
+ e.printStackTrace();
+ }
+ } else if ( obj.isLiteral() ) {
+ String lex = obj.getLiteralLexicalForm();
+ String datatype = obj.getLiteralDatatypeURI();
+ String lang = obj.getLiteralLanguage();
+ if ( lang.isEmpty() )
+ lang = null;
+ String dir = null;
+ if ( obj.getLiteralBaseDirection() != null )
+ dir = obj.getLiteralBaseDirection().toString();
+ try {
+ consumer.quad(s, p, lex, datatype, lang, dir, g);
+ } catch (RdfConsumerException e) {
+ e.printStackTrace();
+ }
+ } else if ( obj.isTripleTerm() ) {
+ throw new JenaTitaniumException("Encountered a triple term");
Review Comment:
They (JSON-LD WG) do have a design for triple terms. Titanium JSON-LD does
not support them, only incompatible "RDF*", which is not RDF 1.2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]