Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARQL PREFIX does not translated into @context #507

Closed
bplatz opened this issue Jun 15, 2023 · 2 comments · Fixed by #587
Closed

SPARQL PREFIX does not translated into @context #507

bplatz opened this issue Jun 15, 2023 · 2 comments · Fixed by #587
Assignees
Labels
bug Something isn't working as expected
Milestone

Comments

@bplatz
Copy link
Contributor

bplatz commented Jun 15, 2023

The current test for PREFIX treats it as a source, but instead it is the equivalent to @context.

The current test that is passing, but incorrect is:

  (testing "external"
    (let [query "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\nSELECT ?name ?mbox\n WHERE {\n ?x foaf:name ?name.\n?x foaf:mbox ?mbox\n}"
          {:keys [prefixes where]} (sparql-to-ad-hoc query)]
      (is (= {:foaf "http://xmlns.com/foaf/0.1/"}
             prefixes))
      (is (= ["foaf" "foaf"]
             (mapv first where))))))

It should instead be this, and pass (note the where test is also incorrect, signifying special where logic when a PREFIX exists, but it should parse like a normal `where clause instead):

  (testing "prefix"
    (let [query "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\nSELECT ?name ?mbox\n WHERE {\n ?x foaf:name ?name.\n?x foaf:mbox ?mbox\n}"
          {:keys [context where]} (sparql-to-ad-hoc query)]
      (is (= {"foaf" "http://xmlns.com/foaf/0.1/"}
             context))
      (is (= [["$fdb" "?x" "foaf:name" ?name]
              ["$fdb" "?x" "foaf:mbox" "?mbox"]]
             where)))))

Also, there is no test that uses multiple PREFIX declarations. Hopefully that just works, or may warrant a separate ticket if not. Here is a test:

  (testing "multiple prefixes"
    (let [query "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n PREFIX ex: <http://example.org/ns/>\nSELECT ?name ?mbox\n WHERE {\n ?x foaf:name ?name.\n?x foaf:mbox ?mbox\n}"
          {:keys [context]} (sparql-to-ad-hoc query)]
      (is (= {"foaf" "http://xmlns.com/foaf/0.1/"
              "ex"   "http://example.org/ns/"}
             context)))))
@bplatz bplatz added this to the 3.0.0-beta2 milestone Jun 15, 2023
@bplatz bplatz added the bug Something isn't working as expected label Jun 15, 2023
@cap10morgan cap10morgan self-assigned this Oct 3, 2023
@cap10morgan
Copy link
Contributor

cap10morgan commented Oct 3, 2023

I worked on this as part of the recent v3 SPARQL work before I noticed this ticket existed. The new, passing SPARQL PREFIX test looks like this:

(testing "PREFIX declarations go into the context"
  (let [book-db @(fluree/stage db book-data)
        query   "PREFIX book: <http://example.org/book/>
                 SELECT ?book ?title
                 WHERE {?book book:title ?title.}"
        results @(fluree/query book-db query {:format :sparql})]
    (is (= [["book:1" "For Whom the Bell Tolls"]
            ["book:2" "The Hitchhiker's Guide to the Galaxy"]]
           results))))

@cap10morgan
Copy link
Contributor

I'll add some other tests along the lines of what is suggested in here and make sure those pass as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants