4

I have a dataset that looks a bit like:

<item1> <isLocated> <someAddress>
<item2> <isLocated> <someAddress>
<item3> <isLocated> <someOtherAddress>

I want to be able to use SPARQL to answer the question:

"Which items will I find at someAddress or someOtherAddress?"

I could use a UNION like this:

SELECT ?item
{
    { ?item <isLocated> <someAddress> }
    UNION { ?item <isLocated> <someOtherAddress }
} 

But I think this will become pretty messy when I start talking about 100's or 1000's of addresses.

I think the VALUES inline data might be more suitable than a heap of UNION queries. I've tried writing the following query but my RDF store/engine (bigdata) seems to choke on it:

SELECT ?item
{
    ?item <isLocated> ?loc .
}
VALUES (?loc) { (<someAddress>) (<someOtherAddress>) }

(based on http://www.w3.org/TR/sparql11-query/#inline-data)

The error I get from bigdata is: Lexical error at line 5, column 7. Encountered: " " (32), after : "VALUES"

Am I forming this query correctly? Is using a UNION or VALUES more appropriate?

It seems no matter how I format this query (based on the w3 examples in the link above) I get similar Lexical errors.

Any ideas?

Cheers.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
user1685073
  • 55
  • 1
  • 6

2 Answers2

5

At a guess, I'd say that Bigdata does not yet support the VALUES clause. This is a brand new feature introduced in the latest SPARQL working draft (published just weeks ago), so quite naturally several tools will not yet support it.

You could try using BINDINGS instead (this is roughly the same feature from previous working drafts, which was replaced).

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • 1
    Reading the bigdata doc implies that they almost fully support SPARQL 1.1 [link](http://www.bigdata.com/bigdata/blog/). But I'm guessing you are right. I replaced `VALUES (?loc)` with `BINDINGS ?loc` in my query and it works as expected. – user1685073 Sep 20 '12 at 22:31
  • 1
    Yes, I'm sure they do, but SPARQL 1.1 is a work in progress, not a fixed standard yet. – Jeen Broekstra Sep 20 '12 at 22:50
3

You've mixed up the syntax a little. Either use:

VALUES ?loc { <someAddress> <someOtherAddress> }

which is a special form for a single variable, or:

VALUES (?loc) { ( <someAddress> ) ( <someOtherAddress> ) }

the general form.

You could also try IN

FILTER (?loc IN ( val1, val2, ...))
user205512
  • 8,798
  • 29
  • 28
  • 1
    You are right I did mess up the syntax in my post, when I use the correct syntax I still get the same error. – user1685073 Sep 20 '12 at 22:22
  • I was running the queries with the correct syntax though (tried both). 'FILTER' does produce a correct set of results. Both you and @JeenBroekstra gave answers that give correct solutions. – user1685073 Sep 20 '12 at 22:28
  • Yep, there's been some back and forth on the name of bindings / values. It's cheap to change, so unfortunately it has changed. (The semantics have changed too, but you probably wouldn't notice) – user205512 Sep 21 '12 at 09:06