On 5 Oct 2011, at 18:40, Eric Scott wrote:
> Hi all-
Hi Eric,
> I've tried using a subquery like this:
>
> SELECT ?entity ?arbitraryLabel
> where
> {
> ?entity my:hasFeature my:VeryImportantFeature.
> {
> SELECT ?arbitraryLabel
> {
> ?entity my:hasLabelSet ?labelSet.
> ?labelSet my:hasLabel ?arbitraryLabel.
> }
> LIMIT 1
> }
> }
>
> on the assumption that the variables in the main query are scoped in such a
> way that they are shared with the subquery.
What's happening is this: sparql is evaluated from inside out. So your inner
select happens first, and you get one row:
?arbitraryLabel = "unrelated label 25"
which is then (cross) joined with the result of ?entity my:hasFeature
my:VeryImportantFeature.
You could make the inner select:
{
SELECT ?entity ?arbitraryLabel
...
}
which gives a more understandable result, perhaps, in that you'll get the
entity with that label returned.
One way to get what you want is:
SELECT ?entity (SAMPLE(?label) AS ?arbitraryLabel)
where
{
?entity my:hasLabelSet ?labelSet .
?labelSet my:hasLabel ?label .
}
GROUP BY ?entity
which says: I want one entity per row. Pick any label.
Damian