grafter icon indicating copy to clipboard operation
grafter copied to clipboard

the api and implementation should define clear extension points for data conversion between dataset and repository domains

Open lisp opened this issue 10 years ago • 0 comments

in order to effect a minimal conversion of the data retrieved by a query from a repository, it was necessary to either filter the result dataset to convert all cell values or to intervene in the initial construction process. the latter recommends itself with respect to both scaling and facility. while the implementation implies a facility at the point of solution-to-map conversion

  • it is unclear how to get at that through the query operator
  • it serves only as an indirect means to affect the cell value conversion.

one alternative would be to provide a generic cell conversion function as the default.

(defmulti term-value class)
(defmethod term-value org.openrdf.model.Literal [literal] (literal-datatype->type literal))
(defmethod term-value org.openrdf.model.URI [uri] (.toString uri))
(defmethod term-value org.openrdf.model.BNode [node] (clojure.string/join ["_:" (.getID node)]))

;;; from grafter/repository.clj                                                                                                                       \

(defn query-bindings->map [^org.openrdf.query.BindingSet qbs]
  (let [boundvars (.getBindingNames qbs)]
    (->> boundvars
         (mapcat (fn [k]
                   [(symbol k) (-> qbs (.getBinding k) .getValue term-value)]))
     (apply hash-map))))

(defn query-results-seq [results]
  (if (.hasNext results)
      (let [current-result (try
                    (query-bindings->map (.next results))
                    (catch Exception e
                           (.close results)
                           (throw e)))]
(lazy-cat [current-result] (query-results-seq results)))
      (.close results)))

another would be to provide a means to specify one through the higher level api.

lisp avatar Oct 15 '15 10:10 lisp