Add from_graph classmethod to Pattern class.