Learning to Substitute Components for Compositional Generalization