qwikidata.sparql module¶
Module for the Wikidata SPARQL endpint.
- get_subclasses_of_item(item_id, return_qids=True)[source]¶
Return all subclasses of a wikidata item.
Finds all items where a chain of the following form exists,:
Qid_i -[P279]-> Qid_j ... Qid_k -[P279]-> item_id
Will always include the item itself in the return results. Note that property P279 = “subclass of”.
- Parameters
Examples
We can get all item IDs that are subclasses of Q6256,
>>> get_subclasses_of_item('Q6256') ['Q6256', 'Q112099', 'Q123480', ... 'Q4994005', 'Q6805624', 'Q15895923']
>>> get_subclasses_of_item('Q6256', return_qids=False) {'head': {'vars': ['WDid']}, 'results': {'bindings': [ {'WDid': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q6256'}}, {'WDid': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q112099'}}, ... {'WDid': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q6805624'}}, {'WDid': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q15895923'}}]}}