BD111
BD111

Reputation: 201

Wikipedia API related topics

I'm looking for some way to retrieve all related topics for some keyword (also a topic). For example for the key word 'Pizza' I want to get something like: ["Food", "Italian", "Cheese"....]. Is there any way to do it with the Wikipedia API? Thanks!

Upvotes: 2

Views: 520

Answers (1)

AXO
AXO

Reputation: 9086

The closest thing that comes to mind is article categories. For information on how to retrieve them using API, refer to API:Categories. For example, the article pizza has the following non-hidden categories:

{
    "continue": {
        "clcontinue": "24768|Popular_culture",
        "continue": "||"
    },
    "query": {
        "pages": {
            "24768": {
                "pageid": 24768,
                "ns": 0,
                "title": "Pizza",
                "categories": [
                    {
                        "ns": 14,
                        "title": "Category:Cheese dishes"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Convenience foods"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Flatbread dishes"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Greek inventions"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Italian-American cuisine"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Italian cuisine"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Italian inventions"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Mediterranean cuisine"
                    },
                    {
                        "ns": 14,
                        "title": "Category:National dishes"
                    },
                    {
                        "ns": 14,
                        "title": "Category:Pizza"
                    }
                ]
            }
        }
    }
}

You can retrieve that via https://en.wikipedia.org/w/api.php?action=query&prop=categories&titles=Pizza&clshow=!hidden.

Similarly for dog: https://en.wikipedia.org/w/api.php?action=query&prop=categories&titles=Dog&clshow=!hidden

Upvotes: 2

Related Questions