fluree / db

Fluree database library
https://fluree.github.io/db/
Other
336 stars 21 forks source link

SPARQL - support inverse/reverse path `^` #508

Open bplatz opened 1 year ago

bplatz commented 1 year ago

SPARQL allows inverse path to be noted with a ^prefix, which means the following statement in a WHERE clause:

{ <mailto:alice@example> ^foaf:mbox ?x }

is equivalent to:

{ ?x foaf:mbox <mailto:alice@example> }

We should look for this prefix on properties in WHERE, and translate it to FlureeQL by flipping the statement. The following is a test that should work:

  (testing "multi-clause, semicolon separator"
    (let [query "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\nPREFIX ex: <http://example.org/ns/>\nSELECT ?x\nWHERE {\n ?x ^foaf:knows <ex:jdoe>.\n}"
          {:keys [where]} (sparql-to-ad-hoc query)]
      (is (= [["$fdb" "ex:jdoe" "foaf:knows" "?x"]]
             where))))
alan-icebreaker commented 4 months ago

Hi Fluree team!

I'd like to also request support for SPARQL property paths, in addition to the inverse/reverse path.

W3C -- https://www.w3.org/TR/sparql11-query/#propertypaths

Our use case is to explore social relationships between users via FOAF relations (and others).

Happy to discuss specific requirements further!

Thank you!