+
    ÖÇÜhµ{  ã                   óØ   € R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt  ! R R4      tRR	 lt ! R
 R]4      tR tRR ltR tR tR tRtRtRt]R8X  d
   ]! 4        R# R# )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                   óÞ   a € ] tR t^t o RtRR ltR tR tR tR t	R t
R	 tR
 tR tR tR t]RR l4       tR tR tR tR R ltR!R ltR tR tR"R ltR tR tR tR tR tR tRt V t!R# )#ÚDependencyGraphzI
A container for the nodes and labelled edges of a dependency structure.
Nc                óÆ   € \        R 4      V n        V P                  ^ ,          P                  RRRRR^ /4       RV n        V'       d   V P	                  VVVVVR7       R# R# )aT  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                  óD   € R RRRRRRRRRRRRRR\        \        4      R	R/	# )
ÚaddressNÚwordÚlemmaÚctagÚtagÚfeatsÚheadÚdepsÚrel)r   Úlist© ó    Ú</usr/lib/python3/dist-packages/nltk/parse/dependencygraph.pyÚ<lambda>Ú*DependencyGraph.__init__.<locals>.<lambda>=   s9   € Ø˜4Ø˜Ø˜Ø˜Ø�tØ˜Ø˜Øœ¤DÓ)Ø�tñ
r   r   ÚTOPr   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__ÚDependencyGraph.__init__$   si   € ô0 !ñ
ó
ˆŒ
ð 	�
‰
�1�×Ñ˜f e¨U°E¸9ÀaÐHÔIàˆŒ	çØ�K‰KØØ-Ø%Ø-Ø#5ð ö ñ r   c                ó    € V P                   V R# )z_
Removes the node with the given address.  References
to this node in others will still exist.
N©r   )r#   r   s   &&r   Úremove_by_addressÚ!DependencyGraph.remove_by_addressW   s   € ð
 �J‰J�wÒr   c                óÈ   € V P                   P                  4        FC  p. pVR,           F-  pWQ9   d   VP                  V4       K  VP                  V4       K/  	  WCR&   KE  	  R# )zX
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_arcsÚDependencyGraph.redirect_arcs^   sW   € ð
 —J‘J×%Ñ%Ö'ˆDØˆHØ˜F—|�|�ØÔ#Ø—O‘O HÖ-à—O‘O CÖ(ñ	 $ð
 $�‹Ló (r   c                óî   € V P                   V,          R,          pV P                   V,          R,          P                  V. 4       V P                   V,          R,          V,          P                  V4       R# )z_
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_arcÚDependencyGraph.add_arcl   sV   € ð
 —:‘:˜kÕ*¨5Õ1ˆØ�
‰
�<Õ  Õ(×3Ñ3°H¸bÔAØ�
‰
�<Õ  Õ(¨Õ2×9Ñ9¸+ÖFr   c                óh  € V P                   P                  4        F“  pV P                   P                  4        Fr  pVR,          VR,          8w  g   K  VR,          R8w  g   K*  VR,          pVR,          P                  V. 4       VR,          V,          P                  VR,          4       Kt  	  K•  	  R# )zZ
Fully connects all non-root nodes.  All nodes are set to be dependents
of the root node.
r   r   r   r   N)r   r,   r6   r-   )r#   Únode1Únode2r9   s   &   r   Úconnect_graphÚDependencyGraph.connect_graphv   sˆ   € ð
 —Z‘Z×&Ñ&Ö(ˆEØŸ™×*Ñ*Ö,�Ø˜Õ# u¨YÕ'7Ö7¸EÀ%½LÈEÖ<QØ$ U�|�HØ˜&•M×,Ñ,¨X°rÔ:Ø˜&•M (Õ+×2Ñ2°5¸Õ3CÖDó	 -ó )r   c                ó(   € V P                   V,          # )z'Return the node with the given address.r(   ©r#   Únode_addresss   &&r   Úget_by_addressÚDependencyGraph.get_by_addressƒ   s   € à�z‰z˜,Õ'Ð'r   c                ó   € WP                   9   # )zY
Returns true if the graph contains a node with the given node
address, false otherwise.
r(   rB   s   &&r   Úcontains_addressÚ DependencyGraph.contains_address‡   s   € ð
 Ÿz™zÑ)Ð)r   c           	     óÖ  € RpVR,          pVR,          p\        V P                  P                  4       R R7       F¡  pVRP                  VR,          VR,          VR,          4      ,          pVR	,          P	                  4        FT  w  r4V FI  pVe#   VR
P                  VR,          WS4      ,          pK)  VRP                  VR,          V4      ,          pKK  	  KV  	  K£  	  VR,          pV# )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                 ó   € V R ,          # )r   r   )Úvs   &r   r   Ú(DependencyGraph.to_dot.<locals>.<lambda>«   s   € ¸aÀ	¾lr   )Úkeyz
{} [label="{} ({})"]r   r   r   z
{} -> {} [label="{}"]z

{} -> {} z
})Úsortedr   r,   ÚformatÚitems)r#   Úsr0   r   r   r2   s   &     r   Úto_dotÚDependencyGraph.to_dotŽ   sß   € ð0 ˆØ	Ð#Õ#ˆØ	Ð'Õ'ˆô ˜4Ÿ:™:×,Ñ,Ó.Ñ4J×KˆDØÐ)×0Ñ0Ø�Y•Ø�Y•Ø�V•óõ ˆAð
 " &�\×/Ñ/Ö1‘	�Û�CØ’ØÐ6×=Ñ=¸dÀ9½oÈsÓXÕXšà˜]×1Ñ1°$°yµ/À3ÓGÕGšó	  ó 2ñ Lð 	
ˆU�
ˆàˆr   c                ó8   € V P                  4       p\        V4      # )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"?>'

)rR   Údot2img)r#   Ú
dot_strings   & r   Ú
_repr_svg_ÚDependencyGraph._repr_svg_»   s   € ð —[‘[“]ˆ
Ü�zÓ"Ð"r   c                ó,   € \        V P                  4      # ©N)r   r   ©r#   s   &r   Ú__str__ÚDependencyGraph.__str__Ë   s   € Ü�t—z‘zÓ"Ð"r   c                ó4   € R \        V P                  4       R2# )z<DependencyGraph with z nodes>)Úlenr   r[   s   &r   Ú__repr__ÚDependencyGraph.__repr__Î   s   € Ø'¬¨D¯J©J«Ð'8¸Ð@Ð@r   c                óè   € \        V 4      ;_uu_ 4       pVP                  4       P                  R4       Uu. uF  p\        VVVVR7      NK  	  upuuRRR4       # u upi   + '       g   i     R# ; i)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   ÚloadÚDependencyGraph.loadÑ   sh   € ô  �(�^Œ^˜vð !'§¡£× 3Ñ 3°FÔ ;óñ !<�Hô  ØØ)Ø#1Ø'9÷	ñ !<ñ÷ Š^ùò÷ �^ˆ^ús   ”"A ¶AÁA ÁA Á A1	c                óÚ   a€ \         P                  ! V P                  V,          R,          P                  4       4      pV P                  V,          R,          o\	        V3R lV 4       4      # )zT
Returns the number of left children under the node specified
by the given address.
r   r   c              3   ó8   <"  € T F  qS8  g   K  ^x € K  	  R# 5i©é   Nr   ©Ú.0ÚcÚindexs   & €r   Ú	<genexpr>Ú0DependencyGraph.left_children.<locals>.<genexpr>ó   ó   øé € Ð4™h˜¨e©)—1’1›hùó   ƒ�
©r   Úfrom_iterabler   r,   Úsum©r#   Ú
node_indexÚchildrenrr   s   && @r   Úleft_childrenÚDependencyGraph.left_childrenì   óP   ø€ ô
 ×&Ò& t§z¡z°*Õ'=¸fÕ'E×'LÑ'LÓ'NÓOˆØ—
‘
˜:Õ& yÕ1ˆÜÔ4™hÓ4Ó4Ð4r   c                óÚ   a€ \         P                  ! V P                  V,          R,          P                  4       4      pV P                  V,          R,          o\	        V3R lV 4       4      # )zU
Returns the number of right children under the node specified
by the given address.
r   r   c              3   ó8   <"  € T F  qS8”  g   K  ^x € K  	  R# 5irm   r   ro   s   & €r   rs   Ú1DependencyGraph.right_children.<locals>.<genexpr>ü   ru   rv   rw   rz   s   && @r   Úright_childrenÚDependencyGraph.right_childrenõ   r   r   c                ó˜   € V P                  VR ,          4      '       g,   V P                  VR ,          ,          P                  V4       R# R# )r   N)rG   r   r    )r#   r0   s   &&r   Úadd_nodeÚDependencyGraph.add_nodeþ   s7   € Ø×$Ñ$ T¨)¥_×5Ò5Ø�J‰J�t˜I•Õ'×.Ñ.¨tÖ4ñ 6r   c                ój  € R pR pR pR p	^V^V^V^
V	/p
\        V\        4      '       d   R VP                  R4       4       pR V 4       pR V 4       pR	p\        V^R
7       Fî  w  rÞVP                  V4      pVf   \	        V4      pMV\	        V4      8X  g   Q hVf
    W¬,          p V! Wý4      w  ppppppppVR8X  d   K`  \        V4      pV'       d
   V^,          pV P                  V,          P                  RVRVRVRVRVRVRVRV/4       V^8X  d
   V^ 8X  d   TpV P                  V,          R,          V,          P                  V4       Kð  	  V P                  ^ ,          R,          V,          '       dI   V P                  ^ ,          R,          V,          ^ ,          pV P                  V,          V n        WPn        R	# \        P                   ! R4       R	#   \
         d!   p\        RP                  T4      4      ThR	p?ii ; i  \        \        3 d    T! T4      w  ppppppp ELti ; i)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                 ó   € V w  r#pWW#VR VR 3# ©Ú r   )Úcellsrr   r   r   r   s   &&   r   Úextract_3_cellsÚ/DependencyGraph._parse.<locals>.extract_3_cells  s   € Ø#‰OˆD�tØ ¨3°°D¸"Ð<Ð<r   c                 ó   € V w  r#rEWW#VR WE3# rŠ   r   )rŒ   rr   r   r   r   r   s   &&    r   Úextract_4_cellsÚ/DependencyGraph._parse.<locals>.extract_4_cells  s   € Ø#(Ñ ˆD�tØ ¨3°°DÐ=Ð=r   c                 óX   € V w  r#rErgp \        V4      pWWEVR Wx3#   \         d     Li ; irŠ   ©ÚintÚ
ValueError)	rŒ   rr   Ú
line_indexr   r   r   Ú_r   r   s	   &&       r   Úextract_7_cellsÚ/DependencyGraph._parse.<locals>.extract_7_cells   sE   € Ø9>Ñ6ˆJ˜e¨!°3ðÜ˜J›�ð  ¨C°°TÐ>Ð>øô ô áðús   ‰ ›)¨)c           
      óZ   € V w
  r#rErgr‰ p
 \        V4      pWWEWgW‰3#   \         d     Li ; irZ   r“   )rŒ   rr   r–   r   r   r   r   r   r   r   r—   s   &&         r   Úextract_10_cellsÚ0DependencyGraph._parse.<locals>.extract_10_cells)  sG   € ØINÑFˆJ˜e¨3°tÀ!ÀQðÜ˜J›�ð  ¨S¸ÐBÐBøô ô áðús   ‹ œ*©*c              3   ó$   "  € T F  qx € K  	  R # 5irZ   r   )rp   Úlines   & r   rs   Ú)DependencyGraph._parse.<locals>.<genexpr>:  s   é € Ð:Ñ'9˜t”dÓ'9ùs   ‚Ú
c              3   ó@   "  € T F  qP                  4       x € K  	  R # 5irZ   )Úrstrip©rp   Úls   & r   rs   rŸ   <  s   é € Ð,¡V —‘—�£Vùs   ‚c              3   ó8   "  € T F  q'       g   K  Vx € K  	  R # 5irZ   r   r£   s   & r   rs   rŸ   =  s   é € Ð'™E�q£Q—’›Eùs   ‚	�
N)Ú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   zBThe graph doesn't contain a node that depends on the root element.)Ú
isinstanceÚstrrf   Ú	enumerater_   ÚKeyErrorr•   rO   Ú	TypeErrorr”   r   r    r-   r!   r   ÚwarningsÚwarn)r#   Úinput_r   r   r   r   r�   r�   r˜   r›   Ú
extractorsÚlinesÚcell_numberrr   rž   rŒ   Úer   r   r   r   r   r   r   Úroot_addresss   &&&&&&                   r   r"   ÚDependencyGraph._parse  sK  € ò,	=ò	>ò	?ò	Cð ˆØˆØˆØÐ ð	
ˆ
ô �fœc×"Ò"Ù: v§|¡|°DÔ'9Ó:ˆFá,¡VÓ,ˆÙ'™EÓ'ˆàˆÜ$ U°!×4‰KˆEØ—J‘J˜~Ó.ˆEØÒ"Ü! %›j‘à"¤c¨%£jÔ0Ð0Ð0àÒ%ðØ%/Õ%<�NðQÙBPØóCÑ?��t˜U D¨#¨u°d¸Cð �sŒ{Ùä�t“9ˆDßØ˜•	�à�J‰J�uÕ×$Ñ$à˜uØ˜DØ˜UØ˜DØ˜3Ø˜UØ˜DØ˜3ð	ôð ˜qÔ  t¨q¤yØ(�Ø�J‰J�tÕ˜VÕ$ SÕ)×0Ñ0°Ö7ñc 5ðf �:‰:�a�=˜Õ Ð!3×4Ô4ØŸ:™: a�=¨Õ0Ð1CÕDÀQÕGˆLØŸ
™
 <Õ0ˆDŒIØ&8Ö#ä�MŠMØWöøô]  ô Ü$ð:ß:@¹&ÀÓ:Móð ðûðûô œzÐ*ô Qñ <JÈ%Ó;PÑ8��e˜T 3¨¨t³Sð	Qús*   Â#GÂ,HÇH
Ç*HÈH
È!H2È1H2c                ó:   € VR ,          pV'       d
   VR8w  d   V# V# )r   Ú,r   )r#   r0   ÚfilterÚws   &&& r   Ú_wordÚDependencyGraph._word|  s   € Ø��LˆßØ�CŒxØ�Øˆr   c           	     ó  € V P                  V4      pVR,          p\        \        P                  ! VR,          P	                  4       4      4      pV'       d*   \        Y4 Uu. uF  qPP                  V4      NK  	  up4      # V# u upi )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   )rD   rN   r   rx   r,   r   Ú_tree)r#   Úir0   r   r   r2   s   &&    r   r½   ÚDependencyGraph._treeƒ  so   € ð ×"Ñ" 1Ó%ˆØ�F�|ˆÜ”e×)Ò)¨$¨v­,×*=Ñ*=Ó*?Ó@ÓAˆçÜ˜¸$Ó?¹$°3Ÿz™z¨#ž¹$Ñ?Ó@Ð@àˆKùò @s   Á B
c           	     óð   € V P                   pVR,          p\        \        P                  ! VR,          P	                  4       4      4      p\        Y# Uu. uF  q@P                  V4      NK  	  up4      # u upi )z~
Starting with the ``root`` node, build a dependency tree using the NLTK
``Tree`` constructor. Dependency labels are omitted.
r   r   )r!   rN   r   rx   r,   r   r½   )r#   r0   r   r   r2   s   &    r   ÚtreeÚDependencyGraph.tree’  s]   € ð
 �y‰yˆà�F�|ˆÜ”e×)Ò)¨$¨v­,×*=Ñ*=Ó*?Ó@ÓAˆÜ�D°dÓ;±d¨sŸ:™: cž?±dÑ;Ó<Ð<ùÒ;s   ÁA3
c              #  ód  "  € V'       g   V P                   pVR,          VR,          3p\        \        P                  ! VR,          P	                  4       4      4       FK  pV P                  V4      pW$R,          VR,          VR,          33x € V P                  VR7       Rj  x€L
  KM  	  R#  L
5i)z[
Extract dependency triples of the form:
((head word, head tag), rel, (dep word, dep tag))
r   r   r   r   )r0   N)r!   rN   r   rx   r,   rD   Útriples)r#   r0   r   r¾   r2   s   &&   r   rÄ   ÚDependencyGraph.triples�  s’   é € ÷ Ø—9‘9ˆDà�V•˜d 6�lÐ+ˆÜœ×+Ò+¨D°­L×,?Ñ,?Ó,AÓBÖCˆAØ×%Ñ% aÓ(ˆCØ˜U� c¨&¥k°3°vµ;Ð%?Ð@Ò@Ø—|‘|¨�|Ó-×-Ò-ó Dñ .ùs   ‚B!B0Â#B.Â$B0c                ó\   €  V P                   V,          R ,          #   \         d     R# i ; i)r   N©r   Ú
IndexError©r#   r¾   s   &&r   Ú_hdÚDependencyGraph._hd¬  s,   € ð	Ø—:‘:˜a•= Õ(Ð(øÜô 	Úð	úó   ‚ œ+ª+c                ó\   €  V P                   V,          R ,          #   \         d     R# i ; i)r   NrÇ   rÉ   s   &&r   Ú_relÚDependencyGraph._rel²  s,   € ð	Ø—:‘:˜a•= Õ'Ð'øÜô 	Úð	úrÌ   c                ó6  € / pV P                   P                  4        F+  pVR,           F  p\        VR,          V.4      p^W&   K  	  K-  	  V P                    F½  p/ pV FU  pV FL  pV^,          V^ ,          8X  g   K  \        V^ ,          V^,          .4      pW,          W,          ,           Wd&   KN  	  KW  	  V FW  p	Wi,          W&   V	^ ,          V	^,          8X  g   K$  V P                  V P	                  V	^ ,          4      V	^ ,          4      p
V
u u # 	  K¿  	  R# )a¥  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   F)r   r,   ÚtupleÚget_cycle_pathrD   )r#   Ú	distancesr0   r2   rM   r—   Únew_entriesÚpair1Úpair2ÚpairÚpaths   &          r   Úcontains_cycleÚDependencyGraph.contains_cycle¹  s  € ð4 ˆ	à—J‘J×%Ñ%Ö'ˆDØ˜F—|�|�Ü˜T )�_¨cÐ2Ó3�Ø!"�	“ó $ñ (ð
 —”ˆAØˆKã"�Û&�EØ˜Q•x 5¨¥8Ö+Ü# U¨1¥X¨u°Q­xÐ$8Ó9˜Ø+4Õ+;¸iÕ>NÕ+N˜Ó(ó 'ñ #ó $�Ø"-Õ"3�	‘Ø˜•7˜d 1�gÖ%Ø×.Ñ.¨t×/BÑ/BÀ4ÈÅ7Ó/KÈTÐRSÍWÓU�DØ”Kó	 $ñ ñ r   c                ó  € VR ,           F  pW28X  g   K  VR,          .u # 	  VR ,           FQ  pV P                  V P                  V4      V4      p\        V4      ^ 8”  g   K6  VP                  ^ VR,          4       Vu # 	  . # )r   r   )rÒ   rD   r_   Úinsert)r#   Ú	curr_nodeÚgoal_node_indexr2   rØ   s   &&&  r   rÒ   ÚDependencyGraph.get_cycle_pathë  sƒ   € Ø˜V×$Ð$ˆCØÖ%Ø! )Õ,Ð-Ò-ñ %ð ˜V×$Ð$ˆCØ×&Ñ& t×':Ñ':¸3Ó'?ÀÓQˆDÜ�4‹y˜1Ž}Ø—‘˜A˜y¨Õ3Ô4Ø’ñ	 %ð
 ˆ	r   c                óì   a€ V^8X  d   RoM.V^8X  d   RoM$V^
8X  d   RoM\        RP                  V4      4      hRP                  V3R l\        V P                  P                  4       4       4       4      # )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
z{word}	{tag}	{head}
z{word}	{tag}	{head}	{rel}
z9{i}	{word}	{lemma}	{ctag}	{tag}	{feats}	{head}	{rel}	_	_
r§   r‹   c              3   óp   <"  € T F+  w  rVR ,          R8w  g   K  SP                   ! RRV/VB x € K-  	  R# 5i)r   r   r¾   Nr   )rO   )rp   r¾   r0   Útemplates   &  €r   rs   Ú+DependencyGraph.to_conll.<locals>.<genexpr>  s9   øé € ð 
á5‘�Ø�E�{˜eÑ#ô )ˆH�OŠOÑ(˜aÐ( 4Ö(Û5ùs   ƒ6š6)r•   rO   ÚjoinrN   r   rP   )r#   Ústylerâ   s   &&@r   Úto_conllÚDependencyGraph.to_conllö  s{   ø€ ð �AŒ:Ø0‰HØ�aŒZØ7‰HØ�bŒ[àUñ ô ð2ß28±&¸³-óð ð
 �w‰wô 
ä! $§*¡*×"2Ñ"2Ó"4Ô5ó
ó 
ð 	
r   c                óÌ  € ^ RI p\        \        ^\        V P                  4      4      4      pV Uu. uF=  q0P                  V4      '       g   K  W0P                  V4      V P                  V4      3NK?  	  pp/ V n        V F*  pV P                  V,          R,          V P                  V&   K,  	  VP                  4       pVP                  V4       VP                  V4       V# u upi )zJConvert the data in a ``nodelist`` into a networkx labeled directed graph.Nr   )Únetworkxr   Úranger_   r   rÊ   rÎ   Ú	nx_labelsÚMultiDiGraphÚadd_nodes_fromÚadd_edges_from)r#   ré   Únx_nodelistÚnÚnx_edgelistÚgs   &     r   Únx_graphÚDependencyGraph.nx_graph  s¾   € ãäœ5 ¤C¨¯
©
£OÓ4Ó5ˆá4?ó
Ù4?¨qÇ8Á8ÈAÇ;Ô*ˆQ—‘˜“˜TŸY™Y q›\Ó*±Kð 	ð 
ð ˆŒÛˆAØ $§
¡
¨1¥¨fÕ 5ˆD�N‰N˜1Óñ ð ×!Ñ!Ó#ˆØ	×Ñ˜Ô%Ø	×Ñ˜Ô%àˆùò
s   ±C!Á&C!)r   rë   r!   r   )NNFNÚROOT)FNrõ   )NFNrõ   )TrZ   )"Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r%   r)   r3   r:   r?   rD   rG   rR   rW   r\   r`   Ústaticmethodri   r}   rƒ   r†   r"   rº   r½   rÁ   rÄ   rÊ   rÎ   rÙ   rÒ   ræ   ró   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      s¨   ø‡ € ñô1òf ò$òGò
Eò(ò*ò+òZ#ò #òAð óó ðò45ò5ò5ôxôtòò	=ô.òòò0òd	ò
÷:ð r   r   c                ó^  €  \        R4        VR9   d%   \        P                  ! RRV,          .RV RR7      pM,\        P                  ! RRV,          .\        V RR7      R7      pVP                  #    \        RP                  T 4      4      h; i  \         d   p\        R	4      ThR
p?ii ; i)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).
Údotz-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   Údot_jsonÚjsonÚsvg)r   Ú
subprocessÚrunÚbytesÚstdoutÚ	ExceptionrO   ÚOSError)rV   ÚtÚprocr³   s   &&  r   rU   rU   &  s¸   € ðSÜ�EÔð	ØÐ6Ô6Ü!—~’~Ø˜F Q�JÐ'Ø#'Ø$Øô	‘ô "—~’~Ø˜F Q�JÐ'Ü 
°VÔ<ô�ð —;‘;Ðøð	Üðß‘6˜*Ó%óð ûô ô SÜÐJÓKÐQRÐRûðSús)   ‚B ŽA"A1 Á1BÂB ÂB,ÂB'Â'B,c                   ó   € ] tR tRtRtRtR# )ÚDependencyGraphErroriK  zDependency graph exception.r   N)rö   r÷   rø   rù   rú   rü   r   r   r   r  r  K  s   † Ý%r   r  c                  óV   € \        4        \        4        \        4        \        4        R # rZ   )Ú	malt_demoÚ
conll_demoÚconll_file_demoÚcycle_finding_demor   r   r   Údemor  O  s   € Ü„KÜ„LÜÔÜÖr   c                óÎ  € \        R4      pVP                  4       pVP                  4        V '       d²   ^ RIp^ RIHp VP                  4       pVP                  4        VP                  V^R7      pVP                  WV^2R7       VP                  WVVP                  4       VP                  . 4       VP                  . 4       VP                  R4       VP                  4        R# R# )zk
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
N)Úpylab)Údim)Ú	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                 ó®   € \        \        4      p V P                  4       pVP                  4        \	        V 4       \	        V P                  ^4      4       R# )z[
A demonstration of how to read a string representation of
a CoNLL format dependency tree.
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                  óú   € \        R 4       \        P                  R4       U u. uF  q '       g   K  \        V 4      NK  	  pp V F.  pVP	                  4       p\        R4       VP                  4        K0  	  R# u up i )zMass conll_read demo...rc   r    N)r-  Úconll_data2rf   r   rÁ   r  )ÚentryÚgraphsÚgraphrÁ   s       r   r  r  �  sa   € Ü	Ð
#Ô$Ü2=×2CÑ2CÀFÔ2KÓUÑ2K¨ËuÔ$Œo˜eÖ$Ñ2K€FÐUÛˆØ�z‰z‹|ˆÜˆdŒØ�‰Žó ùò Vs
   £	A8±A8c            
      ó   € \        \        4      p \        V P                  4       4       \        4       pVP	                  R RR^.RRR^ /4       VP	                  R RR^.RRR^/4       VP	                  R RR^.RRR^/4       VP	                  R RR^.RRR^/4       VP	                  R RR^.RRR^/4       \        VP                  4       4       R# )r   Nr   r   r   r   ÚNTOP)r   Útreebank_datar-  rÙ   r†   )r)  Ú	cyclic_dgs     r   r  r  ˜  sÛ   € Ü	œÓ	'€BÜ	ˆ"×
Ñ
Ó
ÔÜÓ!€IØ×Ñ˜  f¨q¨c°5¸%ÀÈAÐNÔOØ×Ñ˜  f¨q¨c°5¸&À)ÈQÐOÔPØ×Ñ˜  f¨q¨c°5¸&À)ÈQÐOÔPØ×Ñ˜  f¨q¨c°5¸&À)ÈQÐOÔPØ×Ñ˜  f¨q¨c°5¸&À)È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   rU   r  r  r  r  r  r  r  r5  r,  r/  rö   r   r   r   Ú<module>r<     s†   ðñó Û Ý #Ý Ý å &Ý ÷Dñ DôN"SôJ&˜9ô &òô*òZ	òò	&ð€ð(€ð T€ðl ˆzÔÙ†Fñ r   