Text this: The effect of the electronic and structural environment on the valence of cerium