This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-15
Channels
- # announcements (13)
- # aws (6)
- # babashka (23)
- # babashka-sci-dev (6)
- # beginners (64)
- # calva (110)
- # cider (25)
- # cljs-dev (5)
- # cljsrn (8)
- # clojars (5)
- # clojure (20)
- # clojure-austin (1)
- # clojure-europe (77)
- # clojure-nl (1)
- # clojure-uk (3)
- # clojurescript (14)
- # cursive (7)
- # datahike (9)
- # datomic (13)
- # eastwood (15)
- # emacs (14)
- # figwheel-main (1)
- # fulcro (8)
- # graalvm-mobile (2)
- # graphql (2)
- # honeysql (2)
- # hyperfiddle (2)
- # introduce-yourself (4)
- # jobs (4)
- # joyride (4)
- # leiningen (4)
- # lsp (8)
- # minecraft (8)
- # off-topic (11)
- # polylith (18)
- # rdf (2)
- # reagent (3)
- # reitit (4)
- # remote-jobs (1)
- # shadow-cljs (39)
- # specter (7)
- # xtdb (3)
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: ""