Hi, I am querying MediaWiki to get category information from Wikipedia for certain titles. I have written a java program to get the list but some titles do not return category results.
For example, "Populated places" does not return any category listing for the query but if you search Wikipedia, it gives categories. Following is the generated query for this particular title. I am trying to get results in JSON format. The query doesn't work for xml format either.
http://en.wikipedia.org/w/api.php?action=query&prop=categories&title...
what is the problem here???
Kalpa Gunaratna
On Wed, Aug 03, 2011 at 02:40:52PM -0400, Dalkandura Arachchige Gunaratna wrote:
For example, "Populated places" does not return any category listing for the query but if you search Wikipedia, it gives categories.
No it doesn't. http://en.wikipedia.org/w/index.php?title=Populated_places&redirect=no
Perhaps you did not notice you followed a redirect to [[Populated place]], no 's'?
If you want the API to follow redirects, add '&redirects' to your query:
http://en.wikipedia.org/w/api.php?action=query&prop=categories&title...
Thank you and that makes sense. I'm trying to change the code now to support redirects since it gets a different JSONObject (key is not categories for redirects) for redirects.
***one other question, for the title "Nervous system", I need to query into 3 layers. for the firs time it gives me 3 categories, 1. Nervous system 2. Neurobiology 3. Neuroscience
Then I need to query each of these 3 categories to get their sub categories. but in a loop when I parse again Nervous system, it gives me the same three results but I want to get the results as I traverse in Wikipedia manually. In Wikipedia, when I search "Nervous system", it gives me these three results first and then when I click on the category Nervous system (in the initial result of categories), it gives me "Organ systems" and "Mind". How can I do this in the code with MediaWiki API?
Kalpa Gunaratna
----- Original Message ----- From: Brad Jorsch b-jorsch@alum.northwestern.edu Date: Wednesday, August 3, 2011 3:28 pm Subject: Re: [Mediawiki-api] categories query does not return any results. To: MediaWiki API announcements & discussion mediawiki-api@lists.wikimedia.org
On Wed, Aug 03, 2011 at 02:40:52PM -0400, Dalkandura Arachchige Gunaratna wrote:
For example, "Populated places" does not return any category listing for the query but if you search Wikipedia, it gives categories.
No it doesn't. http://en.wikipedia.org/w/index.php?title=Populated_places&redirect=no
Perhaps you did not notice you followed a redirect to [[Populated place]], no 's'?
If you want the API to follow redirects, add '&redirects' to your query:
http://en.wikipedia.org/w/api.php?action=query%E2%88%9D=categories&title...
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Dalkandura Arachchige Gunaratna wrote:
Thank you and that makes sense. I'm trying to change the code now to support redirects since it gets a different JSONObject (key is not categories for redirects) for redirects.
***one other question, for the title "Nervous system", I need to query into 3 layers. for the firs time it gives me 3 categories,
- Nervous system
- Neurobiology
- Neuroscience
Then I need to query each of these 3 categories to get their sub categories. but in a loop when I parse again Nervous system, it gives me the same three results but I want to get the results as I traverse in Wikipedia manually. In Wikipedia, when I search "Nervous system", it gives me these three results first and then when I click on the category Nervous system (in the initial result of categories), it gives me "Organ systems" and "Mind". How can I do this in the code with MediaWiki API?
Kalpa Gunaratna
http://en.wikipedia.org/w/api.php?action=query&prop=categories&title...
Categories [[Nervous system]] is in.
http://en.wikipedia.org/w/api.php?action=query&prop=categories&title...
Categories [[Category:Nervous system]] is in (aka. parent categories).
mediawiki-api@lists.wikimedia.org