In the documentation for rdf_where/1 the following is stated “Preferably, constraints are placed before the graph pattern as they often help the RDF database to exploit its literal indexes.”
Unfortunately, this doesn’t seem to work in practice as illustrated in the transcript below:
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.1-4-gb45cea22c)
?- use_module(library(semweb/rdf11)).
true.
?- use_module(library(semweb/turtle)).
true.
?- rdf_load('test.ttl').
% Loaded "test.ttl" in 0.00 sec; 1 triples
true.
?- {V=="COrUSCENT"},rdf(S,P,V). % <-- I expect this to succeed
false.
?- rdf(S,P,V),{V=="COrUSCENT"}. % <-- Positioning the constraint after the rdf statement works as expected
S = 'file:///Users/jgeurts/tmp/dpei/Projet#002',
P = 'http://www.inria.fr/dpei/acronyme',
V = "COrUSCENT"^^'http://www.w3.org/2001/XMLSchema#string'.
Turns out the Turtle library still asserts strings as untyped literals. I kept that, as changing that will break old code. I did change the literal matching to consider untyped and string typed literals equal.
Not sure this covers all cases. It does fix this problem. I’m a little out of touch with the RDF libraries … They are still a vital part of the eco system though.
Thanks Jan! I’ll let you know if I find other problematic cases
I guess properly asserting string types isn’t an option, is it? Considering that you are a little out of touch with the RDF libraries (which is normal I suppose), such exceptions smell like it may a be a source for future (debugging) problems?
I don’t know. One option might be a setting. For new projects I guess it would be better to ditch the notion of untyped literals. Just replacing them unconditionally will probably cause problems for older projects that are still alive.
Let us wait and see what pops up and decide when this happens.