Wikidata API: check if a Wikivoyage article is related to Wikidata

I want to programmatically check if an English Wikivoyage article (e.g. Bronzeville ) is related to the Wikidata Database or not.

For example, the Bronzeville article in the English Wikivoyage is NOT related to Wikidata (although the element exists ).

Note. Some Wikidata elements have labels, but this does not mean existence or nonexistence, since some elements have no labels, and some elements with the same label relate to two different things (for example, place and person).

Is there a way to do this using the Wikidata API or another?

+4
source share
2 answers

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

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

You will get the result as follows:

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

If the link does not exist (Bronzeville):

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

Result:

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

( props= part of the request exists so that you do not receive all the information about the record, just whether it exists or not.)

+2
source

Whether the Wikivoyage article is related to Wikidata or not can be found through a query similar to the one 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 answer contains "wikibase_item", then it is connected.

+2
source

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


All Articles