rdflib.js icon indicating copy to clipboard operation
rdflib.js copied to clipboard

🐛 SPARQL query demands period which spec says is optional

Open sroze opened this issue 3 years ago • 6 comments

I'm trying to use a SPARQL query to fetch from my store and it doesn't return any results. Here's a very simple reproducer.

Reproducer

const $rdf = require('rdflib');
const store  = $rdf.graph();
store.add(
  store.sym('https://example.com/A'),
  store.sym('https://example.com/foo'),
  'bar',
);

const sparqlQuery = 'CONSTRUCT WHERE { ?nodeA ?edge ?nodeB }';
const query = $rdf.SPARQLToQuery(sparqlQuery, false, store);

store.query(query, result => {
  console.log(result);

  // Actual: []
  // Expected: The node added above 😢

});

sroze avatar Nov 21 '20 19:11 sroze

Hello!

I have the same problem here! Queries always return an empty array! :(

Melchyore avatar Apr 10 '21 02:04 Melchyore

@Melchyore rdflib has its own take on SPARQL. One of the things is that it demands a period after statements. Put a period after "?nodeB" in the query above and you'll get data back as expected.

jeff-zucker avatar Apr 10 '21 03:04 jeff-zucker

So, I'm going to close this issue, because it was a syntax error in the use case, not a bug.

jeff-zucker avatar Apr 10 '21 03:04 jeff-zucker

@jeff-zucker -- I disagree that rdflib treating a period as required, where it is optional according to SPARQL spec, is not a bug.

Anywhere rdflib evinces "its own take on SPARQL" (certainly anywhere rdflib is more stringent, and arguably anywhere rdflib is more forgiving) is absolutely a bug in rdflib, and this requirement by rdflib should be addressed in its code.

Please reopen this issue.

TallTed avatar Apr 12 '21 14:04 TallTed

Fair enough, reopened with better title. I wasn't able to find the period mentioned in the spec, can you point me to it? The examples at W3 are inconsistent, sometimes showing a period and sometimes not.

jeff-zucker avatar Apr 12 '21 15:04 jeff-zucker

I don't know whether the optionality is ever discussed in the prose. I can't quickly find it. However --

Section 19 contains the normative definition of the syntax for the SPARQL query and SPARQL update languages, as given by a grammar expressed in EBNF notation.

-- and this comes from that Section 19 --

[52]     TriplesTemplate     ::= TriplesSameSubject ( '.' TriplesTemplate? )?

Note that the '.' is contained in an element that appears zero or more times (expressed by the trailing ?). Hopefully that's sufficient....

TallTed avatar Apr 12 '21 17:04 TallTed