Created
August 14, 2015 16:46
-
-
Save notconfusing/40c5c22d4368db5010ab to your computer and use it in GitHub Desktop.
Using Pywikibot to Get a Wikidata Subclass of Superclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pywikibot | |
wikidata = pywikibot.Site('en','wikipedia').data_repository() | |
drummer = pywikibot.ItemPage(wikidata, 'Q386854') | |
data = drummer.get() | |
claims = data['claims'] | |
subclass_ofs = claims['P279'] #Property P279 is subclass of | |
superclass_items = [superclass.target for superclass in subclass_ofs] | |
def english_name(item): | |
return item.get()['labels']['en'] | |
superclass_names = [english_name(superclass_item) for superclass_item in superclass_items] | |
print(superclass_names) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment