Roy Smith wrote:
> What's the best way to tell if an article is in a general category?
>  Specifically, given a page title, I want to know if that page is
> (transitively) in Category:Song.  For example, I can get
> 
> http://en.wikipedia.org/w/api.php?action=query&prop=categories&titles=bohemian%20Rhapsody&cllimit=50
> <http://en.wikipedia.org/w/api.php?action=query&prop=categories&titles=bohemian
> Rhapsody&cllimit=50>
> 
> which gives me (in part)
(...)
> What I really want to know is if the page is in Category:Song.  In fact,
> it is, because of the category chain: 1975 singles -> 1975 songs
> -> Songs by year -> Songs, but finding that path involved some intuition
> about likely paths to explore.  Lacking such intuition, is there any
> better mechanism in the API other than an exhaustive search through the
> category tree?
> 
> 
> --
> Roy Smith
> r...@panix.com <mailto:r...@panix.com>

You could implement some heuristic, like "follow categories which
contain the target category name in them", which would lead you to
Category:Songs via Category:Songs written by Freddie Mercury ->
Category:Songs by songwriter -> Category:Songs
But in order to determine a page is NOT in that category you will need
an exhaustive search (skipping already traversed categories).

If you want to test all articles for the same category, it would be
easier to build the graph or child categores of Category:Song, and you
could then directly test for pertenence to any of them (or make the
article list while you are browsing the categories).


_______________________________________________
Mediawiki-api mailing list
Mediawiki-api@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api

Reply via email to