Skip to content
Browse files

Fixes #155 make-triples function to use rdf/make-blank-node

  • Loading branch information
benswirrl authored and RickMoynihan committed Nov 12, 2019
1 parent a48be5f commit 6302e19775976b15ed3e024d1905b25fa3dfac1c
Showing with 30 additions and 2 deletions.
  1. +1 −1 src/grafter_2/rdf4j/templater.clj
  2. +2 −1 test/grafter_2/rdf4j/io_test.clj
  3. +27 −0 test/grafter_2/rdf4j/templater_test.clj
@@ -39,7 +39,7 @@

(defn- make-triples [subject predicate object-or-nested-subject]
(if (blank-node? object-or-nested-subject)
(let [bnode-resource (keyword (gensym "bnode"))
(let [bnode-resource (rdf/make-blank-node)
nested-pairs object-or-nested-subject]

(-> (mapcat (partial make-triples bnode-resource)
@@ -228,6 +228,7 @@
(is (= (statements bais :format :brf)

(deftest quad->backend-quad-test
(testing "IStatement->sesame-statement"
(is (= (sut/quad->backend-quad (->Quad (url/->java-uri "") (url/->java-uri "") "a string" (url/->java-uri "")))
@@ -259,7 +260,7 @@
["ayanami"] (url/path-segments grafter-url)))))

(deftest blank-nodes-load-test
(testing "Blank nodes are keywords"
(testing "Blank nodes are blank node objects"
(let [[[s1 p1 o1] [s2 p2 o2]] (statements (io/resource "grafter/rdf/bnodes.nt"))]
(is (pr/blank-node? o1))
(is (pr/blank-node? s2)))))
@@ -0,0 +1,27 @@
(ns grafter-2.rdf4j.templater-test
(:require [grafter-2.rdf4j.templater :as sut]
[clojure.test :as t]
[grafter-2.rdf.protocols :as pr]
[grafter.url :as url]))

;; TODO add more tests

(def hasBnode (url/->java-uri ""))
(def p (url/->java-uri ""))
(def o (url/->java-uri ""))

(t/deftest triplify-with-bnode
(let [triples (sut/triplify [(url/->java-uri "")
[hasBnode [[p o]]]])]

(t/is (= 2 (count triples)))

(let [main-res (first triples)
bnode-res (second triples)]
(t/is (= hasBnode (:p main-res)))

(t/testing "BNode object of main-res is subject of bnode triple"
(t/is (pr/blank-node? (:o main-res)))
(t/is (pr/blank-node? (:s bnode-res)))
(t/is (= p (:p bnode-res)))
(t/is (= o (:o bnode-res)))))))

0 comments on commit 6302e19

Please sign in to comment.
You can’t perform that action at this time.