in reply to algorithm to categorize

You want AI::Categorize.