Ë
    çÍ:j¿{  ã                   óÌ   — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ  G d„ d	«      Zdd
„Z G d„ de«      Zd„ Zdd„Zd„ Zd„ Zd„ ZdZdZdZedk(  r e«        yy)z™
Tools for reading and writing dependency trees.
The input is assumed to be in Malt-TAB format
(https://stp.lingfil.uu.se/~nivre/research/MaltXML.html).
é    N)Údefaultdict)Úchain)Úpformat)Úfind_binary)ÚTreec                   óÔ   — e Zd ZdZ	 	 	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Ze	 dd„«       Zd„ Zd„ Zd„ Z	 	 	 	 dd„Zd d„Zd„ Zd„ Zd!d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)"ÚDependencyGraphzQ
    A container for the nodes and labelled edges of a dependency structure.
    Nc                 óª   — t        d„ «      | _        | j                  d   j                  ddddœ«       d| _        |r| j	                  |||||¬«       yy)a¬  Dependency graph.

        We place a dummy `TOP` node with the index 0, since the root node is
        often assigned 0 as its head. This also means that the indexing of the
        nodes corresponds directly to the Malt-TAB format, which starts at 1.

        If zero-based is True, then Malt-TAB-like input with node numbers
        starting at 0 and the root node assigned -1 (as produced by, e.g.,
        zpar).

        :param str cell_separator: the cell separator. If not provided, cells
            are split by whitespace.

        :param str top_relation_label: the label by which the top relation is
            identified, for examlple, `ROOT`, `null` or `TOP`.
        c            
      ó4   — d d d d d d d t        t        «      d dœ	S )N)	ÚaddressÚwordÚlemmaÚctagÚtagÚfeatsÚheadÚdepsÚrel)r   Úlist© ó    úo/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/parse/dependencygraph.pyú<lambda>z*DependencyGraph.__init__.<locals>.<lambda>=   s)   € ØØØØØØØÜ#¤DÓ)Øñ
€ r   r   ÚTOP)r   r   r   N)Úcell_extractorÚ
zero_basedÚcell_separatorÚtop_relation_label)r   ÚnodesÚupdateÚrootÚ_parse)ÚselfÚtree_strr   r   r   r   s         r   Ú__init__zDependencyGraph.__init__$   sc   € ô0 !ñ
ó
ˆŒ
ð 	�
‰
�1‰×Ñ e°EÀaÑHÔIàˆŒ	áØ�K‰KØØ-Ø%Ø-Ø#5ð õ ð r   c                 ó   — | j                   |= y)zw
        Removes the node with the given address.  References
        to this node in others will still exist.
        N©r   )r#   r   s     r   Úremove_by_addressz!DependencyGraph.remove_by_addressW   s   € ð
 �J‰J�wÑr   c                 ó²   — | j                   j                  «       D ]:  }g }|d   D ])  }||v r|j                  |«       Œ|j                  |«       Œ+ ||d<   Œ< y)zp
        Redirects arcs to any of the nodes in the originals list
        to the redirect node address.
        r   N)r   ÚvaluesÚappend)r#   Ú	originalsÚredirectÚnodeÚnew_depsÚdeps         r   Úredirect_arcszDependencyGraph.redirect_arcs^   sc   € ð
 —J‘J×%Ñ%Ó'ò 	$ˆDØˆHØ˜F‘|ò )�Ø˜)Ñ#Ø—O‘O HÕ-à—O‘O CÕ(ð	)ð
 $ˆD�ŠLñ	$r   c                 ó´   — | j                   |   d   }| j                   |   d   j                  |g «       | j                   |   d   |   j                  |«       y)zw
        Adds an arc from the node specified by head_address to the
        node specified by the mod address.
        r   r   N)r   Ú
setdefaultr+   )r#   Úhead_addressÚmod_addressÚrelations       r   Úadd_arczDependencyGraph.add_arcl   sV   € ð
 —:‘:˜kÑ*¨5Ñ1ˆØ�
‰
�<Ñ  Ñ(×3Ñ3°H¸bÔAØ�
‰
�<Ñ  Ñ(¨Ñ2×9Ñ9¸+ÕFr   c                 ó  — | j                   j                  «       D ]j  }| j                   j                  «       D ]K  }|d   |d   k7  sŒ|d   dk7  sŒ|d   }|d   j                  |g «       |d   |   j                  |d   «       ŒM Œl y)zr
        Fully connects all non-root nodes.  All nodes are set to be dependents
        of the root node.
        r   r   r   r   N)r   r*   r3   r+   )r#   Únode1Únode2r6   s       r   Úconnect_graphzDependencyGraph.connect_graphv   s–   € ð
 —Z‘Z×&Ñ&Ó(ò 	EˆEØŸ™×*Ñ*Ó,ò E�Ø˜Ñ# u¨YÑ'7Ó7¸EÀ%¹LÈEÓ<QØ$ U™|�HØ˜&‘M×,Ñ,¨X°rÔ:Ø˜&‘M (Ñ+×2Ñ2°5¸Ñ3CÕDñ	Eñ	Er   c                 ó    — | j                   |   S )z'Return the node with the given address.r'   ©r#   Únode_addresss     r   Úget_by_addresszDependencyGraph.get_by_addressƒ   s   € à�z‰z˜,Ñ'Ð'r   c                 ó   — || j                   v S )zq
        Returns true if the graph contains a node with the given node
        address, false otherwise.
        r'   r=   s     r   Úcontains_addressz DependencyGraph.contains_address‡   s   € ð
 ˜tŸz™zÐ)Ð)r   c           	      óh  — d}|dz  }|dz  }t        | j                  j                  «       d„ ¬«      D ]w  }|dj                  |d   |d   |d   «      z  }|d	   j	                  «       D ]@  \  }}|D ]6  }|�|d
j                  |d   ||«      z  }Œ|dj                  |d   |«      z  }Œ8 ŒB Œy |dz  }|S )a  Return a dot representation suitable for using with Graphviz.

        >>> dg = DependencyGraph(
        ...     'John N 2\n'
        ...     'loves V 0\n'
        ...     'Mary N 2'
        ... )
        >>> print(dg.to_dot())
        digraph G{
        edge [dir=forward]
        node [shape=plaintext]
        <BLANKLINE>
        0 [label="0 (None)"]
        0 -> 2 [label="ROOT"]
        1 [label="1 (John)"]
        2 [label="2 (loves)"]
        2 -> 1 [label=""]
        2 -> 3 [label=""]
        3 [label="3 (Mary)"]
        }

        zdigraph G{
zedge [dir=forward]
znode [shape=plaintext]
c                 ó   — | d   S ©Nr   r   )Úvs    r   r   z(DependencyGraph.to_dot.<locals>.<lambda>«   s
   € ¸aÀ	¹l€ r   )Úkeyz
{} [label="{} ({})"]r   r   r   z
{} -> {} [label="{}"]z

{} -> {} z
})Úsortedr   r*   ÚformatÚitems)r#   Úsr.   r   r   r0   s         r   Úto_dotzDependencyGraph.to_dotŽ   sø   € ð0 ˆØ	Ð#Ñ#ˆØ	Ð'Ñ'ˆô ˜4Ÿ:™:×,Ñ,Ó.Ñ4JÔKò 	HˆDØÐ)×0Ñ0Ø�Y‘Ø�Y‘Ø�V‘óñ ˆAð
 " &™\×/Ñ/Ó1ò H‘	��TØò H�CØ�ØÐ6×=Ñ=¸dÀ9¹oÈsÐTWÓXÑX™à˜]×1Ñ1°$°y±/À3ÓGÑG™ñ	HñHð	Hð 	
ˆU‰
ˆàˆr   c                 ó8   — | j                  «       }t        |«      S )a�  Show SVG representation of the transducer (IPython magic).
        >>> from nltk.test.setup_fixt import check_binary
        >>> check_binary('dot')
        >>> dg = DependencyGraph(
        ...     'John N 2\n'
        ...     'loves V 0\n'
        ...     'Mary N 2'
        ... )
        >>> dg._repr_svg_().split('\n')[0]
        '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'

        )rK   Údot2img)r#   Ú
dot_strings     r   Ú
_repr_svg_zDependencyGraph._repr_svg_»   s   € ð —[‘[“]ˆ
Ü�zÓ"Ð"r   c                 ó,   — t        | j                  «      S ©N)r   r   ©r#   s    r   Ú__str__zDependencyGraph.__str__Ë   s   € Ü�t—z‘zÓ"Ð"r   c                 ó4   — dt        | j                  «      › d�S )Nz<DependencyGraph with z nodes>)Úlenr   rR   s    r   Ú__repr__zDependencyGraph.__repr__Î   s   € Ø'¬¨D¯J©J«Ð'8¸Ð@Ð@r   c           
      óÂ   — t        | «      5 }|j                  «       j                  d«      D �cg c]  }t        ||||¬«      ‘Œ c}cddd«       S c c}w # 1 sw Y   yxY w)aû  
        :param filename: a name of a file in Malt-TAB format
        :param zero_based: nodes in the input file are numbered starting from 0
            rather than 1 (as produced by, e.g., zpar)
        :param str cell_separator: the cell separator. If not provided, cells
            are split by whitespace.
        :param str top_relation_label: the label by which the top relation is
            identified, for examlple, `ROOT`, `null` or `TOP`.

        :return: a list of DependencyGraphs

        ú

)r   r   r   N)ÚopenÚreadÚsplitr	   )Úfilenamer   r   r   Úinfiler$   s         r   ÚloadzDependencyGraph.loadÑ   sh   € ô  �(‹^ð 		˜vð !'§¡£× 3Ñ 3°FÓ ;öð ô  ØØ)Ø#1Ø'9ö	ò÷		ñ 		ùò÷		ð 		ús   Œ"A®AÁAÁAÁAc                 ó¶   ‡— t        j                  | j                  |   d   j                  «       «      }| j                  |   d   Št	        ˆfd„|D «       «      S )zl
        Returns the number of left children under the node specified
        by the given address.
        r   r   c              3   ó.   •K  — | ]  }|‰k  sŒ	d –— Œ y­w©é   Nr   ©Ú.0ÚcÚindexs     €r   ú	<genexpr>z0DependencyGraph.left_children.<locals>.<genexpr>ó   ó   øè ø€ Ò4˜¨!¨e«)”1Ñ4ùó   ƒ
Ž©r   Úfrom_iterabler   r*   Úsum©r#   Ú
node_indexÚchildrenrf   s      @r   Úleft_childrenzDependencyGraph.left_childrenì   óP   ø€ ô
 ×&Ñ& t§z¡z°*Ñ'=¸fÑ'E×'LÑ'LÓ'NÓOˆØ—
‘
˜:Ñ& yÑ1ˆÜÓ4˜hÔ4Ó4Ð4r   c                 ó¶   ‡— t        j                  | j                  |   d   j                  «       «      }| j                  |   d   Št	        ˆfd„|D «       «      S )zm
        Returns the number of right children under the node specified
        by the given address.
        r   r   c              3   ó.   •K  — | ]  }|‰kD  sŒ	d –— Œ y­wra   r   rc   s     €r   rg   z1DependencyGraph.right_children.<locals>.<genexpr>ü   rh   ri   rj   rm   s      @r   Úright_childrenzDependencyGraph.right_childrenõ   rq   r   c                 óp   — | j                  |d   «      s"| j                  |d      j                  |«       y y rD   )rA   r   r    )r#   r.   s     r   Úadd_nodezDependencyGraph.add_nodeþ   s4   € Ø×$Ñ$ T¨)¡_Ô5Ø�J‰J�t˜I‘Ñ'×.Ñ.¨tÕ4ð 6r   c                 óž  — d„ }d„ }d„ }d„ }	||||	dœ}
t        |t        «      rd„ |j                  d«      D «       }d„ |D «       }d	„ |D «       }d
}t        |d¬«      D ]¾  \  }}|j                  |«      }|€t	        |«      }n|t	        |«      k(  sJ ‚|€	 |
|   }	  |||«      \  }}}}}}}}|dk(  rŒVt        |«      }|r|dz  }| j                  |   j                  ||||||||dœ«       |dk(  r|dk(  r|}| j                  |   d   |   j                  |«       ŒÀ | j                  d   d   |   r4| j                  d   d   |   d   }| j                  |   | _        || _        y
t        j                   d«       y
# t
        $ r }t        dj                  |«      «      |‚d
}~ww xY w# t        t        f$ r  ||«      \  }}}}}}}Y �Œw xY w)a½  Parse a sentence.

        :param extractor: a function that given a tuple of cells returns a
        7-tuple, where the values are ``word, lemma, ctag, tag, feats, head,
        rel``.

        :param str cell_separator: the cell separator. If not provided, cells
        are split by whitespace.

        :param str top_relation_label: the label by which the top relation is
        identified, for examlple, `ROOT`, `null` or `TOP`.

        c                 ó"   — | \  }}}|||||d|dfS ©NÚ r   )Úcellsrf   r   r   r   s        r   Úextract_3_cellsz/DependencyGraph._parse.<locals>.extract_3_cells  s$   € Ø#‰OˆD�#�tØ˜$  c¨3°°D¸"Ð<Ð<r   c                 ó$   — | \  }}}}|||||d||fS ry   r   )r{   rf   r   r   r   r   s         r   Úextract_4_cellsz/DependencyGraph._parse.<locals>.extract_4_cells  s'   € Ø#(Ñ ˆD�#�t˜SØ˜$  c¨3°°D¸#Ð=Ð=r   c                 ó`   — | \  }}}}}}}	 t        |«      }|||||d||fS # t        $ r Y Œw xY wry   ©ÚintÚ
ValueError)	r{   rf   Ú
line_indexr   r   r   Ú_r   r   s	            r   Úextract_7_cellsz/DependencyGraph._parse.<locals>.extract_7_cells   sQ   € Ø9>Ñ6ˆJ˜˜e S¨!¨T°3ðÜ˜J›�ð ˜$  s¨C°°T¸3Ð>Ð>øô ò áðús   Œ! ¡	-¬-c           
      óf   — | \
  }}}}}}}}	}
}
	 t        |«      }||||||||	fS # t        $ r Y Œw xY wrQ   r€   )r{   rf   rƒ   r   r   r   r   r   r   r   r„   s              r   Úextract_10_cellsz0DependencyGraph._parse.<locals>.extract_10_cells)  sW   € ØINÑFˆJ˜˜e T¨3°°t¸SÀ!ÀQðÜ˜J›�ð ˜$  t¨S°%¸¸sÐBÐBøô ò áðús   �$ ¤	0¯0)é   é   é   é
   c              3   ó    K  — | ]  }|–— Œ y ­wrQ   r   )rd   Úlines     r   rg   z)DependencyGraph._parse.<locals>.<genexpr>:  s   è ø€ Ò:˜t”dÑ:ùs   ‚ú
c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wrQ   )Úrstrip©rd   Úls     r   rg   z)DependencyGraph._parse.<locals>.<genexpr><  s   è ø€ Ò, �—‘—Ñ,ùs   ‚c              3   ó&   K  — | ]	  }|sŒ|–— Œ y ­wrQ   r   r‘   s     r   rg   z)DependencyGraph._parse.<locals>.<genexpr>=  s   è ø€ Ò'�q¢Q”Ñ'ùs   ‚ŠNrb   )ÚstartúTNumber of tab-delimited fields ({}) not supported by CoNLL(10) or Malt-Tab(4) formatr„   )r   r   r   r   r   r   r   r   rˆ   r   r   zBThe graph doesn't contain a node that depends on the root element.)Ú
isinstanceÚstrr[   Ú	enumeraterU   ÚKeyErrorr‚   rH   Ú	TypeErrorr�   r   r    r+   r!   r   ÚwarningsÚwarn)r#   Úinput_r   r   r   r   r|   r~   r…   r‡   Ú
extractorsÚlinesÚcell_numberrf   r�   r{   Úer   r   r   r   r   r   r   Úroot_addresss                            r   r"   zDependencyGraph._parse  s9  € ò,	=ò	>ò	?ò	Cð ØØØ ñ	
ˆ
ô �fœcÔ"Ù: v§|¡|°DÓ'9Ô:ˆFá, VÔ,ˆÙ'˜EÔ'ˆàˆÜ$ U°!Ô4ò 1	8‰KˆE�4Ø—J‘J˜~Ó.ˆEØÐ"Ü! %›j‘à"¤c¨%£jÒ0Ð0Ð0àÐ%ðØ%/°Ñ%<�NðQÙBPØ˜5óCÑ?��t˜U D¨#¨u°d¸Cð �sŠ{Øä�t“9ˆDÙØ˜‘	�à�J‰J�uÑ×$Ñ$à$Ø Ø"Ø ØØ"Ø Øñ	ôð ˜qÒ  t¨q¢yØ(�Ø�J‰J�tÑ˜VÑ$ SÑ)×0Ñ0°Õ7ðc1	8ðf �:‰:�a‰=˜Ñ Ð!3Ò4ØŸ:™: a™=¨Ñ0Ð1CÑDÀQÑGˆLØŸ
™
 <Ñ0ˆDŒIØ&8ˆDÕ#ä�M‰MØWõøô]  ò Ü$ð:ß:@¹&ÀÓ:Móð ðûðûô œzÐ*ò Qñ <JÈ%Ó;PÑ8��e˜T 3¨¨t³Sð	Qús*   ÂE=ÂF)Å=	F&ÆF!Æ!F&Æ)GÇGc                 ó"   — |d   }|r|dk7  r|S |S )Nr   ú,r   )r#   r.   ÚfilterÚws       r   Ú_wordzDependencyGraph._word|  s   € Ø�‰LˆÙØ�CŠxØ�Øˆr   c           	      óð   — | j                  |«      }|d   }t        t        j                  |d   j	                  «       «      «      }|r)t        ||D �cg c]  }| j                  |«      ‘Œ c}«      S |S c c}w )z¥Turn dependency graphs into NLTK trees.

        :param int i: index of a node
        :return: either a word (if the indexed node is a leaf) or a ``Tree``.
        r   r   )r?   rG   r   rk   r*   r   Ú_tree)r#   Úir.   r   r   r0   s         r   r©   zDependencyGraph._treeƒ  sm   € ð ×"Ñ" 1Ó%ˆØ�F‰|ˆÜ”e×)Ñ)¨$¨v©,×*=Ñ*=Ó*?Ó@ÓAˆáÜ˜¸$Ö?°3˜tŸz™z¨#�Ò?Ó@Ð@àˆKùò @s   ÁA3
c           	      óÞ   — | j                   }|d   }t        t        j                  |d   j	                  «       «      «      }t        ||D �cg c]  }| j                  |«      ‘Œ c}«      S c c}w )z–
        Starting with the ``root`` node, build a dependency tree using the NLTK
        ``Tree`` constructor. Dependency labels are omitted.
        r   r   )r!   rG   r   rk   r*   r   r©   )r#   r.   r   r   r0   s        r   ÚtreezDependencyGraph.tree’  s[   € ð
 �y‰yˆà�F‰|ˆÜ”e×)Ñ)¨$¨v©,×*=Ñ*=Ó*?Ó@ÓAˆÜ�D°dÖ;¨s˜4Ÿ:™: c�?Ò;Ó<Ð<ùÒ;s   ÁA*
c              #   ó"  K  — |s| j                   }|d   |d   f}t        t        j                  |d   j	                  «       «      «      D ]?  }| j                  |«      }||d   |d   |d   ff–— | j                  |¬«      E d{  –—†  ŒA y7 Œ­w)zs
        Extract dependency triples of the form:
        ((head word, head tag), rel, (dep word, dep tag))
        r   r   r   r   )r.   N)r!   rG   r   rk   r*   r?   Útriples)r#   r.   r   rª   r0   s        r   r®   zDependencyGraph.triples�  s™   è ø€ ñ Ø—9‘9ˆDà�V‘˜d 6™lÐ+ˆÜœ×+Ñ+¨D°©L×,?Ñ,?Ó,AÓBÓCò 	.ˆAØ×%Ñ% aÓ(ˆCØ˜˜U™ c¨&¡k°3°v±;Ð%?Ð@Ò@Ø—|‘|¨�|Ó-×-Ñ-ñ	.ð .ús   ‚BBÂBÂBc                 óF   — 	 | j                   |   d   S # t        $ r Y y w xY w)Nr   ©r   Ú
IndexError©r#   rª   s     r   Ú_hdzDependencyGraph._hd¬  s,   € ð	Ø—:‘:˜a‘= Ñ(Ð(øÜò 	Ùð	úó   ‚ ”	 Ÿ c                 óF   — 	 | j                   |   d   S # t        $ r Y y w xY w)Nr   r°   r²   s     r   Ú_relzDependencyGraph._rel²  s,   € ð	Ø—:‘:˜a‘= Ñ'Ð'øÜò 	Ùð	úr´   c                 ó®  — i }| j                   j                  «       D ]!  }|d   D ]  }t        |d   |g«      }d||<   Œ Œ# | j                   D ]†  }i }|D ]6  }|D ]/  }|d   |d   k(  sŒt        |d   |d   g«      }||   ||   z   ||<   Œ1 Œ8 |D ]B  }	||	   ||	<   |	d   |	d   k(  sŒ| j                  | j	                  |	d   «      |	d   «      }
|
c c S  Œˆ y)aE  Check whether there are cycles.

        >>> dg = DependencyGraph(treebank_data)
        >>> dg.contains_cycle()
        False

        >>> cyclic_dg = DependencyGraph()
        >>> top = {'word': None, 'deps': [1], 'rel': 'TOP', 'address': 0}
        >>> child1 = {'word': None, 'deps': [2], 'rel': 'NTOP', 'address': 1}
        >>> child2 = {'word': None, 'deps': [4], 'rel': 'NTOP', 'address': 2}
        >>> child3 = {'word': None, 'deps': [1], 'rel': 'NTOP', 'address': 3}
        >>> child4 = {'word': None, 'deps': [3], 'rel': 'NTOP', 'address': 4}
        >>> cyclic_dg.nodes = {
        ...     0: top,
        ...     1: child1,
        ...     2: child2,
        ...     3: child3,
        ...     4: child4,
        ... }
        >>> cyclic_dg.root = top

        >>> cyclic_dg.contains_cycle()
        [1, 2, 4, 3]

        r   r   rb   r   F)r   r*   ÚtupleÚget_cycle_pathr?   )r#   Ú	distancesr.   r0   rF   r„   Únew_entriesÚpair1Úpair2ÚpairÚpaths              r   Úcontains_cyclezDependencyGraph.contains_cycle¹  s/  € ð4 ˆ	à—J‘J×%Ñ%Ó'ò 	#ˆDØ˜F‘|ò #�Ü˜T )™_¨cÐ2Ó3�Ø!"�	˜#’ñ#ð	#ð
 —‘ò 	 ˆAØˆKà"ò O�Ø&ò O�EØ˜Q‘x 5¨¡8Ó+Ü# U¨1¡X¨u°Q©xÐ$8Ó9˜Ø+4°UÑ+;¸iÈÑ>NÑ+N˜ CÒ(ñOðOð $ò  �Ø"-¨dÑ"3�	˜$‘Ø˜‘7˜d 1™gÓ%Ø×.Ñ.¨t×/BÑ/BÀ4ÈÁ7Ó/KÈTÐRSÉWÓU�DØ”Kñ	 ð	 ð r   c                 óØ   — |d   D ]  }||k(  sŒ	|d   gc S  |d   D ]J  }| j                  | j                  |«      |«      }t        |«      dkD  sŒ3|j                  d|d   «       |c S  g S )Nr   r   r   )r¹   r?   rU   Úinsert)r#   Ú	curr_nodeÚgoal_node_indexr0   r¿   s        r   r¹   zDependencyGraph.get_cycle_pathë  s‰   € Ø˜VÑ$ò 	.ˆCØ�oÓ%Ø! )Ñ,Ð-Ò-ð	.ð ˜VÑ$ò 	ˆCØ×&Ñ& t×':Ñ':¸3Ó'?ÀÓQˆDÜ�4‹y˜1‹}Ø—‘˜A˜y¨Ñ3Ô4Ø’ð		ð
 ˆ	r   c                 óÞ   ‡— |dk(  rdŠn*|dk(  rdŠn"|dk(  rdŠnt        dj                  |«      «      ‚dj                  ˆfd	„t        | j                  j                  «       «      D «       «      S )
z®
        The dependency graph in CoNLL format.

        :param style: the style to use for the format (3, 4, 10 columns)
        :type style: int
        :rtype: str
        rˆ   z{word}	{tag}	{head}
r‰   z{word}	{tag}	{head}	{rel}
r‹   z9{i}	{word}	{lemma}	{ctag}	{tag}	{feats}	{head}	{rel}	_	_
r•   rz   c              3   ó\   •K  — | ]#  \  }}|d    dk7  r ‰j                   dd|i|¤Ž–— Œ% y­w)r   r   rª   Nr   )rH   )rd   rª   r.   Útemplates      €r   rg   z+DependencyGraph.to_conll.<locals>.<genexpr>  s<   øè ø€ ò 
á��4Ø�E‰{˜eÒ#ð ˆH�O‰OÑ(˜aÐ( 4Õ(ñ
ùs   ƒ),)r‚   rH   ÚjoinrG   r   rI   )r#   ÚstylerÇ   s     @r   Úto_conllzDependencyGraph.to_conllö  s{   ø€ ð �AŠ:Ø0‰HØ�aŠZØ7‰HØ�bŠ[àUñ ô ð2ß28±&¸³-óð ð
 �w‰wó 
ä! $§*¡*×"2Ñ"2Ó"4Ó5ô
ó 
ð 	
r   c                 óª  — ddl }t        t        dt        | j                  «      «      «      }|D �cg c]7  }| j                  |«      sŒ|| j                  |«      | j                  |«      f‘Œ9 }}i | _        |D ]!  }| j                  |   d   | j                  |<   Œ# |j                  «       }|j                  |«       |j                  |«       |S c c}w )zJConvert the data in a ``nodelist`` into a networkx labeled directed graph.r   Nrb   r   )Únetworkxr   ÚrangerU   r   r³   r¶   Ú	nx_labelsÚMultiDiGraphÚadd_nodes_fromÚadd_edges_from)r#   rÌ   Únx_nodelistÚnÚnx_edgelistÚgs         r   Únx_graphzDependencyGraph.nx_graph  sÂ   € ãäœ5 ¤C¨¯
©
£OÓ4Ó5ˆà4?ö
Ø/0À4Ç8Á8ÈAÅ;ˆQ�—‘˜“˜TŸY™Y q›\Ò*ð
ˆð 
ð ˆŒØò 	6ˆAØ $§
¡
¨1¡¨fÑ 5ˆD�N‰N˜1Òð	6ð ×!Ñ!Ó#ˆØ	×Ñ˜Ô%Ø	×Ñ˜Ô%àˆùò
s   ±CÁ%C)NNFNÚROOT)FNr×   )NFNr×   )TrQ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r(   r1   r7   r;   r?   rA   rK   rO   rS   rV   Ústaticmethodr^   rp   rt   rv   r"   r§   r©   r¬   r®   r³   r¶   rÀ   r¹   rÊ   rÖ   r   r   r   r	   r	      sÂ   „ ñð ØØØØ!ó1òf ò$òGò
Eò(ò*ò+òZ#ò #òAð àLRòó ðò45ò5ò5ð ØØØ!óxótòò	=ó.òòò0òd	ò
ó:r   r	   c                 óP  — 	 t        d«       	 |dv rt        j                  dd|z  gd| d¬«      }n't        j                  dd|z  gt        | d¬«      ¬«      }|j                  S # t
        $ r t        d	j                  | «      «      ‚w xY w# t        $ r}t        d
«      |‚d}~ww xY w)a­  
    Create image representation fom dot_string, using the 'dot' program
    from the Graphviz package.

    Use the 't' argument to specify the image file format, for ex. 'jpeg', 'eps',
    'json', 'png' or 'webp' (Running 'dot -T:' lists all available formats).

    Note that the "capture_output" option of subprocess.run() is only available
    with text formats (like svg), but not with binary image formats (like png).
    Údot)rÞ   Údot_jsonÚjsonÚsvgz-T%sT)Úcapture_outputÚinputÚtextÚutf8)Úencoding)rã   zACannot create image representation by running dot from string: {}z0Cannot find the dot binary from Graphviz packageN)r   Ú
subprocessÚrunÚbytesÚstdoutÚ	ExceptionrH   ÚOSError)rN   ÚtÚprocr¡   s       r   rM   rM   &  sÀ   € ðSÜ�EÔð	ØÐ6Ñ6Ü!—~‘~Ø˜F Q™JÐ'Ø#'Ø$Øô	‘ô "—~‘~Ø˜F Q™JÐ'Ü 
°VÔ<ô�ð —;‘;ÐøÜò 	Üðß‘6˜*Ó%óð ð	ûô
 ò SÜÐJÓKÐQRÐRûðSús)   ‚B ŽAA$ Á$$BÂB Â	B%ÂB Â B%c                   ó   — e Zd ZdZy)ÚDependencyGraphErrorzDependency graph exception.N)rØ   rÙ   rÚ   rÛ   r   r   r   rð   rð   K  s   „ Ú%r   rð   c                  óT   — t        «        t        «        t        «        t        «        y rQ   )Ú	malt_demoÚ
conll_demoÚconll_file_demoÚcycle_finding_demor   r   r   Údemorö   O  s   € Ü„KÜ„LÜÔÜÕr   c                 óÂ  — t        d«      }|j                  «       }|j                  «        | r²ddl}ddlm} |j                  «       }|j                  «        |j                  |d¬«      }|j                  ||d¬«       |j                  |||j                  «       |j                  g «       |j                  g «       |j                  d	«       |j                  «        yy)
zw
    A demonstration of the result of reading a dependency
    version of the first sentence of the Penn Treebank.
    á  Pierre  NNP     2       NMOD
Vinken  NNP     8       SUB
,       ,       2       P
61      CD      5       NMOD
years   NNS     6       AMOD
old     JJ      2       NMOD
,       ,       2       P
will    MD      0       ROOT
join    VB      8       VC
the     DT      11      NMOD
board   NN      9       OBJ
as      IN      9       VMOD
a       DT      15      NMOD
nonexecutive    JJ      15      NMOD
director        NN      12      PMOD
Nov.    NNP     9       VMOD
29      CD      16      NMOD
.       .       9       VMOD
r   N)Úpylabrb   )Údimé2   )Ú	node_sizeztree.png)r	   r¬   ÚpprintrÌ   Ú
matplotlibrù   rÖ   ÚinfoÚspring_layoutÚdraw_networkx_nodesÚdraw_networkx_labelsrÎ   ÚxticksÚyticksÚsavefigÚshow)ÚnxÚdgr¬   rÌ   rù   rÕ   Úposs          r   rò   rò   V  s¸   € ô
 
ð	ó
€Bð* �7‰7‹9€DØ‡K�K„MÙ	ãÝ$à�K‰K‹MˆØ	�‰ŒØ×$Ñ$ Q¨AÐ$Ó.ˆØ×$Ñ$ Q¨°rÐ$Ô:à×%Ñ% a¨¨b¯l©lÔ;Ø�‰�RÔØ�‰�RÔØ�‰�jÔ!Ø�
‰
�ð 
r   c                  ó¬   — t        t        «      } | j                  «       }|j                  «        t	        | «       t	        | j                  d«      «       y)zg
    A demonstration of how to read a string representation of
    a CoNLL format dependency tree.
    r‰   N)r	   Úconll_data1r¬   rý   ÚprintrÊ   )r  r¬   s     r   ró   ró   ƒ  s9   € ô
 
œÓ	%€BØ�7‰7‹9€DØ‡K�K„MÜ	ˆ"„IÜ	ˆ"�+‰+�a‹.Õr   c                  óä   — t        d«       t        j                  d«      D � cg c]  } | sŒt        | «      ‘Œ }} |D ]-  }|j	                  «       }t        d«       |j                  «        Œ/ y c c} w )NzMass conll_read demo...rX   rŽ   )r  Úconll_data2r[   r	   r¬   rý   )ÚentryÚgraphsÚgraphr¬   s       r   rô   rô   �  s`   € Ü	Ð
#Ô$Ü2=×2CÑ2CÀFÓ2KÖU¨ÊuŒo˜eÕ$ÐU€FÐUØò ˆØ�z‰z‹|ˆÜˆdŒØ�‰�ñùò Vs
   £A-«A-c                  ó€  — t        t        «      } t        | j                  «       «       t        «       }|j	                  d dgdddœ«       |j	                  d dgdddœ«       |j	                  d dgdddœ«       |j	                  d dgdddœ«       |j	                  d dgdddœ«       t        |j                  «       «       y )	Nrb   r   r   )r   r   r   r   é   ÚNTOPr‰   rˆ   )r	   Útreebank_datar  rÀ   rv   )r  Ú	cyclic_dgs     r   rõ   rõ   ˜  s³   € Ü	œÓ	'€BÜ	ˆ"×
Ñ
Ó
ÔÜÓ!€IØ×Ñ ¨q¨c¸%ÈAÑNÔOØ×Ñ ¨q¨c¸&ÈQÑOÔPØ×Ñ ¨q¨c¸&ÈQÑOÔPØ×Ñ ¨q¨c¸&ÈQÑOÔPØ×Ñ ¨q¨c¸&ÈQÑOÔPÜ	ˆ)×
"Ñ
"Ó
$Õ%r   rø   a/  
1   Ze                ze                Pron  Pron  per|3|evofmv|nom                 2   su      _  _
2   had               heb               V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   met               met               Prep  Prep  voor                             8   mod     _  _
4   haar              haar              Pron  Pron  bez|3|ev|neut|attr               5   det     _  _
5   moeder            moeder            N     N     soort|ev|neut                    3   obj1    _  _
6   kunnen            kan               V     V     hulp|ott|1of2of3|mv              2   vc      _  _
7   gaan              ga                V     V     hulp|inf                         6   vc      _  _
8   winkelen          winkel            V     V     intrans|inf                      11  cnj     _  _
9   ,                 ,                 Punc  Punc  komma                            8   punct   _  _
10  zwemmen           zwem              V     V     intrans|inf                      11  cnj     _  _
11  of                of                Conj  Conj  neven                            7   vc      _  _
12  terrassen         terras            N     N     soort|mv|neut                    11  cnj     _  _
13  .                 .                 Punc  Punc  punt                             12  punct   _  _
a  1   Cathy             Cathy             N     N     eigen|ev|neut                    2   su      _  _
2   zag               zie               V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   hen               hen               Pron  Pron  per|3|mv|datofacc                2   obj1    _  _
4   wild              wild              Adj   Adj   attr|stell|onverv                5   mod     _  _
5   zwaaien           zwaai             N     N     soort|mv|neut                    2   vc      _  _
6   .                 .                 Punc  Punc  punt                             5   punct   _  _

1   Ze                ze                Pron  Pron  per|3|evofmv|nom                 2   su      _  _
2   had               heb               V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   met               met               Prep  Prep  voor                             8   mod     _  _
4   haar              haar              Pron  Pron  bez|3|ev|neut|attr               5   det     _  _
5   moeder            moeder            N     N     soort|ev|neut                    3   obj1    _  _
6   kunnen            kan               V     V     hulp|ott|1of2of3|mv              2   vc      _  _
7   gaan              ga                V     V     hulp|inf                         6   vc      _  _
8   winkelen          winkel            V     V     intrans|inf                      11  cnj     _  _
9   ,                 ,                 Punc  Punc  komma                            8   punct   _  _
10  zwemmen           zwem              V     V     intrans|inf                      11  cnj     _  _
11  of                of                Conj  Conj  neven                            7   vc      _  _
12  terrassen         terras            N     N     soort|mv|neut                    11  cnj     _  _
13  .                 .                 Punc  Punc  punt                             12  punct   _  _

1   Dat               dat               Pron  Pron  aanw|neut|attr                   2   det     _  _
2   werkwoord         werkwoord         N     N     soort|ev|neut                    6   obj1    _  _
3   had               heb               V     V     hulp|ovt|1of2of3|ev              0   ROOT    _  _
4   ze                ze                Pron  Pron  per|3|evofmv|nom                 6   su      _  _
5   zelf              zelf              Pron  Pron  aanw|neut|attr|wzelf             3   predm   _  _
6   uitgevonden       vind              V     V     trans|verldw|onverv              3   vc      _  _
7   .                 .                 Punc  Punc  punt                             6   punct   _  _

1   Het               het               Pron  Pron  onbep|neut|zelfst                2   su      _  _
2   hoorde            hoor              V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   bij               bij               Prep  Prep  voor                             2   ld      _  _
4   de                de                Art   Art   bep|zijdofmv|neut                6   det     _  _
5   warme             warm              Adj   Adj   attr|stell|vervneut              6   mod     _  _
6   zomerdag          zomerdag          N     N     soort|ev|neut                    3   obj1    _  _
7   die               die               Pron  Pron  betr|neut|zelfst                 6   mod     _  _
8   ze                ze                Pron  Pron  per|3|evofmv|nom                 12  su      _  _
9   ginds             ginds             Adv   Adv   gew|aanw                         12  mod     _  _
10  achter            achter            Adv   Adv   gew|geenfunc|stell|onverv        12  svp     _  _
11  had               heb               V     V     hulp|ovt|1of2of3|ev              7   body    _  _
12  gelaten           laat              V     V     trans|verldw|onverv              11  vc      _  _
13  .                 .                 Punc  Punc  punt                             12  punct   _  _

1   Ze                ze                Pron  Pron  per|3|evofmv|nom                 2   su      _  _
2   hadden            heb               V     V     trans|ovt|1of2of3|mv             0   ROOT    _  _
3   languit           languit           Adv   Adv   gew|geenfunc|stell|onverv        11  mod     _  _
4   naast             naast             Prep  Prep  voor                             11  mod     _  _
5   elkaar            elkaar            Pron  Pron  rec|neut                         4   obj1    _  _
6   op                op                Prep  Prep  voor                             11  ld      _  _
7   de                de                Art   Art   bep|zijdofmv|neut                8   det     _  _
8   strandstoelen     strandstoel       N     N     soort|mv|neut                    6   obj1    _  _
9   kunnen            kan               V     V     hulp|inf                         2   vc      _  _
10  gaan              ga                V     V     hulp|inf                         9   vc      _  _
11  liggen            lig               V     V     intrans|inf                      10  vc      _  _
12  .                 .                 Punc  Punc  punt                             11  punct   _  _

1   Zij               zij               Pron  Pron  per|3|evofmv|nom                 2   su      _  _
2   zou               zal               V     V     hulp|ovt|1of2of3|ev              7   cnj     _  _
3   mams              mams              N     N     soort|ev|neut                    4   det     _  _
4   rug               rug               N     N     soort|ev|neut                    5   obj1    _  _
5   ingewreven        wrijf             V     V     trans|verldw|onverv              6   vc      _  _
6   hebben            heb               V     V     hulp|inf                         2   vc      _  _
7   en                en                Conj  Conj  neven                            0   ROOT    _  _
8   mam               mam               V     V     trans|ovt|1of2of3|ev             7   cnj     _  _
9   de                de                Art   Art   bep|zijdofmv|neut                10  det     _  _
10  hare              hare              Pron  Pron  bez|3|ev|neut|attr               8   obj1    _  _
11  .                 .                 Punc  Punc  punt                             10  punct   _  _

1   Of                of                Conj  Conj  onder|metfin                     0   ROOT    _  _
2   ze                ze                Pron  Pron  per|3|evofmv|nom                 3   su      _  _
3   had               heb               V     V     hulp|ovt|1of2of3|ev              0   ROOT    _  _
4   gewoon            gewoon            Adj   Adj   adv|stell|onverv                 10  mod     _  _
5   met               met               Prep  Prep  voor                             10  mod     _  _
6   haar              haar              Pron  Pron  bez|3|ev|neut|attr               7   det     _  _
7   vriendinnen       vriendin          N     N     soort|mv|neut                    5   obj1    _  _
8   rond              rond              Adv   Adv   deelv                            10  svp     _  _
9   kunnen            kan               V     V     hulp|inf                         3   vc      _  _
10  slenteren         slenter           V     V     intrans|inf                      9   vc      _  _
11  in                in                Prep  Prep  voor                             10  mod     _  _
12  de                de                Art   Art   bep|zijdofmv|neut                13  det     _  _
13  buurt             buurt             N     N     soort|ev|neut                    11  obj1    _  _
14  van               van               Prep  Prep  voor                             13  mod     _  _
15  Trafalgar_Square  Trafalgar_Square  MWU   N_N   eigen|ev|neut_eigen|ev|neut      14  obj1    _  _
16  .                 .                 Punc  Punc  punt                             15  punct   _  _
Ú__main__)rá   )F)rÛ   rç   r›   Úcollectionsr   Ú	itertoolsr   rý   r   Únltk.internalsr   Ú	nltk.treer   r	   rM   rë   rð   rö   rò   ró   rô   rõ   r  r  r  rØ   r   r   r   ú<module>r     s†   ðñó Û Ý #Ý Ý å &Ý ÷Dñ DóN"SôJ&˜9ô &òó*òZ	òò	&ð€ð(€ð T€ðl ˆzÒÙ…Fð r   