1

I want to retrieve all the related objects of an entity and their labels, but I'm struggling against how the label service and the distinction between statements and (actual) entities works in Wikidata.

For example, given a query such as this one:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>

SELECT ?plabel ?o ?statement ?statement_valueLabel
WHERE
{
  wd:Q9671 ?p ?o. # Michael Schumacher

  # Get the predicate's label
  ?pEntity wikibase:claim ?p . 
    
  OPTIONAL {
    ?pEntity rdfs:label ?plabel .
    FILTER (LANG(?plabel) = "en") 
  }
  
  # (Try) to get the object's label by accessing the claim
  ?o ?statement ?statement_value.

  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # gives ?statement_valueLabel
}

I can manage to get the label of the statement, but in the process I also pull the statement's metadata which I don't want. For example:

Ugh

Am I doing this wrong? How can I simply get e.g position held UNICED Goodwill Ambassador?

2
  • without the statement qualifiers, it should be like this? Commented Jan 13 at 6:07
  • SELECT ?plabel ?statement_valueLabel WHERE { wd:Q9671 ?p ?stmt. # Michael Schumacher # Get the predicate's label ?pEntity wikibase:claim ?p . ?pEntity wikibase:statementProperty ?stmt_prop. OPTIONAL { ?pEntity rdfs:label ?plabel . FILTER (LANG(?plabel) = "en") } # (Try) to get the object's label by accessing the claim ?stmt ?stmt_prop ?statement_value. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # gives ?statement_valueLabel } Commented Jan 13 at 6:07

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.