8

What is the Wikidata API equivalent to this page which lists all known Wikidata properties? I would like to search for a property, e.g. 'doctoral advisor', and get back P184.

A similar function exists for items, but I can't seem to find the equivalent for properties.

Termininja
  • 6,620
  • 12
  • 48
  • 49
nerab
  • 121
  • 1
  • 7

4 Answers4

8

Using action=wbsearchentities with type=property should do. Wikidata API doc is here, search for "=wb" to get the Wikidata-specific functions.

svick
  • 236,525
  • 50
  • 385
  • 514
Magnus Manske
  • 231
  • 1
  • 2
  • 1
    Great, thanks, that looks great. So I can search, and I can get one property with [action=wbgetentities&ids=P17](https://www.wikidata.org/w/api.php?action=wbgetentities&ids=P17), but what about the list of all properties? – nerab Aug 04 '14 at 20:51
6

Update: thank to @nerab's answer, I updated wikidata-properties-dumper to use Quarry SQL results: that's indead much cleaner :)

Update 2: Quarry wasn't that flexible, I moved to use a SPARQL query and wrapped that in a Wikidata CLI command: wd props

I wrote a small script to query all properties with wikidata API's action=wbgetentities. It generate a json file with

key: value

being

property Pid: property label in the request language

I published the outputs for a few languages and could do for other language on request until there is an official (and cleaner) answer for this need

maxlath
  • 1,804
  • 15
  • 24
  • This CLI cannot be installed on Windows. – sean Apr 15 '19 at 09:04
  • @sean it should be possible to install it on windows, if it fails that's a bug I would be happy to fix. Do you get that same error https://github.com/maxlath/wikidata-cli/issues/72 or something else? – maxlath Apr 15 '19 at 10:55
4

Thanks to the comments in @maxlath's project, I found Quarry.

A list of all Wikidata properties can be fetched from

http://quarry.wmflabs.org/run/45013/output/1/json

This particular list is in English, but the query can be modified for other languages, too.

nerab
  • 121
  • 1
  • 7
2

You can use this SPARQL query: it returns property name, description and comma separated also known as labels from English language:

SELECT ?property ?propertyLabel ?propertyDescription (GROUP_CONCAT(DISTINCT(?altLabel); separator = ", ") AS ?altLabel_list) WHERE {
    ?property a wikibase:Property .
    OPTIONAL { ?property skos:altLabel ?altLabel . FILTER (lang(?altLabel) = "en") }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
 }
GROUP BY ?property ?propertyLabel ?propertyDescription
LIMIT 5000
Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106