Reputation: 1355
Beginner in DBPedia/SPARQL/Semantic data. I ran following queries to "find out the sport for each athlete"
select ?athlete ?sport where
{
?athlete rdf:type <http://dbpedia.org/ontology/Athlete>. #query1
?athlete dbpedia2:sport ?sport #query2
}
It does give results but not the full set that I am looking for. "query1" by itself returns more athletes but combined with "query2", I get a lot less resultset.
Please explain the discrepancy. Am I missing something? Whats the alternative?
Regards
Upvotes: 2
Views: 342
Reputation: 2247
Your query selects all athlete nodes which have both rdf:type and dbpedia2:sport properties. You can use optional
clause to retrieve nodes even if some property isn't bound. For example:
select ?athlete ?sport where {
?athlete rdf:type <http://dbpedia.org/ontology/Athlete>. #query1
optional {?athlete dbpedia2:sport ?sport} #query2
}
Better way to get sport:
select ?athlete ?type where {
?athlete rdf:type <http://dbpedia.org/ontology/Athlete>.
optional {
?athlete rdf:type ?type.
?type rdfs:subClassOf <http://dbpedia.org/ontology/Athlete>
}
}
Upvotes: 3