Foundations of Probabilistic Logic Programming