A characterization of semiampleness and contractions of relative curves