Search code examples
sparqlwikidata

How to get all property from an item based on its Q number?


I want to gather all properties of a item from wikidata.

All queries I see so far assume you know properties you are looking for, but in my case, I'm not.

For example, when querying for Q1798740, I would like a returned value that looks like

[{"item": "Q1798740",
  "P31": ["Q1146"],
  "P17": ["Q70972"],
  ...
  "P2043":"70 metres"}
]

and that contains all statements from the wikidata page

What query should I perform?


Solution

  • You need only to ask for {wd:Q1798740 ?p ?value} but it would be useful also to get the labels of the properties, which is a bit trickier:

    SELECT DISTINCT ?p ?property_label ?value 
    WHERE
    {
    wd:Q1798740 ?p ?value .
    
    ?property wikibase:directClaim ?p ;
              rdfs:label ?property_label .
    
     FILTER(LANG(?property_label)="en")
    }