Reputation: 91
Given a subject with multiple occurrences of the same property, is it possible to retrieve all the objects/values they point to, without specifying in advance their number?
This question resembles this one.
Example data (taken from link above):
@prefix example: <http://example.org/> .
example:subject1 example:property example:object1 .
example:subject1 example:property example:object2 .
example:subject1 example:property example:object3 .
...
It is possible to get a defined number of objects via:
select ?subject ?object1/2/n
where {?subject example:property ?object1, ?object2 .}
filter( ?object1 != ?object2 ).
But how to do if we do not know the number of occurrences of the property in advance? (besides programmatically). Thank you.
Upvotes: 0
Views: 871
Reputation: 11479
I suppose, you are a bit confused by the Turtle syntax.
In fact,
SELECT ?object1
WHERE {
?subject example:property ?object1, ?object2 .
FILTER ( ?object1 != ?object2 ).
}
is just a syntactic sugar for:
SELECT ?object1
WHERE {
?subject example:property ?object1 .
?subject example:property ?object2 .
FILTER ( ?object1 != ?object2 ).
}
This pattern matches all the triples which are different from each other only by their objects.
I suppose, "a subject with multiple occurrences of the same property" (from your question) means "there exist different objects for the same subject and the same property".
The pattern is symmetric, i.e. if :object1
is bound to ?object1
in a result, then :object1
will be bound to ?object2
in another result. It doesn't matter for this pattern whether any third triple with different object :object3
exists, but if it exists, :object3
will be bound to ?object1
in yet another result.
You can try also something like this for better understanding:
SELECT DISTINCT ?object1
WHERE {
?subject example:property ?object1 .
FILTER EXISTS {
?subject example:property ?object2 .
FILTER ( ?object1 != ?object2 )
}
}
Upvotes: 1