
    \Mh                         d Z ddlZddlZddlmZ dgZ ed           ej        d          d                         ZdS )	z;Function for computing the moral graph of a directed graph.    N)not_implemented_formoral_graph
undirectedT)returns_graphc                     |                                  }| j                                        D ]-}t          j        |d          }|                    |           .|S )a  Return the Moral Graph

    Returns the moralized graph of a given directed graph.

    Parameters
    ----------
    G : NetworkX graph
        Directed graph

    Returns
    -------
    H : NetworkX graph
        The undirected moralized graph of G

    Raises
    ------
    NetworkXNotImplemented
        If `G` is undirected.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (2, 3), (2, 5), (3, 4), (4, 3)])
    >>> G_moral = nx.moral_graph(G)
    >>> G_moral.edges()
    EdgeView([(1, 2), (2, 3), (2, 5), (2, 4), (3, 4)])

    Notes
    -----
    A moral graph is an undirected graph H = (V, E) generated from a
    directed Graph, where if a node has more than one parent node, edges
    between these parent nodes are inserted and all directed edges become
    undirected.

    https://en.wikipedia.org/wiki/Moral_graph

    References
    ----------
    .. [1] Wray L. Buntine. 1995. Chain graphs for learning.
           In Proceedings of the Eleventh conference on Uncertainty
           in artificial intelligence (UAI'95)
       )r)to_undirectedpredvalues	itertoolscombinationsadd_edges_from)GHpredspredecessors_combinationss       Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/algorithms/moral.pyr   r      s`    X 	
A 4 4$-$:5A$F$F$F!	23333H    )	__doc__r   networkxnxnetworkx.utilsr   __all___dispatchabler    r   r   <module>r      s    B B         . . . . . ./ \""%%%. . &% #". . .r   