How to group wikipedia categories in python?

后端 未结 6 622
心在旅途
心在旅途 2021-02-01 06:58

For each concept of my dataset I have stored the corresponding wikipedia categories. For example, consider the following 5 concepts and their corresponding wikipedia categories.

6条回答
  •  天涯浪人
    2021-02-01 07:05

    "Therefore, I would like to know if there is a way to obtain the parent category of the categories (for example, the categories of enzyme inhibitor and bypass surgery belong to medical parent category)"

    MediaWiki categories are themselves wiki pages. A "parent category" is just a category which the "child" category page belongs to. So you can get the parent categories of a category in exactly the same way as you'd obtain the categories of any other wiki page.

    For example, using pymediawiki:

    p = wikipedia.page('Category:Enzyme inhibitors')
    parents = p.categories
    

提交回复
热议问题