Nicolas Raoul
Nicolas Raoul

Reputation: 60193

Wikidata API: Check whether a Wikivoyage article is linked from Wikidata

I want to programmatically check whether an English Wikivoyage article (for instance Bronzeville) is linked from the Wikidata database or not.

For instance, the Bronzeville article at English Wikivoyage is NOT linked from Wikidata (even though the item exists).

Note: Some Wikidata items have labels, but that does not imply existence or non-existence, as some items have no label, and some items with the same label refer to two different things (for instance a place and a person).

Is there a way to do this, via the Wikidata API or other?

Upvotes: 4

Views: 598

Answers (2)

svick
svick

Reputation: 244757

You can use the wbgetentities method for this. To do this, ask it for the entity that's related to the desired article on enwikivoyage. For example, for an entity where the link exists (Prague):

http://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwikivoyage&titles=Prague&format=xml&props=

You get result like this:

<entity id="q1085" type="item" />

If the link doesn't exist (Bronzeville):

http://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwikivoyage&titles=Bronzeville&format=xml&props=

The result is:

<entity site="enwikivoyage" title="Bronzeville" missing="" />

(The props= part of the query is there so that you don't get all the information about the entry, just whether it exists or not.)

Upvotes: 2

Nicolas Raoul
Nicolas Raoul

Reputation: 60193

Whether a Wikivoyage article is linked from Wikidata or not can be found via a query like the ones below:

https://en.wikivoyage.org/w/api.php?action=query&titles=Bronzeville&prop=pageprops&format=jsonfm

https://en.wikivoyage.org/w/api.php?action=query&titles=Paris&prop=pageprops&format=jsonfm

If the response contains "wikibase_item", then it means it is linked.

Upvotes: 3

Related Questions