Closed-Form Gibbs Sampling for Graphical Models with Algebraic Constraints