Search code examples
sparqlwikidata

Get properties by QID?


I can get item and its properties by label:

SELECT distinct ?item ?itemLabel ?itemDescription
  (SAMPLE(?DR) as ?DR) (SAMPLE(?article)as ?article)
WHERE {
  ?item wdt:P31 wd:Q5.
  ?item ?label "Einstein"@en
  OPTIONAL{?item wdt:P569 ?DR .}
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>.
  OPTIONAL{?item wdt:P570 ?RIP .}
  OPTIONAL{?item wdt:P18 ?image .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?itemDescription

See on Wikidata Query Services.

How can I do the same using QID instead label?


Solution

  • Using the URI instead of the variable ?item will get the information based on the entity Albert Einstein:

    PREFIX  schema: <http://schema.org/>
    PREFIX  bd:   <http://www.bigdata.com/rdf#>
    PREFIX  wdt:  <http://www.wikidata.org/prop/direct/>
    PREFIX  wikibase: <http://wikiba.se/ontology#>
    
    SELECT DISTINCT  ?item ?itemLabel ?itemDescription (SAMPLE(?DR) AS ?DRSample) (SAMPLE(?article) AS ?articleSample)
    WHERE
      { ?article  schema:about       ?item ;
                  schema:inLanguage  "en" ;
                  schema:isPartOf    <https://en.wikipedia.org/>
        FILTER ( ?item = <http://www.wikidata.org/entity/Q937> )
        OPTIONAL
          { ?item  wdt:P569  ?DR }
        OPTIONAL
          { ?item  wdt:P570  ?RIP }
        OPTIONAL
          { ?item  wdt:P18  ?image }
        SERVICE wikibase:label
          { bd:serviceParam
                      wikibase:language  "en"
          }
      }
    GROUP BY ?item ?itemLabel ?itemDescription