I have the following RDF data (Person, worksAt, Branch) (Branch, location, Town) (Town, country, Country)
and the property path
worksAt, location, country
Can I formulate a SPARQL query where given a property e.g. country it will return me the most-left class (i.e. Person) of the graph?
SELECT ?person WHERE
{
?person :worksAt ?branch.
?branch :location ?town.
?town :country :?country.
}
Using a sequence path defined as:
elt1 / elt2 A sequence path of elt1, followed by elt2
SELECT ?person WHERE
{
?person :worksAt/:location/:country ?country.
}
I don't understand what you mean with "given a property e.g. country", do you mean a specific instance instead? For example if the person should work in Germany, you would replace ?country
with :Germany
.
These examples assume that your properties only have a single class as a domain, e.g. only persons can work somewhere. Otherwise you have to add ?person a :Person.
and so on.