Extending Factor Graphs so as to Unify Directed and Undirected Graphical Models