Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/encoding/terms/nquads-shard-term.lisp

KindCoveredAll%
expression4881 59.3
branch38 37.5
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; -*-
2
 
3
 (in-package :org.datagraph.spocq.implementation)
4
 
5
 ;;; replace the nquads field encoding operator with one which retrieves terms directly from lmdb.
6
 ;;; delegates to turtle term encoding
7
 
8
 (defmethod write-rdf-nquads :around ((results solution-generator) (stream t))
9
   (rlmdb::with-string-database (sdb)
10
     (call-next-method)))
11
 
12
 (fmakunbound 'write-rdf-field-nquads)
13
 
14
 (defun write-rdf-field-nquads (page variables stream &optional (index 0) (start 0) end)
15
   (assert (= (length (array-dimensions page)) 2) () "invalid result array dimensions: ~a" (array-dimensions page))
16
   (let ((width (array-dimension page 1))
17
         (default-graph-term (when *nquads-default-graph-term* (iri-lexical-form *nquads-default-graph-term*))))
18
     (dotimes (page-index (array-dimension page 0))
19
       (when (>= index start)
20
         (when (and end (>= index end))
21
           (return))
22
         (loop for value-index from 0 below width
23
           do (let ((term-id (aref page page-index value-index)))
24
                ;; (print (list page-index value-index term-id))
25
                (case term-id
26
                  (0
27
                   (if (= value-index 3)
28
                       (when default-graph-term
29
                         (format stream "<~a>" default-graph-term))
30
                       (ecase *ntriples-unbound-term-mode*
31
                         (spocq:unbound-variable
32
                          (format stream "<urn:dydra:unbound~@[:~a~]>" (nth value-index variables)))
33
                         (error
34
                          (error "invalid null ntriples/nquads term.")))))
35
                  ((-1 4294967295)
36
                         ;; suppress the term as the graph designator
37
                         (if (= value-index 3)
38
                             (when default-graph-term
39
                               (format stream "<~a>" default-graph-term))))
40
                  ((-2 4294967294)
41
                   (write-string "<urn:dydra:named>" stream))
42
                  (t
43
                   (encode-turtle-term-number term-id stream)))
44
                (write-char #\space stream)))
45
         (write-char #\. stream)
46
         (nquads-eol stream))
47
       (incf index)))
48
   index)
49
 
50