An Algebraic Approach to Moralisation and Triangulation of Probabilistic Graphical Models