Skip to content

Commit

Permalink
allow use of id-maps in :values pattern
Browse files Browse the repository at this point in the history
The json-ld standard does not actually support iri expansion in a value map. Also, iris
are denoted with id maps in every other bit of FQL syntax. This commit allows both
json-ld-compliant iri declaration and makes our syntax more consistent.
  • Loading branch information
dpetran committed Jun 19, 2024
1 parent 8a1f678 commit c1602d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/clj/fluree/db/query/fql/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@
(defn match-value-binding-map
[var-match binding-map context]
(let [attrs (expand-keys binding-map context)
id (get attrs const/iri-id)
val (get attrs const/iri-value)]
(if-let [dt-iri (get-expanded-datatype attrs context)]
(if (= const/iri-anyURI dt-iri)
(let [expanded (json-ld/expand-iri val context)]
(where/match-iri var-match expanded))
(where/match-value var-match val dt-iri))
(if-let [lang (get attrs const/iri-language)]
(where/match-value var-match val const/iri-lang-string {:lang lang})
(let [dt (datatype/infer-iri val)]
(where/match-value var-match val dt))))))
(cond id (let [expanded (json-ld/expand-iri id context)]
(where/match-iri var-match expanded))
:else
(if-let [dt-iri (get-expanded-datatype attrs context)]
(if (= const/iri-anyURI dt-iri)
(let [expanded (json-ld/expand-iri val context)]
(where/match-iri var-match expanded))
(where/match-value var-match val dt-iri))
(if-let [lang (get attrs const/iri-language)]
(where/match-value var-match val const/iri-lang-string {:lang lang})
(let [dt (datatype/infer-iri val)]
(where/match-value var-match val dt)))))))

(defn match-value-binding
[var-match value context]
Expand Down
15 changes: 13 additions & 2 deletions test/fluree/db/query/values_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
(is (= [["foo1"] ["foo2"] ["foo3"]]
@(fluree/query db1 {"select" ["?foo"]
"values" ["?foo" ["foo1" "foo2" "foo3" ]]}))
"syntactic form is parsed correctly"))))
"syntactic form is parsed correctly")))
(testing "iri values"
(is (= [["Brian" "brian@example.org"]
["Cam" "cam@example.org"]]
@(fluree/query db1 {"@context" context
"select" ["?name" "?email"]
"where" [{"@id" "?s" "schema:name" "?name"}
{"@id" "?s" "schema:email" "?email"}
["values"
["?s" [{"@id" "ex:cam"}
{"@id" "ex:brian"}]]]]}))
"id-maps can be used to distinguish iris")))
(testing "where pattern"
(testing "single var"
(is (= [["Brian" "brian@example.org"]
Expand All @@ -56,7 +67,7 @@
{"@id" "?s" "schema:email" "?email"}
["values"
[["?s"] [[{"@type" "xsd:anyURI" "@value" "ex:cam"}]
[{"@type" "xsd:anyURI" "@value" "ex:brian"}]]]]]}))
[{"@id" "ex:brian"}]]]]]}))
"syntactic form is parsed correctly"))
(testing "nested under optional clause"
(is (= [["Nikola" nil true]]
Expand Down

0 comments on commit c1602d5

Please sign in to comment.