Domain-Driven Approaches for Constrained Counting and Sampling