Parsing Countries, Regions, Cities Wikipedia

Is it possible to get a list of all countries, regions and cities of Wikipedia with the relations between them? I could not find an API suitable for this task. What is the easiest way to analyze all the information I need? PS: I know that there are other data sources from which I can get this information. But I'm interested in Wikipedia ...

+4
source share
2 answers

It may be a bit tedious to get the whole graph, but you can get most of the data from the experimental / unofficial Wikidata a> request API.

I suggest the following workflow:

  • Go to the instance of the objects you want to work with, say Estonia (Q191) and find your copy (P31), you will find: country, sovereign state, UN member, EU member, etc.

  • Use the Wikidata Query Query API Command to display each entity that as selected property P31. Let's try the country (Q6256) :

    http://wdq.wmflabs.org/api?q=claim[31:6256]

It displays an array of numeric identifiers: your countries! (note that the result is still incomplete, as only 141 items were found: both countries are not on Wikidat or, as Nemo suggested in the comments, some countries can be found in countries (Q6256) subclasses (P279) )

  • , , API :

    https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q16&format=json&props=labels|claims&languages=en|fr

    ( (Q16), json, , . )

50, :

https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q16|Q17|Q20|Q27|Q28|Q29|Q30|Q31|Q32|Q33|Q34|Q35|Q36|Q37|Q38|Q39|Q40|Q41|Q43|Q45|Q77|Q79|Q96|Q114&format=json&props=labels|claims&languages=en|fr
  • , (P150), .

  • tree. , (Q142), http://wdq.wmflabs.org/api?q=tree[142][150] Tadaaa, 36994 ! , , . , .

  • , (P279) (Q15284) ( ): , (Q484170),

    http://wdq.wmflabs.org/api?q=tree[142][150] AND claim[31:484170]

    : !

+3

Wikidata / dbpedia.

Wikidata, MediaWiki, API, . pywikibot. , , (, ).

Wikidata

+2

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


All Articles