Search code examples
sparqlmarklogicmarklogic-8propertypath

Incomplete sem:sparql results for Property Paths when "optimize=0"


Consider the following subClassOf relations:

m1
|_ m1_1
   |_ m1_1_1

The following query correctly returns m1_1 and m1_1_1:

sem:sparql('
SELECT * 
WHERE { 
 ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ <http://example.org/people#m1> .
}', (), 
("optimize=1"))

However, the following query only returns m1_1:

sem:sparql('
SELECT * 
WHERE { 
 ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ <http://example.org/people#m1> .
}', (), 
("optimize=0"))

It's also the case with *.

After upgrading to MarkLogic 8.0-5.2, the previous sem:sparql queries return correct results but not when the object is a parameter. E.g. the following query doesn't return anything:

sem:sparql('
SELECT * 
WHERE {
?s <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ ?item . 
}',
(map:new ((map:entry ("item", sem:iri("http://example.org/people#m1"))))), 
("optimize=0"))

Solution

  • Here are some possible workarounds:

    sem:sparql('
    SELECT * 
    WHERE {
    BIND (?param AS ?item) .
    ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ ?item . 
    }',
    (map:new ((map:entry ("param", sem:iri("http://example.org/people#m1"))))), 
    ("optimize=0"))
    

    Or

    sem:sparql('
    SELECT * 
    WHERE {
    ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ ?item . 
    FILTER (?item = ?param) .
    }',
    (map:new ((map:entry ("param", sem:iri("http://example.org/people#m1"))))), 
    ("optimize=0"))