Unexpected results with SERVICE clause

I have the following query comparing offsets in text extracted by different tools. I load all the information extracted by tool1/tool2 into different databases and use a federated query from the tool1 database (since it extracts many more details and therefore has way more triples).

prefix foo: <http://purl.org/foo#>
prefix doco: <http://purl.org/spar/doco/>
select distinct ?sent1 ?sent2 ?offset 
where {
        { #pragma group.join
            ?doc1 rdfs:label "someLabel"^^xsd:string .
            ?doc1 foo:contains ?sent1 .
            ?sent1 a doco:Sentence ; foo:char_offset ?offset }
        { SERVICE <http://localhost:5820/tool2/query>
            { SELECT ?sent2 where {
                ?doc2 rdfs:label "someLabel"^^xsd:string .
                ?doc2 foo:contains ?sent2 .
                ?sent2 a doco:Sentence ; foo:char_offset ?offset .
            }}}
} ORDER BY ?offset

I get a binding set result for EVERY sentence from tool1 matched with EVERY sentence from tool2. This is wrong since the ?offset should be the same value/same variable.

However, if I change the query to add a filter, then the results are correct:

prefix foo: <http://purl.org/foo#>
prefix doco: <http://purl.org/spar/doco/>
select distinct ?sent1 ?sent2 ?offset 
where {
        { #pragma group.join
            ?doc1 rdfs:label "someLabel"^^xsd:string .
            ?doc1 foo:contains ?sent1 .
            ?sent1 a doco:Sentence ; foo:char_offset ?offset }
        { SERVICE <http://localhost:5820/tool2/query>
            { SELECT ?sent2 ?offset2 where {
                ?doc2 rdfs:label "someLabel"^^xsd:string .
                ?doc2 foo:contains ?sent2 .
                ?sent2 a doco:Sentence ; foo:char_offset ?offset2 .
            }}}
        filter (?offset = ?offset2) 
} ORDER BY ?offset

Andrea

Thanks for the details Andrea. Which version of Stardog are you using to run this query?

I am still on 6.1.0.

Andrea

Any status on this? Having to add the FILTER is definitely slowing things down.

Andrea

I did verify that the problem still exists with 6.1.1.

Andrea

Sorry for the delay. I just noticed that you project out ?offset in the first query:

        { SERVICE <http://localhost:5820/tool2/query>
            { SELECT ?sent2 where {

You will need to include ?offset in the projection if you want it to join with the other parts of the query.

HTH,
Jess

When I do that, I get an error: QueryEval: SERVICE evaluation returned HTTP response code 400.

Andrea

For what it's worth, you can use SERVICE <db://tool2> instead of SERVICE <http://localhost:5820/tool2/query> for looking at other databases on the same server. This would avoid using HTTP to do it and take out another possible point of failure for the query. Might that get around the 400?

Stephen, When I replace http://... with db://dbname, I get the error:

Encountered " "where" "WHERE "" at line 107, column 1. Was expecting one of: "{" ... "}" ... ";" ... "," ... "." ... "bind" ... "graph" ... "minus" ... "filter" ... "values" ... "service" ... "optional" ... "." ...

Note, specifically that the line 3 is 107!

So, my choices are:

  1. Executes correctly with the filter
  2. HTTP response code 400
  3. Query error

Andrea

You can try using either WireShark or if you don't want to install anything either Hookbin or RequestBin to look at the actual request that is being sent and returning 404.

Andrea,

Can you share the entire query? Either here or to support@stardog.com? It sounds like something non-obvious is going on.

Jess