Efficient Detection of Exchangeable Factors in Factor Graphs