ó
    ´OÂf`U  ã                   óL  • S r SSKJr  SSKJrJrJrJr  SSKJ	r	J
r
JrJrJrJr  SSKJrJrJrJrJrJrJrJrJrJrJrJr  SSKJr  SSKJr   " S S	\5      r  " S
 S\5      r! " S S\5      r" " S S\5      r# " S S\5      r$ " S S\5      r% " S S\5      r& " S S\5      r' " S S\5      r(\" 5       \$" 5       \%" 5       \#" 5       /r)\" 5       \(" 5       \&" 5       \#" 5       /r*\" 5       \(" 5       \'" 5       \#" 5       /r+ " S S\5      r, " S S\,5      r- " S S\,5      r. " S  S!\,5      r/ " S" S#\!5      r0S$ r1S%S%S%S%S&\,S'4S( jr2S) r3\4S*:X  aX  SS+K5J6r6  \2" 5         \7" 5         \6" S,5      r8\," \8S-S.9r9S/r:\:Rw                  5       r<\9R{                  \<5      r>\> H  r?\7" \?5        M     g0g0)1z`
Extension of chart parsing implementation to handle grammars with
feature structures as nodes.
é    )Úperf_counter)ÚTYPEÚ
FeatStructÚfind_variablesÚunify)ÚCFGÚFeatStructNonterminalÚNonterminalÚ
ProductionÚis_nonterminalÚis_terminal)ÚBottomUpPredictCombineRuleÚBottomUpPredictRuleÚCachedTopDownPredictRuleÚChartÚChartParserÚEdgeIÚEmptyPredictRuleÚFundamentalRuleÚLeafInitRuleÚSingleEdgeFundamentalRuleÚTopDownInitRuleÚTreeEdge)Úlogic)ÚTreec                   óh   ^ • \ rS rSrSrSS jr\S 5       rSS jrS r	S r
S rS	 rU 4S
 jrSrU =r$ )ÚFeatureTreeEdgeé.   aá  
A specialized tree edge that allows shared variable bindings
between nonterminals on the left-hand side and right-hand side.

Each ``FeatureTreeEdge`` contains a set of ``bindings``, i.e., a
dictionary mapping from variables to values.  If the edge is not
complete, then these bindings are simply stored.  However, if the
edge is complete, then the constructor applies these bindings to
every nonterminal in the edge whose symbol implements the
interface ``SubstituteBindingsI``.
c                 óL  • Uc  0 nU[        U5      :X  a:  U(       a3  U R                  X%5      nU Vs/ s H  o`R                  Xe5      PM     nn0 n[        R                  " XX#U5        XPl        U R
                  [        [        UR                  5       5      5      4U l        gs  snf )aB  
Construct a new edge.  If the edge is incomplete (i.e., if
``dot<len(rhs)``), then store the bindings as-is.  If the edge
is complete (i.e., if ``dot==len(rhs)``), then apply the
bindings to all nonterminals in ``lhs`` and ``rhs``, and then
clear the bindings.  See ``TreeEdge`` for a description of
the other arguments.
N)	ÚlenÚ_bindr   Ú__init__Ú	_bindingsÚ_comparison_keyÚtupleÚsortedÚitems)ÚselfÚspanÚlhsÚrhsÚdotÚbindingsÚelts          Ú9/usr/lib/python3/dist-packages/nltk/parse/featurechart.pyr"   ÚFeatureTreeEdge.__init__;   sŽ   € ð ÑØˆHð ”#�c“(‹?žxØ—*‘*˜SÓ+ˆCÙ8;Ó<º°—:‘:˜cÖ,¹ˆCÐ<ØˆHô 	×Ò˜$ c°Ô4Ø!ŒØ $× 4Ñ 4´e¼FÀ8Ç>Á>ÓCSÓ<TÓ6UÐVˆÕùò =s   ±B!c                 óT   • [        X4U R                  5       U R                  5       SS9$ )zù
:return: A new ``TreeEdge`` formed from the given production.
    The new edge's left-hand side and right-hand side will
    be taken from ``production``; its span will be
    ``(index,index)``; and its dot position will be ``0``.
:rtype: TreeEdge
r   )r)   r*   r+   r,   )r   r*   r+   )Ú
productionÚindexs     r/   Úfrom_productionÚFeatureTreeEdge.from_productionV   s+   € ô Ø� Z§^¡^Ó%5¸:¿>¹>Ó;KÐQRñ
ð 	
ó    c                 ó|   • [        U R                  S   U4U R                  U R                  U R                  S-   US9$ )a8  
:return: A new ``FeatureTreeEdge`` formed from this edge.
    The new edge's dot position is increased by ``1``,
    and its end index will be replaced by ``new_end``.
:rtype: FeatureTreeEdge
:param new_end: The new end index.
:type new_end: int
:param bindings: Bindings for the new edge.
:type bindings: dict
r   é   )r)   r*   r+   r,   r-   )r   Ú_spanÚ_lhsÚ_rhsÚ_dot)r(   Únew_endr-   s      r/   Úmove_dot_forwardÚ FeatureTreeEdge.move_dot_forwardc   s=   € ô Ø—*‘*˜Q‘- Ð)Ø—	‘	Ø—	‘	Ø—	‘	˜A‘Øñ
ð 	
r6   c                 óR   • [        U[        5      (       d  U$ UR                  U5      $ ©N)Ú
isinstancer	   Úsubstitute_bindings)r(   Úntr-   s      r/   r!   ÚFeatureTreeEdge._bindv   s&   € Ü˜"Ô3×4Ñ4ØˆIØ×%Ñ% hÓ/Ð/r6   c                 óV   • U R                  U R                  5       U R                  5      $ rA   )r!   Únextsymr#   ©r(   s    r/   Únext_with_bindingsÚ"FeatureTreeEdge.next_with_bindings{   s   € Ø�z‰z˜$Ÿ,™,›.¨$¯.©.Ó9Ð9r6   c                 ó6   • U R                   R                  5       $ )z3
Return a copy of this edge's bindings dictionary.
)r#   ÚcopyrH   s    r/   r-   ÚFeatureTreeEdge.bindings~   s   € ð �~‰~×"Ñ"Ó$Ð$r6   c                 óð   • [        U R                  /[        U R                  5      -   [        U R                  R                  5       5      -   [        U R                  R                  5       5      -   [        S9$ )zH
:return: The set of variables used by this edge.
:rtype: set(Variable)
©Úfs_class)r   r:   Úlistr;   r#   ÚkeysÚvaluesr   rH   s    r/   Ú	variablesÚFeatureTreeEdge.variables„   se   € ô
 Ø�Y‰YˆKÜ�4—9‘9‹oñä�4—>‘>×&Ñ&Ó(Ó)ñ*ô �4—>‘>×(Ñ(Ó*Ó+ñ,ô  ñ
ð 	
r6   c                 óè   >• U R                  5       (       a  [        TU ]	  5       $ SSR                  S [	        U R
                  R                  5       5       5       5      -  n[        TU ]	  5        SU 3$ )Nz{%s}z, c              3   ó,   #   • U  H
  nS U-  v •  M     g7f)z%s: %rN© )Ú.0Úitems     r/   Ú	<genexpr>Ú*FeatureTreeEdge.__str__.<locals>.<genexpr>•   s   é € ð *Ú,J D�˜4–Ò,Jùs   ‚Ú )Úis_completeÚsuperÚ__str__Újoinr&   r#   r'   )r(   r-   Ú	__class__s     €r/   r`   ÚFeatureTreeEdge.__str__‘   sn   ø€ Ø×Ñ×ÑÜ‘7‘?Ó$Ð$à §	¡	ñ *Ü,2°4·>±>×3GÑ3GÓ3IÔ,Jó*ó !ñ ˆHô ‘g‘oÓ'Ð(¨¨(¨Ð4Ð4r6   )r#   r$   )r   NrA   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   Ústaticmethodr4   r>   r!   rI   r-   rT   r`   Ú__static_attributes__Ú__classcell__)rb   s   @r/   r   r   .   sE   ø† ñ
ôWð6 ñ

ó ð

ô
ò&0ò
:ò%ò
÷5ó 5r6   r   c                   ó<   • \ rS rSrSrS rS rS rS r\	4S jr
Srg	)
ÚFeatureCharté¢   zE
A Chart for feature grammars.
:see: ``Chart`` for more information.
c                 óB  ^ ^• T0 :X  a  [        T R                  5      $ [        TR                  5       5      n[	        U5      nUT R
                  ;  a  T R                  U5        [	        UU 4S jU 5       5      n[        T R
                  U   R                  U/ 5      5      $ )z†
Returns an iterator over the edges in this chart.
See ``Chart.select`` for more information about the
``restrictions`` on the edges.
c              3   óL   >#   • U  H  nTR                  TU   5      v •  M     g 7frA   )Ú_get_type_if_possible)rY   ÚkeyÚrestrictionsr(   s     €€r/   r[   Ú&FeatureChart.select.<locals>.<genexpr>º   s'   øé € ð 
ÚEO¸cˆD×&Ñ& |°CÑ'8×9Ð9ÂZùs   ƒ!$)ÚiterÚ_edgesr&   rR   r%   Ú_indexesÚ
_add_indexÚget)r(   rs   Ú
restr_keysÚvalss   ``  r/   ÚselectÚFeatureChart.select¨   s�   ù€ ð ˜2ÓÜ˜Ÿ™Ó$Ð$ô ˜L×-Ñ-Ó/Ó0ˆ
Ü˜:Ó&ˆ
ð ˜TŸ]™]Ó*Ø�O‰O˜JÔ'äõ 
ÙEOó
ó 
ˆô �D—M‘M *Ñ-×1Ñ1°$¸Ó;Ó<Ð<r6   c                 ó  ^ ^• U H&  n[        [        U5      (       a  M  [        SU-  5      e   0 =nT R                  U'   T R                   H:  m[        UU 4S jU 5       5      nUR                  U/ 5      R                  T5        M<     g)zs
A helper function for ``select``, which creates a new index for
a given set of attributes (aka restriction keys).
zBad restriction: %sc              3   ód   >#   • U  H%  nTR                  [        TU5      " 5       5      v •  M'     g 7frA   ©rq   Úgetattr©rY   rr   Úedger(   s     €€r/   r[   Ú*FeatureChart._add_index.<locals>.<genexpr>Î   ó,   øé € ð ÚLVÀS�×*Ñ*¬7°4¸Ô+=Ó+?×@Ð@ÊJùó   ƒ-0N)Úhasattrr   Ú
ValueErrorrw   rv   r%   Ú
setdefaultÚappend)r(   rz   rr   r3   r{   rƒ   s   `    @r/   rx   ÚFeatureChart._add_index¿   s†   ù€ ó ˆCÜœ5 #×&Ó&Ü Ð!6¸Ñ!<Ó=Ð=ñ ð
 -/Ð.ˆ�—‘˜jÑ)ð —K”KˆDÜõ ÙLVóó ˆDð ×Ñ˜T 2Ó&×-Ñ-¨dÖ3ò	  r6   c                 ó¼   ^ ^• T R                   R                  5        H<  u  p#[        UU 4S jU 5       5      nUR                  U/ 5      R	                  T5        M>     g)z[
A helper function for ``insert``, which registers the new
edge with all existing indexes.
c              3   ód   >#   • U  H%  nTR                  [        TU5      " 5       5      v •  M'     g 7frA   r€   r‚   s     €€r/   r[   Ú6FeatureChart._register_with_indexes.<locals>.<genexpr>Ù   r…   r†   N)rw   r'   r%   r‰   rŠ   )r(   rƒ   rz   r3   r{   s   ``   r/   Ú_register_with_indexesÚ#FeatureChart._register_with_indexesÓ   sS   ù€ ð
 "&§¡×!4Ñ!4Ö!6ÑˆJÜõ ÙLVóó ˆDð ×Ñ˜T 2Ó&×-Ñ-¨dÖ3ò	 "7r6   c                 óV   • [        U[        5      (       a  [        U;   a	  U[           $ U$ )z|
Helper function which returns the ``TYPE`` feature of the ``item``,
if it exists, otherwise it returns the ``item`` itself
)rB   Údictr   )r(   rZ   s     r/   rq   Ú"FeatureChart._get_type_if_possibleÞ   s&   € ô
 �dœD×!Ñ!¤d¨d£lØœ‘:ÐàˆKr6   c              #   ó:  #   • U R                  SU R                  S9 Hw  n[        U[        5      (       d  M  UR	                  5       [
           U[
           :X  d  M>  [        UR	                  5       USS9(       d  M^  U R                  USUS9 S h  v•N   My     g  N	7f)Nr   )ÚstartÚendT©Úrename_vars)ÚcompleteÚ
tree_class)r|   Ú_num_leavesrB   r   r*   r   r   Útrees)r(   r•   rš   rƒ   s       r/   ÚparsesÚFeatureChart.parsesè   sy   é € Ø—K‘K a¨T×-=Ñ-=�KÓ>ˆDä˜D¤/×2Ó2Ø—X‘X“Z¤Ñ%¨¬t©Õ4Ü˜4Ÿ8™8›: u¸$×?Ñ?àŸ:™: d°TÀj˜:ÐQ×QÒQò ?ñ Rùs"   ‚1B· BÁBÁ;BÂBÂ
BrX   N)rd   re   rf   rg   rh   r|   rx   r�   rq   r   r�   rj   rX   r6   r/   rm   rm   ¢   s&   † ñò
=ò.4ò(	4òð (,÷ Rr6   rm   c                   ó   • \ rS rSrSrS rSrg)ÚFeatureFundamentalRuleé÷   ak  
A specialized version of the fundamental rule that operates on
nonterminals whose symbols are ``FeatStructNonterminal``s.  Rather
than simply comparing the nonterminals for equality, they are
unified.  Variable bindings from these unifications are collected
and stored in the chart using a ``FeatureTreeEdge``.  When a
complete edge is generated, these bindings are applied to all
nonterminals in the edge.

The fundamental rule states that:

- ``[A -> alpha \* B1 beta][i:j]``
- ``[B2 -> gamma \*][j:k]``

licenses the edge:

- ``[A -> alpha B3 \* beta][i:j]``

assuming that B1 and B2 can be unified to generate B3.
c              #   óÜ  #   • UR                  5       UR                  5       :X  a?  UR                  5       (       a*  UR                  5       (       a  [	        U[
        5      (       d  g UR                  5       nUR                  5       n[	        U[
        5      (       a  [        U5      (       d  g UR                  5       [           UR                  5       [           :w  a  g UR                  5       nUR                  UR                  5       S9n[        XeUSS9nUc  g OXe:w  a  g UR                  5       nUR                  UR                  5       U5      n	UR                  X“U5      (       a  U	v •  g g 7f)N©Ú	used_varsFr—   )r–   r•   Úis_incompleter^   rB   r   r*   rG   r   r   r-   Úrename_variablesrT   r   r>   Úinsert_with_backpointer)
r(   ÚchartÚgrammarÚ	left_edgeÚ
right_edgeÚfoundrG   r-   ÚresultÚnew_edges
             r/   ÚapplyÚFeatureFundamentalRule.apply  sC  é € ð �M‰M‹O˜z×/Ñ/Ó1Ó1Ø×'Ñ'×)Ñ)Ø×&Ñ&×(Ñ(Ü˜9¤o×6Ñ6àØ—‘Ó ˆØ×#Ñ#Ó%ˆÜ�j¤/×2Ñ2Ü! '×*Ñ*ØØ× Ñ Ó"¤4Ñ(¨J¯N©NÓ,<¼TÑ,BÓBØà ×)Ñ)Ó+ˆHð ×*Ñ*°Y×5HÑ5HÓ5JÐ*ÐKˆEô ˜7¨8ÀÑGˆFØ‰~Øð ð ÓØà ×)Ñ)Ó+ˆHð ×-Ñ-¨j¯n©nÓ.>ÀÓIˆð ×(Ñ(¨¸j×IÑIØ‹Nð Jùs   ‚E*E,rX   N©rd   re   rf   rg   rh   r¯   rj   rX   r6   r/   r    r    ÷   s   † ñõ*%r6   r    c                   ó2   • \ rS rSrSr\" 5       rS rS rSr	g)Ú FeatureSingleEdgeFundamentalRulei5  zà
A specialized version of the completer / single edge fundamental rule
that operates on nonterminals whose symbols are ``FeatStructNonterminal``.
Rather than simply comparing the nonterminals for equality, they are
unified.
c              #   óÄ   #   • U R                   nUR                  UR                  5       SUR                  5       S9 H  nUR	                  XXS5       S h  v•N   M     g  N	7f)NF)r–   r^   rG   )Ú_fundamental_ruler|   r•   r*   r¯   )r(   r¨   r©   r«   Úfrrª   s         r/   Ú_apply_completeÚ0FeatureSingleEdgeFundamentalRule._apply_complete?  s[   é € Ø×#Ñ#ˆØŸ™Ø× Ñ Ó"°¸z¿~¹~Ó?Oð &ó 
ˆIð —x‘x °	ÓF×FÒFò
ñ Gùó   ‚AA ÁAÁ
A c              #   óÄ   #   • U R                   nUR                  UR                  5       SUR                  5       S9 H  nUR	                  XX55       S h  v•N   M     g  N	7f)NT)r•   r^   r*   )rµ   r|   r–   rG   r¯   )r(   r¨   r©   rª   r¶   r«   s         r/   Ú_apply_incompleteÚ2FeatureSingleEdgeFundamentalRule._apply_incompleteF  sZ   é € Ø×#Ñ#ˆØŸ,™,Ø—-‘-“/¨t¸×9JÑ9JÓ9Lð 'ó 
ˆJð —x‘x °	ÓF×FÒFò
ñ Gùr¹   rX   N)
rd   re   rf   rg   rh   r    rµ   r·   r»   rj   rX   r6   r/   r³   r³   5  s   † ññ /Ó0ÐòGõGr6   r³   c                   ó   • \ rS rSrS rSrg)ÚFeatureTopDownInitRuleiS  c              #   óº   #   • UR                  UR                  5       S9 H6  n[        R                  US5      nUR	                  US5      (       d  M2  Uv •  M8     g 7f)N©r*   r   rX   )Úproductionsr•   r   r4   Úinsert)r(   r¨   r©   Úprodr®   s        r/   r¯   ÚFeatureTopDownInitRule.applyT  sK   é € Ø×'Ñ'¨G¯M©M«OÐ'Ó<ˆDÜ&×6Ñ6°t¸QÓ?ˆHØ�|‰|˜H b×)Ó)Ø”ò =ùs   ‚AAÁ	ArX   N©rd   re   rf   rg   r¯   rj   rX   r6   r/   r¾   r¾   S  s   † õr6   r¾   c                   ó   • \ rS rSrSrS rSrg)ÚFeatureTopDownPredictRulei[  a©  
A specialized version of the (cached) top down predict rule that operates
on nonterminals whose symbols are ``FeatStructNonterminal``.  Rather
than simply comparing the nonterminals for equality, they are
unified.

The top down expand rule states that:

- ``[A -> alpha \* B1 beta][i:j]``

licenses the edge:

- ``[B2 -> \* gamma][j:j]``

for each grammar production ``B2 -> gamma``, assuming that B1
and B2 can be unified.
c              #   óè  #   • UR                  5       (       a  g UR                  5       UR                  5       pT[        U5      (       d  g UR	                  5       nU R
                  R                  Xe4S5      nUS   UL a	  US   UL a  g UR                  US9 HÆ  nUR                  5       (       aN  UR                  5       S   n	[        U	5      (       a+  XQR                  5       :¼  a  MP  X‘R                  U5      :w  a  Mf  [        UR                  5       USS9(       d  M†  [        R                  XƒR                  5       5      n
UR!                  U
S5      (       d  MÂ  U
v •  MÈ     X4U R
                  Xe4'   g 7f)N)NNr   r8   rÀ   Tr—   rX   )r^   rG   r–   r   rI   Ú_donery   rÁ   r+   r   Ú
num_leavesÚleafr   r*   r   r4   rÂ   )r(   r¨   r©   rƒ   rG   r3   Únextsym_with_bindingsÚdonerÃ   Úfirstr®   s              r/   r¯   ÚFeatureTopDownPredictRule.applyn  s9  é € Ø×Ñ×ÑØØŸ™›¨¯©«�Ü˜g×&Ñ&Øð
 !%× 7Ñ 7Ó 9ÐØ�z‰z�~‰~Ð4Ð<¸lÓKˆØ�‰7�eÒ  Q¡¨7Ò 2Øà×'Ñ'¨GÐ'Ó4ˆDð �x‰x�z‰zØŸ™›
 1™�Ü˜u×%Ñ%Ø× 0Ñ 0Ó 2Ó2Ù Ø§
¡
¨5Ó 1Ó1Ù ô �T—X‘X“ZÐ!6ÀD×IÑIÜ*×:Ñ:¸4ÇÁÃÓL�Ø—<‘< ¨"×-Ó-Ø"”Nñ! 5ð& 5:Ð3Cˆ�
‰
Ð(Ð/Ò0ùs   ‚DE2Ä8E2ÅE2rX   Nr±   rX   r6   r/   rÇ   rÇ   [  s   † ñõ$"Dr6   rÇ   c                   ó   • \ rS rSrS rSrg)ÚFeatureBottomUpPredictRulei˜  c              #   ót  #   • UR                  5       (       a  g UR                  UR                  5       S9 H}  n[        U[        5      (       a%  UR                  5       S   n[        U5      (       d  M=  [        R                  XCR                  5       5      nUR                  US5      (       d  My  Uv •  M     g 7f)N©r+   r   rX   )
r¥   rÁ   r*   rB   r   r+   r   r4   r•   rÂ   )r(   r¨   r©   rƒ   rÃ   Ú_nextr®   s          r/   r¯   Ú FeatureBottomUpPredictRule.apply™  s‹   é € Ø×Ñ×ÑØØ×'Ñ'¨D¯H©H«JÐ'Ó7ˆDÜ˜$¤×0Ñ0ØŸ™›
 1™�Ü% e×,Ñ,Ùä&×6Ñ6°t¿Z¹Z»\ÓJˆHØ�|‰|˜H b×)Ó)Ø”ò 8ùs   ‚B)B8Â/	B8rX   NrÅ   rX   r6   r/   rÑ   rÑ   ˜  s   † õr6   rÑ   c                   ó   • \ rS rSrS rSrg)Ú!FeatureBottomUpPredictCombineRulei§  c              #   óR  #   • UR                  5       (       a  g UR                  5       nUR                  US9 Hê  n0 n[        U[        5      (       ar  UR                  5       S   n[        U5      (       d  M?  [        UR                  5       4UR                  5       -   [        S9nUR                  US9n[        XtUSS9n	U	c  MŒ  [        R                  XSR                  5       5      R                  UR                  5       U5      n
UR                  X£45      (       d  Mæ  U
v •  Mì     g 7f)NrÓ   r   rO   r£   Fr—   )r¥   r*   rÁ   rB   r   r+   r   r   r   r¦   r   r4   r•   r>   r–   rÂ   )r(   r¨   r©   rƒ   r¬   rÃ   r-   rÔ   r¤   r­   r®   s              r/   r¯   Ú'FeatureBottomUpPredictCombineRule.apply¨  sÿ   é € Ø×Ñ×ÑØØ—‘“
ˆØ×'Ñ'¨EÐ'Ó2ˆDØˆHÜ˜$¤×0Ñ0ØŸ™›
 1™�Ü% e×,Ñ,Ùô +Ø—X‘X“Z�M D§H¡H£JÑ.¼ñ�	ð ×.Ñ.¸Ð.ÐC�ä˜u¨XÀ5ÑI�Ø‘>Ùä&×6Ñ6Ø—j‘j“lóçÑ˜tŸx™x›z¨8Ó4ð ð �|‰|˜H g×.Ó.Ø”ò- 3ùs   ‚DD'Ä	D'rX   NrÅ   rX   r6   r/   r×   r×   §  s   † õr6   r×   c                   ó   • \ rS rSrS rSrg)ÚFeatureEmptyPredictRuleiÅ  c              #   óâ   #   • UR                  SS9 HX  n[        UR                  5       S-   5       H5  n[        R	                  X45      nUR                  US5      (       d  M1  Uv •  M7     MZ     g 7f)NT)Úemptyr8   rX   )rÁ   ÚrangerÊ   r   r4   rÂ   )r(   r¨   r©   rÃ   r3   r®   s         r/   r¯   ÚFeatureEmptyPredictRule.applyÆ  s`   é € Ø×'Ñ'¨dÐ'Ó3ˆDÜ˜u×/Ñ/Ó1°AÑ5Ö6�Ü*×:Ñ:¸4ÓG�Ø—<‘< ¨"×-Ó-Ø"”Nó 7ò 4ùs   ‚AA/Á"A/rX   NrÅ   rX   r6   r/   rÛ   rÛ   Å  s   † õ#r6   rÛ   c                   ó$   • \ rS rSr\S\4S jrSrg)ÚFeatureChartParseriæ  é   c                 ó<   • [         R                  " U U4UUUS.UD6  g )N)ÚstrategyÚtrace_chart_widthÚchart_class)r   r"   )r(   r©   rä   rå   ræ   Úparser_argss         r/   r"   ÚFeatureChartParser.__init__ç  s2   € ô 	×ÒØØð	
ð Ø/Ø#ñ	
ð ó	
r6   rX   N)rd   re   rf   rg   ÚBU_LC_FEATURE_STRATEGYrm   r"   rj   rX   r6   r/   rá   rá   æ  s   † ð (ØØ ÷
r6   rá   c                   ó   • \ rS rSrS rSrg)ÚFeatureTopDownChartParseriù  c                 ó<   • [         R                  " X[        40 UD6  g rA   )rá   r"   ÚTD_FEATURE_STRATEGY©r(   r©   rç   s      r/   r"   Ú"FeatureTopDownChartParser.__init__ú  ó   € Ü×#Ò# DÔ3FÑVÈ+ÓVr6   rX   N©rd   re   rf   rg   r"   rj   rX   r6   r/   rë   rë   ù  ó   † õWr6   rë   c                   ó   • \ rS rSrS rSrg)ÚFeatureBottomUpChartParseriþ  c                 ó<   • [         R                  " X[        40 UD6  g rA   )rá   r"   ÚBU_FEATURE_STRATEGYrî   s      r/   r"   Ú#FeatureBottomUpChartParser.__init__ÿ  rð   r6   rX   Nrñ   rX   r6   r/   rô   rô   þ  rò   r6   rô   c                   ó   • \ rS rSrS rSrg)Ú$FeatureBottomUpLeftCornerChartParseri  c                 ó<   • [         R                  " X[        40 UD6  g rA   )rá   r"   ré   rî   s      r/   r"   Ú-FeatureBottomUpLeftCornerChartParser.__init__  s   € Ü×#Ò#ØÔ1ñ	
Ø5@ó	
r6   rX   Nrñ   rX   r6   r/   rù   rù     s   † õ
r6   rù   c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚInstantiateVarsCharti  a'  
A specialized chart that 'instantiates' variables whose names
start with '@', by replacing them with unique new variables.
In particular, whenever a complete edge is added to the chart, any
variables in the edge's ``lhs`` whose names start with '@' will be
replaced by unique new ``Variable``.
c                 ó.   • [         R                  X5        g rA   )rm   r"   )r(   Útokenss     r/   r"   ÚInstantiateVarsChart.__init__  s   € Ü×Ñ˜dÕ+r6   c                 óL   • [        5       U l        [        R                  U 5        g rA   )ÚsetÚ_instantiatedrm   Ú
initializerH   s    r/   r  ÚInstantiateVarsChart.initialize  s   € Ü ›UˆÔÜ×Ñ Õ%r6   c                 óp   • XR                   ;   a  gU R                  U5        [        R                  XU5      $ )NF)r  Úinstantiate_edgerm   rÂ   )r(   rƒ   Úchild_pointer_lists      r/   rÂ   ÚInstantiateVarsChart.insert  s3   € Ø×%Ñ%Ó%ØØ×Ñ˜dÔ#Ü×"Ñ" 4Ð/AÓBÐBr6   c                 ó,  • [        U[        5      (       d  gUR                  5       (       d  gXR                  ;   a  gU R	                  U5      nU(       d  gU R
                  R                  U5        UR                  5       R                  U5      Ul	        g)a&  
If the edge is a ``FeatureTreeEdge``, and it is complete,
then instantiate all variables whose names start with '@',
by replacing them with unique new variables.

Note that instantiation is done in-place, since the
parsing algorithms might already hold a reference to
the edge for future use.
N)
rB   r   r^   Ú_edge_to_cplsÚ	inst_varsr  Úaddr*   rC   r:   )r(   rƒ   r  s      r/   r  Ú%InstantiateVarsChart.instantiate_edge%  sy   € ô ˜$¤×0Ñ0ØØ×Ñ×!Ñ!ØØ×%Ñ%Ó%Øð —N‘N 4Ó(ˆ	ÞØð 	×Ñ×Ñ˜tÔ$Ø—H‘H“J×2Ñ2°9Ó=ˆ�	r6   c                 óÖ   • UR                  5       R                  5        Vs0 s H;  nUR                  R                  S5      (       d  M%  U[        R
                  " 5       _M=     sn$ s  snf )NÚ@)r*   rT   ÚnameÚ
startswithr   Úunique_variable)r(   rƒ   Úvars      r/   r  ÚInstantiateVarsChart.inst_varsB  sZ   € ð —x‘x“z×+Ñ+Ô-ó
â-�Ø�x‰x×"Ñ" 3×'ó )ˆC”×&Ò&Ó(Ò(Ù-ñ
ð 	
ùò 
s   ¡$A&Á	A&)r  N)rd   re   rf   rg   rh   r"   r  rÂ   r  r  rj   rX   r6   r/   rý   rý     s!   † ñò,ò&òCò>õ:
r6   rý   c                  ó0   • SSK Jn   U R                  S5      $ )Nr   ©ÚFeatureGrammara  
S  -> NP VP
PP -> Prep NP
NP -> NP PP
VP -> VP PP
VP -> Verb NP
VP -> Verb
NP -> Det[pl=?x] Noun[pl=?x]
NP -> "John"
NP -> "I"
Det -> "the"
Det -> "my"
Det[-pl] -> "a"
Noun[-pl] -> "dog"
Noun[-pl] -> "cookie"
Verb -> "ate"
Verb -> "saw"
Prep -> "with"
Prep -> "under"
)Únltk.grammarr  Ú
fromstringr  s    r/   Údemo_grammarr  O  s   € Ý+à×$Ñ$ð	óð r6   Tr8   z$I saw John with a dog with my cookiec                 ó  • SS K nSS Kn[        5         [        5       n	U(       a  [        U	5        [        5         [        SUR                  5        U(       a  [        SU5        UR                  5       n
[        5       nU" X”S9nUR                  U
5      n[        UR                  U	R                  5       5      5      nU (       a  [        S[        5       U-
  -  5        U(       a  U H  n[        U5        M     g [        S[        U5      5        g )Nr   Ú*z	Sentence:©ÚtracezTime: %sz	Nr trees:)ÚsysÚtimeÚprintr  rd   Úsplitr   Úchart_parserQ   r�   r•   r    )Úprint_timesÚprint_grammarÚprint_treesÚprint_sentencer  ÚparserÚsentr   r!  r©   rÿ   ÚtÚcpr¨   rœ   Útrees                   r/   Údemor.  j  s¾   € ó Ûä	„GÜ‹n€GÞÜˆgŒÜŒÜ	ˆ#ˆv�‰ÔÞÜˆk˜4Ô Ø�Z‰Z‹\€FÜ‹€AÙ	�Ñ	%€BØ�N‰N˜6Ó"€EÜ�—‘˜gŸm™m›oÓ.Ó/€EÞÜˆjœL›N¨QÑ.Ñ/Ô0ÞÛˆDÜ�$ŽKò ô 	ˆkœ3˜u›:Õ&r6   c                  ó  • SS K n U R                  SS5        SS KnUR                  S5      nUR	                  5       R                  SS5      R                  S5        UR	                  5       R                  SS5      R                  S5        g )Nr   zfor i in range(1): demo()z/tmp/profile.outr!  Úcumé<   )ÚprofileÚrunÚpstatsÚStatsÚ
strip_dirsÚ
sort_statsÚprint_stats)r2  r4  Úps      r/   Úrun_profiler:  Œ  si   € Ûà‡K�KÐ+Ð-?Ô@Ûà�‰Ð'Ó(€AØ‡L�LƒN×Ñ˜f eÓ,×8Ñ8¸Ô<Ø‡L�LƒN×Ñ˜e VÓ,×8Ñ8¸Õ<r6   Ú__main__)Úloadz!grammars/book_grammars/feat0.fcfgé   r  zKim likes childrenN)@rh   r!  r   Únltk.featstructr   r   r   r   r  r   r	   r
   r   r   r   Únltk.parse.chartr   r   r   r   r   r   r   r   r   r   r   r   Únltk.semr   Ú	nltk.treer   r   rm   r    r³   r¾   rÇ   rÑ   r×   rÛ   rí   rö   ré   rá   rë   rô   rù   rý   r  r.  r:  rd   Ú	nltk.datar<  r"  r©   r,  r*  r#  rÿ   Úparserœ   r-  rX   r6   r/   Ú<module>rD     sê  ðñõ ç CÓ C÷÷ ÷÷ ÷ ó õ Ý ôj5�hô j5ôhMR�5ô MRôj;˜_ô ;ô|GÐ'@ô Gô<˜_ô ô5DÐ 8ô 5DôzÐ!4ô ôÐ(Bô ô<#Ð.ô #ñ ƒNÙÓÙÓÙ$Ó&ð	Ð ñ ƒNÙÓÙÓ Ù$Ó&ð	Ð ñ ƒNÙÓÙ%Ó'Ù$Ó&ð	Ð ô
˜ô 
ô&WÐ 2ô Wô
WÐ!3ô Wô

Ð+=ô 
ô8
˜<ô 8
ò@ð8 ØØØØ
ØØ	/ô'òD=ð ˆzÓÝá„FÙ	„GÙÐ6Ó7€GÙ	˜G¨1Ñ	-€BØ€DØ�Z‰Z‹\€FØ�H‰H�VÓ€EÛˆÙˆdŽò ð r6   