How to find a Wikidata object by property?

I would like to know if there is a way to find a Wikidata object with the specified property using their API. For example, there are many objects that have the Freebase ID property (property: P646). This is a unique identifier, and I want to get the object by this identifier.

Does anyone know how to achieve this?

+6
source share
3 answers

[ updated answer : using SPARQL endpoint]

wdq is replaced by the official SPARQL endpoint , where this query looks like this:

PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?item ?itemLabel WHERE { ?item wdt:P646 "/m/0gnfq" . } 

You can PREFIX wd: PREFIX wdt: PREFIX rdfs: PREFIX p: PREFIX v: SELECT? Item? ItemLabel WHERE {? Item wdt: P646 "/ m / 0gnfq". SERVICE wikibase: label {bd: serviceParam wikibase: language "en". }} rel = noreferrer> try this on query.wikidata.org

and to get the results of this query in JSON format, you can make a query at " https://query.wikidata.org/sparql?format=json&query=YOURQUERY ", where YOURQUERY is a SPARQL query with URI encoding:

https://query.wikidata.org/sparql?format=json&query=PREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%20PREFIX%20wdt%3A%20%3Chttp% 3A% 2F% 2Fwww.wikidata.org% 2Fprop% 2Fdirect% 2F% 3E% 20SELECT% 20% 3Fitem% 20% 3FitemLabel% 20WHERE% 20% 7B% 20% 3Fitem% 20wdt% 3AP646% 20% 22% 2Fm% 2F0gnfq 22% 20. % 20SERVICE% 20wikibase% 3Alabel% 20% 7B% 20bd% 3AserviceParam% 20wikibase% 3Alanguage% 20% 22en% 22% 20% 20% 7D% 20% 7D

[ old answer : using WDQ]

you can get the wmflabs API ( documentation ) as follows:

 http://wdq.wmflabs.org/api?q=string[646:/m/0gnfq] 

Here I am asking for Wikidata entities with property 646 value /m/0gnfq .

The answer will look like this:

 { "status": { "error": "OK", "items": 1, "querytime": "161ms", "parsed_query": "STRING[646:'/m/0gnfq']" }, "items": [ 180736 ] } 

So the entity I was looking for is Q180736 .

Here, the request uses the string parameter, since freebase identifiers are strings in Wikidata, but for properties that imply Wikidata entities as a value type, you will need to use the claim parameter. Example from the documentation:

The requirement [138: 676555] returns all items that are named after (P138) Francis of Assisi (Q676555).

+10
source

Now there is a SPARQL endpoint at https://query.wikidata.org

Here you can enter a SPARQL query for Wikidata. for example, for a Freebase property, it might look like this:

 PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX wikibase: <http://wikiba.se/ontology#> PREFIX p: <http://www.wikidata.org/prop/> PREFIX v: <http://www.wikidata.org/prop/statement/> PREFIX q: <http://www.wikidata.org/prop/qualifier/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?subject ?subjectLabel WHERE { ?subject wdt:P646 ?object . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } } LIMIT 10 
+1
source

I also prefer the Wikidata request API , but if you need more information about the elements, you can use the Wikidata API . For example, in your case, all elements that reference the Freebase identifier property (P646) :

 https://www.wikidata.org/w/api.php?action=query&format=xml&generator=backlinks&gblnamespace=0&gbllimit=5000&prop=info&gbltitle=Property:P646 
+1
source

Source: https://habr.com/ru/post/978865/


All Articles