Question

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?

Was it helpful?

Solution 2

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.)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top