Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/encoding/rdf-json.lisp
| Kind | Covered | All | % |
| expression | 0 | 119 | 0.0 |
| branch | 0 | 4 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.implementation; -*-
3
(in-package :org.datagraph.spocq.implementation)
6
;;; http://www.w3.org/TR/rdf-sparql-XMLres/
8
;;; reading in in json.lsip
10
;;; solution field writing when as json, require just s-p-o
12
(defparameter *encode-json-term.type-literals* t)
14
(defgeneric write-rdf+json (results stream)
15
(:documentation "Encode the result field to the stream as rdf+json (or pplication/json.
16
If results are a list of lists, then the first element is a header, which specifies the variable names and
17
the remaining entries aer solutions sets. if a variable is unbound, the solution element is etf:nil.
18
Otherwise, the results can be a matrix, in which case the dimensionality is explicit.")
20
(:method ((result symbol) (stream t))
21
(log-warn "json result is not a graph: ~s." result)
24
(:method ((results list-solution-field) (stream t))
25
(write-rdf+json (cons (list-solution-field-dimensions results)
26
(list-solution-field-solutions results))
29
(:method ((results cons) (stream t))
30
(let* ((dimensions (first results))
31
(solutions (rest results)))
33
(cond ((equal dimensions *construct-dimensions*)
35
((= (length dimensions) (length *construct-dimensions*))
36
;; (log-warn "json dimensions assumed: dimensions ~s." dimensions)
37
;;(setf dimensions *construct-dimensions*)
40
(log-warn "json result is not a graph: dimensions ~s." dimensions)
41
(return-from write-rdf+json 0)))
43
(let* ((cache (make-hash-table :test #'equalp))
44
(subjects (remove-duplicates (mapcar #'first solutions) :test #'equalp))
45
;(root-subjects (set-difference subjects (remove-duplicates (mapcar #'third solutions) :test #'equalp)))
47
(*encode-json-term.type-literals* nil)) ; suppress type wrapper
48
;; no offset limit handling
49
(loop for (subject predicate object) in solutions
50
for entry = (gethash subject cache)
53
do (push object (getf (rest entry) predicate))
54
else do (setf (gethash subject cache)
55
`(,subject ,predicate (,object))))
56
(labels ((emit-objects (objects)
58
(write-char #\[ stream)
59
(loop for first = t then nil
61
do (progn (unless first (write-string ", " stream))
62
(emit-object object)))
63
(write-char #\] stream))
65
(emit-object (first objects)))))
67
(multiple-value-bind (cache-entry present-p)
68
(gethash object cache)
71
(setf (gethash object cache) nil)
72
(write-char #\{ stream)
73
(write-string "\"ID\": " stream)
74
(encode-json-term object stream)
75
(loop for (property objects) on (rest cache-entry) by #'cddr
76
do (progn (format stream ", \"~a\": "
77
(if (symbolp property)
78
(symbol-name property)
79
(iri-lexical-form property)))
80
(emit-objects objects)))
81
(write-char #\} stream))
83
(encode-json-term object stream)))
84
(encode-json-term object stream)))))
86
;(emit-objects root-subjects)
87
(emit-objects subjects)
89
(incf-stat *statements-returned* count))))
91
(:method ((results boolean-generator) (stream t))
92
(log-warn "attempt to encode a boolean result as json")
95
(:method ((results solution-generator) (stream t))
96
(log-warn "attempt to encode a solution generator as rdf+json")
99
(:method ((result-field true-matrix-field) (stream t))
100
(log-warn "attempt to encode a boolean result as rdf+json")
103
(:method ((result-field false-matrix-field) (stream t))
104
(log-warn "attempt to encode a boolean result as rdf+json")
107
(:method ((result-field matrix-field) (stream t))
108
(log-warn "attempt to encode a matrix field as rdf+json")))
117
(defmethod send-response-message (operation (message-body t) (stream t) (content-type mime:rdf/json))
118
"Given a MESSAGE, and a STREAM with the application/rdf+xml CONTENT-TYPE, encode as an xml rdf document"
119
(when *encoding-trace-output*
120
(setf stream (make-broadcast-stream *encoding-trace-output* stream)))
121
(let ((*package* *spocq-reader-package*))
122
(write-rdf+json message-body stream)))
126
(write-rdf+json *rdf+xml=test=field* *trace-output*)