Although retrieving through the stream works extremely well, it consistently fails at about the same place each time (in this case, at 90ish of 150K triples). Drakma, on the other hand, doesn't have the issue. Is there something wrong with how I've configured the request? (see commented out section below)
(defun sparql-stream->db (query &key db)
"The query must return ?s ?p ?o triples for the streaming json parse"
;(handler-case
(let ((db (if db db
(make-solid-db (make-temp-graph-namespace))))
)
|
;;can only get about 90 triples until failure with dex
(multiple-value-bind (result http-status response-hash uri stream)
(dex:post (string+ (get-server) "/blazegraph/sparql")
:content (list `("query".,query))
:headers (list `("accept". ,(getf (config :sparql-output) :json)))
:want-stream t
:keep-alive t
:use-connection-pool t
)
(print (list result http-status (alexandria:hash-table-alist response-hash) uri stream))
|#
(multiple-value-bind (stream status-code headers uri http-stream must-close status-text)
(drakma:http-request
(string+ (get-server) "/blazegraph/sparql")
:method :post
;:content-type "text/plain"
:accept (getf (config :sparql-output) :json)
:want-stream t
:parameters (list `("query".,query)))
(print (list stream status-code headers uri http-stream must-close status-text))
(with-open-stream (stm stream)
(with-open-stream (s (flexi-streams:make-flexi-stream stm :external-format :utf-8))
;(read-line s)
(json-streams:with-open-json-stream (js (json-streams:make-json-input-stream s))
(loop for item = (json-streams:json-read js)
until (or (eql item :eof)
(string= item "bindings")))
(json-streams:json-read js);;advancing to triples section
(loop for j-triple = (json-streams::parse-single js)
until (or (eql j-triple :end-array)
(eql j-triple :eof))
do (json-stream-triple->db db j-triple)
)))))
db))
Although retrieving through the stream works extremely well, it consistently fails at about the same place each time (in this case, at 90ish of 150K triples). Drakma, on the other hand, doesn't have the issue. Is there something wrong with how I've configured the request? (see commented out section below)
(defun sparql-stream->db (query &key db) "The query must return ?s ?p ?o triples for the streaming json parse" ;(handler-case (let ((db (if db db (make-solid-db (make-temp-graph-namespace)))) )
|