I'm looking to use SPARQL for a relatively basic task: Given a FOAF graph, I'd like to parse the elements I find in there, get their tags (if they exist) and then, use those as new graphs from which to find information about those people.
So for instance, you could imagine a simple use case where I want to run a SPARQL query to list all of my favorite foods (as per my FOAF file), and also the favorite foods of all my friends.
Here is what this looks like at the moment. Note that for testing purposes, at the moment all I'm trying to do with the query below is fetch the name of the friend, through the ?name3 variable. Running this query doesn't return any results for ?graph and ?name3, even though I know that the rdfs:seeAlso link to some valid RDF files, of which at least two should have a name attribute. Thanks for any input you might have!
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?name1 ?name2 ?graph ?name3
FROM <my-rdf-file>
WHERE {
?person1 foaf:knows ?person2 .
?person1 foaf:name ?name1 .
?person2 foaf:name ?name2 .
OPTIONAL {
?person2 rdfs:seeAlso ?graph .
GRAPH ?graph {
?person3 foaf:name ?name3 .
}
}
}