linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
565 stars 143 forks source link

🐛 SPARQL query demands period which spec says is optional #459

Open sroze opened 3 years ago

sroze commented 3 years ago

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 😢

});
Melchyore commented 3 years ago

Hello!

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

jeff-zucker commented 3 years ago

@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 commented 3 years ago

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

TallTed commented 3 years ago

@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.

jeff-zucker commented 3 years ago

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.

TallTed commented 3 years ago

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....