sparqlmediawiki-apiwikidata-query-servicewikibase

Wikidata Sparql get item descriptions


I'm following the MWAPI docs (https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI#Find_all_entities_with_labels_%22cheese%22_and_get_their_types) and have the following query:

SELECT * WHERE {
  SERVICE wikibase:mwapi {
      bd:serviceParam wikibase:endpoint "www.wikidata.org";
                      wikibase:api "EntitySearch";
                      mwapi:search "python";
                      mwapi:language "en".
      ?item wikibase:apiOutputItem mwapi:item.
      ?label wikibase:apiOutputItem mwapi:label.
      ?num wikibase:apiOrdinal true.
  }
} 
ORDER BY ASC(?num) LIMIT 10

I also want to retrieve the description of the wikidata item but don't know how to get it. I've tried adding the following line ?description wikibase:apiOutputItem mwapi:description but it seems to be an invalid property on the API. How do I retrieve it and where can I find this in the docs?

Query reproducible here: https://query.wikidata.org/#SELECT%20%2a%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Amwapi%20%7B%0A%20%20%20%20%20%20bd%3AserviceParam%20wikibase%3Aendpoint%20%22www.wikidata.org%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wikibase%3Aapi%20%22EntitySearch%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Asearch%20%22python%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Alanguage%20%22en%22.%0A%20%20%20%20%20%20%3Fitem%20wikibase%3AapiOutputItem%20mwapi%3Aitem.%0A%20%20%20%20%20%20%3Flabel%20wikibase%3AapiOutputItem%20mwapi%3Alabel.%0A%20%20%20%20%20%20%3Fdesc%20wikibase%3AapiOutputItem%20mwapi%3Adescription.%0A%20%20%20%20%20%20%3Fnum%20wikibase%3AapiOrdinal%20true.%0A%20%20%7D%0A%7D%20%0AORDER%20BY%20ASC%28%3Fnum%29%20LIMIT%2010


Solution

  • The wikibase:label service provides both the label and the description of an item for a specified language. Both have to be explicitly queried for in the SELECT part:

    SELECT ?item ?itemLabel ?itemDescription ?num WHERE {
      SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "EntitySearch";
                        mwapi:search "python";
                        mwapi:language "en".
        ?item wikibase:apiOutputItem mwapi:item.
        ?num wikibase:apiOrdinal true.
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY ASC(?num) LIMIT 10