Ranking to Learn and Learning to Rank: On the Role of Ranking in Pattern Recognition Applications