2

I'm running the following query to get Athletes data from DBpedia

  SELECT * WHERE {

  ?player a <http://dbpedia.org/ontology/Athlete> .
  ?player foaf:name ?firstname .
  ?player foaf:surname ?lastname .
  ?player <http://dbpedia.org/ontology/country> ?birthplace .
  ?player <http://dbpedia.org/ontology/birthDate> ?birthDate .
  ?player <http://dbpedia.org/ontology/Person/height> ?height .
  ?player <http://dbpedia.org/ontology/Person/weight> ?weight .
}

but it only returns about 300 records! What's the problem with my query?

1 Answer 1

3

I had to make the last four attributes optional

  SELECT * WHERE {

  ?player a <http://dbpedia.org/ontology/Athlete> .
  ?player foaf:name ?firstname .
  ?player foaf:surname ?lastname .
  optional {?player <http://dbpedia.org/ontology/country> ?birthplace .}
  optional {?player <http://dbpedia.org/ontology/birthDate> ?birthDate .}
  optional {?player <http://dbpedia.org/ontology/Person/height> ?height .}
  optional {?player <http://dbpedia.org/ontology/Person/weight> ?weight .}
}

this way I could get all the records even when there are missing values

3
  • 1
    Note that you're not getting all the records straight off -- there are more than 650K solutions to this query, and you (currently) get 10K from the query as written. You can add a few clauses -- ORDER BY, LIMIT, OFFSET -- to step through the full solution set. Also note, you'll often get multiple rows for a single ?player -- because WIkipedia, and hence DBpedia, is full of dirty data. This may or may not matter to your use, but it's important to know.
    – TallTed
    Commented Aug 18, 2016 at 22:26
  • How can I prevent retrieving multiple rows for the same player?
    – user8811
    Commented Aug 19, 2016 at 13:44
  • 1
    This depends on which attributes matter to you, and whether you care that there are other values for them. If you just add ORDER BY ?player to your query, you can see some of the dirtiness present. If you don't care about which value you get, SAMPLE is a useful tool. The query becomes too long for a comment, and I think this is a distinct question (which may have an answer already), so I won't go deeper here.
    – TallTed
    Commented Aug 19, 2016 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.