Calculate the dictionary rank of any given arbitrary string