rvesse commented on code in PR #3502:
URL: https://github.com/apache/jena/pull/3502#discussion_r2413324113


##########
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();

Review Comment:
   Probably ought to wrap this into a Jena specific error?



##########
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:
   Maybe something a little clearer for the end user:
   
   ```suggestion
                   throw new JenaTitaniumException("Triple terms not supported 
in JSON-LD");
   ```
   
   I don't follow JSON-LD specs so don't know if they plan to support it in 
future iterations of the spec in which case the wording might want to be "not 
currently supported"



-- 
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]

Reply via email to