Skip to content

Commit 4761f41

Browse files
authored
Merge pull request threatgrid#63 from quoll/nil-trailers-61
Removed naga/nil from graph data
2 parents 3edf993 + 3d50574 commit 4761f41

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/naga/data.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
[k (into {} (map #(apply vector (rest %)) vs))]))
2323
(into {}))
2424
node-list (loop [nl [] n node]
25-
(if (= :naga/nil n)
25+
(if-not n
2626
nl
2727
(let [{f :naga/first r :naga/rest} (listmap n)]
2828
(recur (conj nl f) r))))]
@@ -44,11 +44,10 @@
4444
(let [id (store/new-node *current-storage*)
4545
[value-id triples] (value-triples v)
4646
[next-id next-triples] (list-triples vs)]
47-
[id (concat [[id (store/data-property *current-storage* value-id) value-id]
48-
[id :naga/rest next-id]]
47+
[id (concat [[id (store/data-property *current-storage* value-id) value-id]]
48+
(when next-id [[id :naga/rest next-id]])
4949
triples
50-
next-triples)])
51-
[:naga/nil nil]))
50+
next-triples)])))
5251

5352
(defmethod value-triples List
5453
[vlist]
@@ -59,7 +58,7 @@
5958

6059
(defmethod value-triples Map [v] (map->triples v))
6160

62-
(defmethod value-triples nil [v] [:naga/nil nil])
61+
(defmethod value-triples nil [v] nil)
6362

6463
(defmethod value-triples :default [v] [v nil])
6564

@@ -69,7 +68,7 @@
6968
and builds triples around it"
7069
[entity-id :- s/Any
7170
[property value] :- [s/Keyword s/Any]]
72-
(let [[value-id value-data] (value-triples value)]
71+
(if-let [[value-id value-data] (value-triples value)]
7372
(cons [entity-id property value-id] value-data)))
7473

7574

@@ -128,8 +127,7 @@
128127
"Return all the property/value pairs for a given entity in the store."
129128
[store :- Storage
130129
entity :- s/Any]
131-
(if-not (= entity :naga/nil)
132-
(store/resolve-pattern store [entity '?p '?o])))
130+
(store/resolve-pattern store [entity '?p '?o]))
133131

134132

135133
(s/defn check-structure :- (s/maybe [[s/Keyword s/Any]])
@@ -161,8 +159,9 @@
161159
;; convert the data to a map
162160
(let [st (into {} pairs)]
163161
;; if the properties indicate a list, then process it
164-
(if-let [remaining (:naga/rest st)]
165-
(let [first-prop-elt (get-data st)
162+
(when (:naga/first st)
163+
(let [remaining (:naga/rest st)
164+
first-prop-elt (get-data st)
166165
[_ first-elt] (recurse-node store first-prop-elt)]
167166
(assert first-elt)
168167
;; recursively build the list

test/naga/test_data.clj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
[:test/n2 :naga/first 42]
3636
[:test/n2 :naga/rest :test/n3]
3737
[:test/n3 :naga/first 54]
38-
[:test/n3 :naga/rest :naga/nil]
3938
[:test/n2 :naga/contains 42]
4039
[:test/n2 :naga/contains 54]] m3))
4140
(is (= [[:test/n1 :db/ident :test/n1]
@@ -52,9 +51,7 @@
5251
[:test/n4 :naga/rest :test/n6]
5352
[:test/n5 :a 2]
5453
[:test/n6 :naga/first :test/n7]
55-
[:test/n6 :naga/rest :naga/nil]
5654
[:test/n7 :naga/first "nested"]
57-
[:test/n7 :naga/rest :naga/nil]
5855
[:test/n7 :naga/contains "nested"]
5956
[:test/n2 :naga/contains :test/n3]
6057
[:test/n2 :naga/contains :test/n5]
@@ -83,7 +80,6 @@
8380
[:test/n2 :naga/first 42]
8481
[:test/n2 :naga/rest :test/n3]
8582
[:test/n3 :naga/first 54]
86-
[:test/n3 :naga/rest :naga/nil]
8783
[:test/n2 :naga/contains 42]
8884
[:test/n2 :naga/contains 54]] m3))
8985
(is (= [[:test/n1 :db/ident :test/n1]
@@ -100,9 +96,7 @@
10096
[:test/n4 :naga/rest :test/n6]
10197
[:test/n5 :a 2]
10298
[:test/n6 :naga/first :test/n7]
103-
[:test/n6 :naga/rest :naga/nil]
10499
[:test/n7 :naga/first "nested"]
105-
[:test/n7 :naga/rest :naga/nil]
106100
[:test/n7 :naga/contains "nested"]
107101
[:test/n2 :naga/contains :test/n3]
108102
[:test/n2 :naga/contains :test/n5]

0 commit comments

Comments
 (0)