Fork me on GitHub
#rdf
<
2022-06-15
>
Kelvin13:06:54

So I was playing around with Apache Jena's https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSetFormatter.html class (in order to work with the SPARQL Protocol). Each method accepts either a https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSet.html or a boolean, and since the latter was easier to work with I was using that. And here are the results:

(defmacro ->format-str
  "Macro to work with ResultSetFormatter to return strings."
  [f this]
  `(with-open [~'baos (java.io.ByteArrayOutputStream.)]
     (~f ~'baos ~this)
     (String. (.toByteArray ~'baos))))

(->format-str ResultSetFormatter/outputAsJSON true)

; Result: "{ \n  \"head\" : { } ,\n  \"boolean\" : true\n}\n"

(->format-str ResultSetFormatter/outputAsXML true)

; Result: "<?xml version=\"1.0\"?>\n<sparql xmlns=\"\">\n  <head>\n  </head>\n  <boolean>true</boolean>\n</sparql>\n"

(->format-str ResultSetFormatter/outputAsCSV true)

; Result: ""

Kelvin13:06:31

As you can see, for JSON and XML the formatted results make sense, but for CSV the result becomes an empty string. This seems "wrong," and I haven't been able to find much documentation on what the result for ASK queries (which return booleans) should be