§
    'ê[fX  ã                   ó  — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ  G d„ d	e¦  «        Z  G d
„ de¦  «        Z! G d„ de¦  «        Z" G d„ de¦  «        Z# G d„ de¦  «        Z$ G d„ de¦  «        Z% G d„ de¦  «        Z& G d„ de¦  «        Z' G d„ de¦  «        Z( e¦   «          e$¦   «          e%¦   «          e#¦   «         gZ) e¦   «          e(¦   «          e&¦   «          e#¦   «         gZ* e¦   «          e(¦   «          e'¦   «          e#¦   «         gZ+ G d„ de¦  «        Z, G d„ de,¦  «        Z- G d„ de,¦  «        Z. G d „ d!e,¦  «        Z/ G d"„ d#e!¦  «        Z0d$„ Z1d%d%d%d%d&e,d'fd(„Z2d)„ Z3e4d*k    rmdd+l5m6Z6  e2¦   «           e7¦   «           e6d,¦  «        Z8 e,e8d-¬.¦  «        Z9d/Z:e: ;                    ¦   «         Z<e9 =                    e<¦  «        Z>e>D ]Z? e7e?¦  «         Œd0S d0S )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                   ó`   ‡ — e Zd ZdZdd„Zed„ ¦   «         Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zˆ fd„Zˆ xZS )ÚFeatureTreeEdgea  
    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``.
    r   Nc                 ó<  ‡ ‡— ‰€i Š|t          |¦  «        k    r)‰r'‰                      |‰¦  «        }ˆˆ fd„|D ¦   «         }i Št          j        ‰ ||||¦  «         ‰‰ _        ‰ j        t          t          ‰                     ¦   «         ¦  «        ¦  «        f‰ _        dS )az  
        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.
        Nc                 ó<   •— g | ]}‰                      |‰¦  «        ‘ŒS © )Ú_bind)Ú.0ÚeltÚbindingsÚselfs     €€úK/var/www/piapp/venv/lib/python3.11/site-packages/nltk/parse/featurechart.pyú
<listcomp>z,FeatureTreeEdge.__init__.<locals>.<listcomp>N   s'   ø€ Ð<Ð<Ð<°�4—:’:˜c 8Ñ,Ô,Ð<Ð<Ð<ó    )	Úlenr!   r   Ú__init__Ú	_bindingsÚ_comparison_keyÚtupleÚsortedÚitems)r%   ÚspanÚlhsÚrhsÚdotr$   s   `    `r&   r*   zFeatureTreeEdge.__init__;   s¬   øø€ ð ÐØˆHð •#�c‘(”(Š?ˆ?˜xˆ?Ø—*’*˜S (Ñ+Ô+ˆCØ<Ð<Ð<Ð<Ð<¸Ð<Ñ<Ô<ˆCØˆHõ 	Ô˜$  c¨3°Ñ4Ô4Ð4Ø!ˆŒØ $Ô 4µe½FÀ8Ç>Â>ÑCSÔCSÑ<TÔ<TÑ6UÔ6UÐVˆÔÐÐr(   c                 ót   — t          ||f|                      ¦   «         |                      ¦   «         d¬¦  «        S )a)  
        :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   )r0   r1   r2   r3   )r   r1   r2   )Ú
productionÚindexs     r&   Úfrom_productionzFeatureTreeEdge.from_productionV   s=   € õ Ø˜� Z§^¢^Ñ%5Ô%5¸:¿>º>Ñ;KÔ;KÐQRð
ñ 
ô 
ð 	
r(   c                 óh   — t          | j        d         |f| j        | j        | j        dz   |¬¦  «        S )a€  
        :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   é   )r0   r1   r2   r3   r$   )r   Ú_spanÚ_lhsÚ_rhsÚ_dot)r%   Únew_endr$   s      r&   Úmove_dot_forwardz FeatureTreeEdge.move_dot_forwardc   s?   € õ Ø”*˜Q”- Ð)Ø”	Ø”	Ø”	˜A‘Øð
ñ 
ô 
ð 	
r(   c                 óZ   — t          |t          ¦  «        s|S |                     |¦  «        S ©N)Ú
isinstancer	   Úsubstitute_bindings)r%   Úntr$   s      r&   r!   zFeatureTreeEdge._bindv   s.   € Ý˜"Õ3Ñ4Ô4ð 	ØˆIØ×%Ò% hÑ/Ô/Ð/r(   c                 ó\   — |                       |                      ¦   «         | j        ¦  «        S rA   )r!   Únextsymr+   ©r%   s    r&   Únext_with_bindingsz"FeatureTreeEdge.next_with_bindings{   s    € Ø�zŠz˜$Ÿ,š,™.œ.¨$¬.Ñ9Ô9Ð9r(   c                 ó4   — | j                              ¦   «         S )zC
        Return a copy of this edge's bindings dictionary.
        )r+   ÚcopyrG   s    r&   r$   zFeatureTreeEdge.bindings~   s   € ð Œ~×"Ò"Ñ$Ô$Ð$r(   c                 ó   — t          | j        gt          | j        ¦  «        z   t          | j                             ¦   «         ¦  «        z   t          | j                             ¦   «         ¦  «        z   t          ¬¦  «        S )z`
        :return: The set of variables used by this edge.
        :rtype: set(Variable)
        ©Úfs_class)r   r;   Úlistr<   r+   ÚkeysÚvaluesr   rG   s    r&   Ú	variableszFeatureTreeEdge.variables„   su   € õ
 ØŒYˆKÝ�4”9‰oŒoñå�4”>×&Ò&Ñ(Ô(Ñ)Ô)ñ*õ �4”>×(Ò(Ñ*Ô*Ñ+Ô+ñ,õ  ð
ñ 
ô 
ð 	
r(   c                 óB  •— |                       ¦   «         r t          ¦   «                              ¦   «         S dd                     d„ t	          | j                             ¦   «         ¦  «        D ¦   «         ¦  «        z  }t          ¦   «                              ¦   «         › d|› �S )Nz{%s}z, c              3   ó    K  — | ]	}d |z  V — Œ
dS )z%s: %rNr    )r"   Úitems     r&   ú	<genexpr>z*FeatureTreeEdge.__str__.<locals>.<genexpr>•   s7   è è € ð *ð *Ø$(�˜4‘ð*ð *ð *ð *ð *ð *r(   Ú )Úis_completeÚsuperÚ__str__Újoinr.   r+   r/   )r%   r$   Ú	__class__s     €r&   rY   zFeatureTreeEdge.__str__‘   s›   ø€ Ø×ÒÑÔð 	5Ý‘7”7—?’?Ñ$Ô$Ð$à §	¢	ð *ð *Ý,2°4´>×3GÒ3GÑ3IÔ3IÑ,JÔ,Jð*ñ *ô *ñ !ô !ñ ˆHõ ‘g”g—o’oÑ'Ô'Ð4Ð4¨(Ð4Ð4Ð4r(   )r   NrA   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   Ústaticmethodr7   r?   r!   rH   r$   rQ   rY   Ú__classcell__)r[   s   @r&   r   r   .   sÅ   ø€ € € € € ð
ð 
ðWð Wð Wð Wð6 ð

ð 

ñ „\ð

ð
ð 
ð 
ð 
ð&0ð 0ð 0ð
:ð :ð :ð%ð %ð %ð
ð 
ð 
ð5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5r(   r   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zefd„Z	dS )ÚFeatureChartzQ
    A Chart for feature grammars.
    :see: ``Chart`` for more information.
    c                 ój  ‡ ‡— ‰i k    rt          ‰ j        ¦  «        S t          ‰                     ¦   «         ¦  «        }t	          |¦  «        }|‰ j        vr‰                      |¦  «         t	          ˆˆ fd„|D ¦   «         ¦  «        }t          ‰ j        |                              |g ¦  «        ¦  «        S )z¦
        Returns an iterator over the edges in this chart.
        See ``Chart.select`` for more information about the
        ``restrictions`` on the edges.
        c              3   óN   •K  — | ]}‰                      ‰|         ¦  «        V — Œ d S rA   )Ú_get_type_if_possible)r"   ÚkeyÚrestrictionsr%   s     €€r&   rU   z&FeatureChart.select.<locals>.<genexpr>º   sG   øè è € ð 
ð 
Ø>AˆD×&Ò& |°CÔ'8Ñ9Ô9ð
ð 
ð 
ð 
ð 
ð 
r(   )ÚiterÚ_edgesr.   rO   r-   Ú_indexesÚ
_add_indexÚget)r%   rh   Ú
restr_keysÚvalss   ``  r&   ÚselectzFeatureChart.select¨   sË   øø€ ð ˜2ÒÐÝ˜œÑ$Ô$Ð$õ ˜L×-Ò-Ñ/Ô/Ñ0Ô0ˆ
Ý˜:Ñ&Ô&ˆ
ð ˜Tœ]Ð*Ð*Ø�OŠO˜JÑ'Ô'Ð'åð 
ð 
ð 
ð 
ð 
ØEOð
ñ 
ô 
ñ 
ô 
ˆõ �D”M *Ô-×1Ò1°$¸Ñ;Ô;Ñ<Ô<Ð<r(   c                 ó  ‡ ‡— |D ])}t          t          |¦  «        st          d|z  ¦  «        ‚Œ*i x}‰ j        |<   ‰ j        D ]GŠt          ˆˆ fd„|D ¦   «         ¦  «        }|                     |g ¦  «                             ‰¦  «         ŒHdS )z‹
        A helper function for ``select``, which creates a new index for
        a given set of attributes (aka restriction keys).
        zBad restriction: %sc              3   ón   •K  — | ]/}‰                       t          ‰|¦  «        ¦   «         ¦  «        V — Œ0d S rA   ©rf   Úgetattr©r"   rg   Úedger%   s     €€r&   rU   z*FeatureChart._add_index.<locals>.<genexpr>Î   óU   øè è € ð ð ØEH�×*Ò*Ð+=­7°4¸Ñ+=Ô+=Ñ+?Ô+?Ñ@Ô@ðð ð ð ð ð r(   N)Úhasattrr   Ú
ValueErrorrk   rj   r-   Ú
setdefaultÚappend)r%   rn   rg   r6   ro   rv   s   `    @r&   rl   zFeatureChart._add_index¿   sÓ   øø€ ð ð 	>ð 	>ˆCÝ�5 #Ñ&Ô&ð >Ý Ð!6¸Ñ!<Ñ=Ô=Ð=ð>ð -/Ð.ˆ�”˜jÑ)ð ”Kð 	4ð 	4ˆDÝð ð ð ð ð ØLVðñ ô ñ ô ˆDð ×Ò˜T 2Ñ&Ô&×-Ò-¨dÑ3Ô3Ð3Ð3ð		4ð 	4r(   c                 óÒ   ‡ ‡— ‰ j                              ¦   «         D ]J\  }}t          ˆˆ fd„|D ¦   «         ¦  «        }|                     |g ¦  «                             ‰¦  «         ŒKdS )zs
        A helper function for ``insert``, which registers the new
        edge with all existing indexes.
        c              3   ón   •K  — | ]/}‰                       t          ‰|¦  «        ¦   «         ¦  «        V — Œ0d S rA   rs   ru   s     €€r&   rU   z6FeatureChart._register_with_indexes.<locals>.<genexpr>Ù   rw   r(   N)rk   r/   r-   rz   r{   )r%   rv   rn   r6   ro   s   ``   r&   Ú_register_with_indexesz#FeatureChart._register_with_indexesÓ   s•   øø€ ð
 $(¤=×#6Ò#6Ñ#8Ô#8ð 	4ð 	4ÑˆZ˜Ýð ð ð ð ð ØLVðñ ô ñ ô ˆDð ×Ò˜T 2Ñ&Ô&×-Ò-¨dÑ3Ô3Ð3Ð3ð		4ð 	4r(   c                 ó\   — t          |t          ¦  «        rt          |v r|t                   S |S )z”
        Helper function which returns the ``TYPE`` feature of the ``item``,
        if it exists, otherwise it returns the ``item`` itself
        )rB   Údictr   )r%   rT   s     r&   rf   z"FeatureChart._get_type_if_possibleÞ   s-   € õ
 �d�DÑ!Ô!ð 	¥d¨d l lØ�”:ÐàˆKr(   c              #   óR  K  — |                       d| j        ¬¦  «        D ]‡}t          |t          ¦  «        rp|                     ¦   «         t
                   |t
                   k    rBt          |                     ¦   «         |d¬¦  «        r|                      |d|¬¦  «        E d {V —† Œˆd S )Nr   )ÚstartÚendT©Úrename_vars)ÚcompleteÚ
tree_class)rp   Ú_num_leavesrB   r   r1   r   r   Útrees)r%   r‚   r‡   rv   s       r&   ÚparseszFeatureChart.parsesè   s±   è è € Ø—K’K a¨TÔ-=�KÑ>Ô>ð 	Rð 	RˆDå˜D¥/Ñ2Ô2ðRà—X’X‘Z”Z¥Ô%¨­t¬Ò4Ð4Ý˜4Ÿ8š8™:œ: u¸$Ð?Ñ?Ô?ð 5ð  Ÿ:š: d°TÀj˜:ÑQÔQÐQÐQÐQÐQÐQÐQÐQøð	Rð 	Rr(   N)
r\   r]   r^   r_   rp   rl   r~   rf   r   rŠ   r    r(   r&   rc   rc   ¢   sy   € € € € € ðð ð
=ð =ð =ð.4ð 4ð 4ð(	4ð 	4ð 	4ðð ð ð (,ð Rð Rð Rð Rð Rð Rr(   rc   c                   ó   — e Zd ZdZd„ ZdS )ÚFeatureFundamentalRulea£  
    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              #   óf  K  — |                      ¦   «         |                     ¦   «         k    r=|                     ¦   «         r)|                     ¦   «         rt	          |t
          ¦  «        sd S |                     ¦   «         }|                     ¦   «         }t	          |t
          ¦  «        r§t          |¦  «        sd S |                     ¦   «         t                   |                     ¦   «         t                   k    rd S | 
                    ¦   «         }|                     |                     ¦   «         ¬¦  «        }t          |||d¬¦  «        }|€d S n||k    rd S | 
                    ¦   «         }|                     |                      ¦   «         |¦  «        }	|                     |	||¦  «        r|	V — d S d S )N©Ú	used_varsFr„   )rƒ   r‚   Úis_incompleterW   rB   r   r1   rF   r   r   r$   Úrename_variablesrQ   r   r?   Úinsert_with_backpointer)
r%   ÚchartÚgrammarÚ	left_edgeÚ
right_edgeÚfoundrF   r$   ÚresultÚnew_edges
             r&   ÚapplyzFeatureFundamentalRule.apply  s´  è è € ð �MŠM‰OŒO˜z×/Ò/Ñ1Ô1Ò1Ð1Ø×'Ò'Ñ)Ô)ð 2à×&Ò&Ñ(Ô(ð 2õ ˜9¥oÑ6Ô6ð 2ð
 ˆFØ—’Ñ Ô ˆØ×#Ò#Ñ%Ô%ˆÝ�j¥/Ñ2Ô2ð 	,Ý! 'Ñ*Ô*ð Ø�Ø× Ò Ñ"Ô"¥4Ô(¨J¯NªNÑ,<Ô,<½TÔ,BÒBÐBØ�à ×)Ò)Ñ+Ô+ˆHð ×*Ò*°Y×5HÒ5HÑ5JÔ5JÐ*ÑKÔKˆEõ ˜7 E¨8ÀÐGÑGÔGˆFØˆ~Ø�ð ð ˜%ÒÐØ�à ×)Ò)Ñ+Ô+ˆHð ×-Ò-¨j¯nªnÑ.>Ô.>ÀÑIÔIˆð ×(Ò(¨°9¸jÑIÔIð 	ØˆNˆNˆNˆNˆNð	ð 	r(   N©r\   r]   r^   r_   rš   r    r(   r&   rŒ   rŒ   ÷   s-   € € € € € ðð ð*%ð %ð %ð %ð %r(   rŒ   c                   ó2   — e Zd ZdZ e¦   «         Zd„ Zd„ ZdS )Ú FeatureSingleEdgeFundamentalRulezô
    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              #   óÒ   K  — | j         }|                     |                     ¦   «         d|                     ¦   «         ¬¦  «        D ] }|                     ||||¦  «        E d {V —† Œ!d S )NF)rƒ   rW   rF   )Ú_fundamental_rulerp   r‚   r1   rš   )r%   r“   r”   r–   Úfrr•   s         r&   Ú_apply_completez0FeatureSingleEdgeFundamentalRule._apply_complete?  sŠ   è è € ØÔ#ˆØŸšØ× Ò Ñ"Ô"°¸z¿~º~Ñ?OÔ?Oð &ñ 
ô 
ð 	Gð 	GˆIð —x’x  w°	¸:ÑFÔFÐFÐFÐFÐFÐFÐFÐFÐFð	Gð 	Gr(   c              #   óÒ   K  — | j         }|                     |                     ¦   «         d|                     ¦   «         ¬¦  «        D ] }|                     ||||¦  «        E d {V —† Œ!d S )NT)r‚   rW   r1   )rŸ   rp   rƒ   rF   rš   )r%   r“   r”   r•   r    r–   s         r&   Ú_apply_incompletez2FeatureSingleEdgeFundamentalRule._apply_incompleteF  sˆ   è è € ØÔ#ˆØŸ,š,Ø—-’-‘/”/¨t¸×9JÒ9JÑ9LÔ9Lð 'ñ 
ô 
ð 	Gð 	GˆJð —x’x  w°	¸:ÑFÔFÐFÐFÐFÐFÐFÐFÐFÐFð	Gð 	Gr(   N)r\   r]   r^   r_   rŒ   rŸ   r¡   r£   r    r(   r&   r�   r�   5  sU   € € € € € ðð ð /Ð.Ñ0Ô0ÐðGð Gð GðGð Gð Gð Gð Gr(   r�   c                   ó   — e Zd Zd„ ZdS )ÚFeatureTopDownInitRulec              #   óÊ   K  — |                      |                     ¦   «         ¬¦  «        D ]7}t                               |d¦  «        }|                     |d¦  «        r|V — Œ8d S )N©r1   r   r    )Úproductionsr‚   r   r7   Úinsert)r%   r“   r”   Úprodr™   s        r&   rš   zFeatureTopDownInitRule.applyT  sm   è è € Ø×'Ò'¨G¯MªM©O¬OÐ'Ñ<Ô<ð 	ð 	ˆDÝ&×6Ò6°t¸QÑ?Ô?ˆHØ�|Š|˜H bÑ)Ô)ð Ø���øð	ð 	r(   N©r\   r]   r^   rš   r    r(   r&   r¥   r¥   S  s#   € € € € € ðð ð ð ð r(   r¥   c                   ó   — e Zd ZdZd„ ZdS )ÚFeatureTopDownPredictRuleaÕ  
    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              #   ó:  K  — |                      ¦   «         rd S |                     ¦   «         |                     ¦   «         }}t          |¦  «        sd S |                     ¦   «         }| j                             ||fd¦  «        }|d         |u r|d         |u rd S |                     |¬¦  «        D ]Ý}|                     ¦   «         r\|                     ¦   «         d         }	t          |	¦  «        r3|| 
                    ¦   «         k    rŒX|	|                     |¦  «        k    rŒrt          |                     ¦   «         |d¬¦  «        rGt                               ||                     ¦   «         ¦  «        }
|                     |
d¦  «        r|
V — ŒÞ||f| j        ||f<   d S )N)NNr   r9   r§   Tr„   r    )rW   rF   rƒ   r   rH   Ú_donerm   r¨   r2   r   Ú
num_leavesÚleafr   r1   r   r7   r©   )r%   r“   r”   rv   rF   r6   Únextsym_with_bindingsÚdonerª   Úfirstr™   s              r&   rš   zFeatureTopDownPredictRule.applyn  s£  è è € Ø×ÒÑÔð 	ØˆFØŸš™œ¨¯ª©¬�ˆÝ˜gÑ&Ô&ð 	ØˆFð
 !%× 7Ò 7Ñ 9Ô 9ÐØŒz�~Š~Ð4°eÐ<¸lÑKÔKˆØ�Œ7�eÐÐ  Q¤¨7Ð 2Ð 2ØˆFà×'Ò'¨GÐ'Ñ4Ô4ð 	#ð 	#ˆDð �xŠx‰zŒzð !ØŸš™
œ
 1œ�Ý˜uÑ%Ô%ð !Ø × 0Ò 0Ñ 2Ô 2Ò2Ð2Ø Ø §
¢
¨5Ñ 1Ô 1Ò1Ð1Ø õ �T—X’X‘Z”ZÐ!6ÀDÐIÑIÔIð #Ý*×:Ò:¸4ÀÇÂÁÄÑLÔL�Ø—<’< ¨"Ñ-Ô-ð #Ø"�N�N�Nøð 5:¸7Ð3CˆŒ
Ð(¨%Ð/Ñ0Ð0Ð0r(   Nr›   r    r(   r&   r­   r­   [  s2   € € € € € ðð ð$"Dð "Dð "Dð "Dð "Dr(   r­   c                   ó   — e Zd Zd„ ZdS )ÚFeatureBottomUpPredictRulec              #   ó˜  K  — |                      ¦   «         rd S |                     |                     ¦   «         ¬¦  «        D ]ˆ}t          |t          ¦  «        r*|                     ¦   «         d         }t          |¦  «        sŒAt                               ||                     ¦   «         ¦  «        }| 	                    |d¦  «        r|V — Œ‰d S )N©r2   r   r    )
r�   r¨   r1   rB   r   r2   r   r7   r‚   r©   )r%   r“   r”   rv   rª   Ú_nextr™   s          r&   rš   z FeatureBottomUpPredictRule.apply™  sÄ   è è € Ø×ÒÑÔð 	ØˆFØ×'Ò'¨D¯HªH©J¬JÐ'Ñ7Ô7ð 	ð 	ˆDÝ˜$¥Ñ0Ô0ð ØŸš™
œ
 1œ�Ý% eÑ,Ô,ð Øå&×6Ò6°t¸T¿ZºZ¹\¼\ÑJÔJˆHØ�|Š|˜H bÑ)Ô)ð Ø���øð	ð 	r(   Nr«   r    r(   r&   r¶   r¶   ˜  s#   € € € € € ðð ð ð ð r(   r¶   c                   ó   — e Zd Zd„ ZdS )Ú!FeatureBottomUpPredictCombineRulec              #   óÆ  K  — |                      ¦   «         rd S |                     ¦   «         }|                     |¬¦  «        D �]}i }t          |t          ¦  «        r”|                     ¦   «         d         }t          |¦  «        sŒDt          |                     ¦   «         f|                     ¦   «         z   t          ¬¦  «        }| 	                    |¬¦  «        }t          |||d¬¦  «        }	|	€Œ®t                               ||                     ¦   «         ¦  «                             |                     ¦   «         |¦  «        }
|                     |
|f¦  «        r|
V — �Œd S )Nr¸   r   rL   rŽ   Fr„   )r�   r1   r¨   rB   r   r2   r   r   r   r‘   r   r7   r‚   r?   rƒ   r©   )r%   r“   r”   rv   r—   rª   r$   r¹   r�   r˜   r™   s              r&   rš   z'FeatureBottomUpPredictCombineRule.apply¨  sZ  è è € Ø×ÒÑÔð 	ØˆFØ—’‘
”
ˆØ×'Ò'¨EÐ'Ñ2Ô2ð 	ñ 	ˆDØˆHÝ˜$¥Ñ0Ô0ð ØŸš™
œ
 1œ�Ý% eÑ,Ô,ð Øõ +Ø—X’X‘Z”Z�M D§H¢H¡J¤JÑ.½ðñ ô �	ð ×.Ò.¸Ð.ÑCÔC�å˜u e¨XÀ5ÐIÑIÔI�Ø�>Øå&×6Ò6Ø�d—j’j‘l”lñô çÒ˜tŸxšx™zœz¨8Ñ4Ô4ð ð �|Š|˜H t gÑ.Ô.ð Ø���ùð-	ð 	r(   Nr«   r    r(   r&   r»   r»   §  s#   € € € € € ðð ð ð ð r(   r»   c                   ó   — e Zd Zd„ ZdS )ÚFeatureEmptyPredictRulec              #   óô   K  — |                      d¬¦  «        D ]^}t          |                     ¦   «         dz   ¦  «        D ]7}t                               ||¦  «        }|                     |d¦  «        r|V — Œ8Œ_d S )NT)Úemptyr9   r    )r¨   Úranger°   r   r7   r©   )r%   r“   r”   rª   r6   r™   s         r&   rš   zFeatureEmptyPredictRule.applyÆ  s’   è è € Ø×'Ò'¨dÐ'Ñ3Ô3ð 	#ð 	#ˆDÝ˜u×/Ò/Ñ1Ô1°AÑ5Ñ6Ô6ð #ð #�Ý*×:Ò:¸4ÀÑGÔG�Ø—<’< ¨"Ñ-Ô-ð #Ø"�N�N�Nøð#ð	#ð 	#r(   Nr«   r    r(   r&   r¾   r¾   Å  s#   € € € € € ð#ð #ð #ð #ð #r(   r¾   c                   ó   — e Zd Zedefd„ZdS )ÚFeatureChartParseré   c                 ó4   — t          j        | |f|||dœ|¤Ž d S )N)ÚstrategyÚtrace_chart_widthÚchart_class)r   r*   )r%   r”   rÆ   rÇ   rÈ   Úparser_argss         r&   r*   zFeatureChartParser.__init__ç  sH   € õ 	ÔØØð	
ð Ø/Ø#ð	
ð 	
ð ð	
ð 	
ð 	
ð 	
ð 	
r(   N)r\   r]   r^   ÚBU_LC_FEATURE_STRATEGYrc   r*   r    r(   r&   rÃ   rÃ   æ  s3   € € € € € ð (ØØ ð
ð 
ð 
ð 
ð 
ð 
r(   rÃ   c                   ó   — e Zd Zd„ ZdS )ÚFeatureTopDownChartParserc                 ó8   — t          j        | |t          fi |¤Ž d S rA   )rÃ   r*   ÚTD_FEATURE_STRATEGY©r%   r”   rÉ   s      r&   r*   z"FeatureTopDownChartParser.__init__ú  ó&   € ÝÔ# D¨'Õ3FÐVÐVÈ+ÐVÐVÐVÐVÐVr(   N©r\   r]   r^   r*   r    r(   r&   rÌ   rÌ   ù  ó(   € € € € € ðWð Wð Wð Wð Wr(   rÌ   c                   ó   — e Zd Zd„ ZdS )ÚFeatureBottomUpChartParserc                 ó8   — t          j        | |t          fi |¤Ž d S rA   )rÃ   r*   ÚBU_FEATURE_STRATEGYrÏ   s      r&   r*   z#FeatureBottomUpChartParser.__init__ÿ  rÐ   r(   NrÑ   r    r(   r&   rÔ   rÔ   þ  rÒ   r(   rÔ   c                   ó   — e Zd Zd„ ZdS )Ú$FeatureBottomUpLeftCornerChartParserc                 ó8   — t          j        | |t          fi |¤Ž d S rA   )rÃ   r*   rÊ   rÏ   s      r&   r*   z-FeatureBottomUpLeftCornerChartParser.__init__  s6   € ÝÔ#Ø�'Õ1ð	
ð 	
Ø5@ð	
ð 	
ð 	
ð 	
ð 	
r(   NrÑ   r    r(   r&   rØ   rØ     s#   € € € € € ð
ð 
ð 
ð 
ð 
r(   rØ   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚInstantiateVarsCharta?  
    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                 ó<   — t                                | |¦  «         d S rA   )rc   r*   )r%   Útokenss     r&   r*   zInstantiateVarsChart.__init__  s   € Ý×Ò˜d FÑ+Ô+Ð+Ð+Ð+r(   c                 ó`   — t          ¦   «         | _        t                               | ¦  «         d S rA   )ÚsetÚ_instantiatedrc   Ú
initializerG   s    r&   rá   zInstantiateVarsChart.initialize  s(   € Ý ™UœUˆÔÝ×Ò Ñ%Ô%Ð%Ð%Ð%r(   c                 óz   — || j         v rdS |                      |¦  «         t                               | ||¦  «        S )NF)rà   Úinstantiate_edgerc   r©   )r%   rv   Úchild_pointer_lists      r&   r©   zInstantiateVarsChart.insert  sB   € Ø�4Ô%Ð%Ð%Ø�5Ø×Ò˜dÑ#Ô#Ð#Ý×"Ò" 4¨Ð/AÑBÔBÐBr(   c                 ó4  — t          |t          ¦  «        sdS |                     ¦   «         sdS || j        v rdS |                      |¦  «        }|sdS | j                             |¦  «         |                     ¦   «                              |¦  «        |_	        dS )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   rW   Ú_edge_to_cplsÚ	inst_varsrà   Úaddr1   rC   r;   )r%   rv   rç   s      r&   rã   z%InstantiateVarsChart.instantiate_edge%  s¡   € õ ˜$¥Ñ0Ô0ð 	ØˆFØ×ÒÑ!Ô!ð 	ØˆFØ�4Ô%Ð%Ð%ØˆFð —N’N 4Ñ(Ô(ˆ	Øð 	ØˆFð 	Ô×Ò˜tÑ$Ô$Ð$Ø—H’H‘J”J×2Ò2°9Ñ=Ô=ˆŒ	ˆ	ˆ	r(   c                 ób   — d„ |                      ¦   «                              ¦   «         D ¦   «         S )Nc                 ój   — i | ]0}|j                              d ¦  «        ¯|t          j        ¦   «         “Œ1S )ú@)ÚnameÚ
startswithr   Úunique_variable)r"   Úvars     r&   ú
<dictcomp>z2InstantiateVarsChart.inst_vars.<locals>.<dictcomp>C  sI   € ð 
ð 
ð 
àØŒx×"Ò" 3Ñ'Ô'ð
Ø•Ô&Ñ(Ô(ð
ð 
ð 
r(   )r1   rQ   )r%   rv   s     r&   rç   zInstantiateVarsChart.inst_varsB  s7   € ð
ð 
à—x’x‘z”z×+Ò+Ñ-Ô-ð
ñ 
ô 
ð 	
r(   N)	r\   r]   r^   r_   r*   rá   r©   rã   rç   r    r(   r&   rÛ   rÛ     sl   € € € € € ðð ð,ð ,ð ,ð&ð &ð &ðCð Cð Cð>ð >ð >ð:
ð 
ð 
ð 
ð 
r(   rÛ   c                  ó8   — ddl m}  |                      d¦  «        S )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  s1   € Ø+Ð+Ð+Ð+Ð+Ð+à×$Ò$ð	ñô ð r(   Tr9   z$I saw John with a dog with my cookiec                 óz  — dd l }dd l}t          ¦   «          t          ¦   «         }	|rt          |	¦  «         t          ¦   «          t          d|j        ¦  «         |rt          d|¦  «         |                     ¦   «         }
t          ¦   «         } ||	|¬¦  «        }|                     |
¦  «        }t          | 	                    |	 
                    ¦   «         ¦  «        ¦  «        }| r!t          dt          ¦   «         |z
  z  ¦  «         |r|D ]}t          |¦  «         Œd S t          dt          |¦  «        ¦  «         d S )Nr   Ú*z	Sentence:©ÚtracezTime: %sz	Nr trees:)ÚsysÚtimeÚprintrö   r\   Úsplitr   Úchart_parserN   rŠ   r‚   r)   )Úprint_timesÚprint_grammarÚprint_treesÚprint_sentencerú   ÚparserÚsentrû   rü   r”   rÝ   ÚtÚcpr“   r‰   Útrees                   r&   Údemor	  j  s:  € ð €J€J€JØ€K€K€Kå	�G„G€GÝ‰nŒn€GØð Ýˆg‰ŒˆÝ‰ŒˆÝ	ˆ#ˆvŒÑÔÐØð !Ýˆk˜4Ñ Ô Ð Ø�ZŠZ‰\Œ\€FÝ‰Œ€AØ	ˆ�˜uÐ	%Ñ	%Ô	%€BØ�NŠN˜6Ñ"Ô"€EÝ�—’˜gŸmšm™oœoÑ.Ô.Ñ/Ô/€EØð 1Ýˆj�L™NœN¨QÑ.Ñ/Ñ0Ô0Ð0Øð 'Øð 	ð 	ˆDÝ�$‰KŒKˆKˆKð	ð 	õ 	ˆk�3˜u™:œ:Ñ&Ô&Ð&Ð&Ð&r(   c                  óX  — dd l } |                      dd¦  «         dd l}|                     d¦  «        }|                     ¦   «                              dd¦  «                             d¦  «         |                     ¦   «                              dd¦  «                             d¦  «         d S )Nr   zfor i in range(1): demo()z/tmp/profile.outrü   Úcumé<   )ÚprofileÚrunÚpstatsÚStatsÚ
strip_dirsÚ
sort_statsÚprint_stats)r  r  Úps      r&   Úrun_profiler  Œ  sš   € Ø€N€N€Nà‡K‚KÐ+Ð-?Ñ@Ô@Ð@Ø€M€M€Mà�ŠÐ'Ñ(Ô(€AØ‡L‚L�N„N×Ò˜f eÑ,Ô,×8Ò8¸Ñ<Ô<Ð<Ø‡L‚L�N„N×Ò˜e VÑ,Ô,×8Ò8¸Ñ<Ô<Ð<Ð<Ð<r(   Ú__main__)Úloadz!grammars/book_grammars/feat0.fcfgé   rù   zKim likes childrenN)@r_   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   rc   rŒ   r�   r¥   r­   r¶   r»   r¾   rÎ   rÖ   rÊ   rÃ   rÌ   rÔ   rØ   rÛ   rö   r	  r  r\   Ú	nltk.datar  rý   r”   r  r  rþ   rÝ   Úparser‰   r  r    r(   r&   ú<module>r     sv  ððð ð Ð Ð Ð Ð Ð à CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ Cðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðj5ð j5ð j5ð j5ð j5�hñ j5ô j5ð j5ðhMRð MRð MRð MRð MR�5ñ MRô MRð MRðj;ð ;ð ;ð ;ð ;˜_ñ ;ô ;ð ;ð|Gð Gð Gð Gð GÐ'@ñ Gô Gð Gð<ð ð ð ð ˜_ñ ô ð ð5Dð 5Dð 5Dð 5Dð 5DÐ 8ñ 5Dô 5Dð 5Dðzð ð ð ð Ð!4ñ ô ð ðð ð ð ð Ð(Bñ ô ð ð<#ð #ð #ð #ð #Ð.ñ #ô #ð #ð €L�N„NØÐÑÔØÐÑÔØ$Ð$Ñ&Ô&ð	Ð ð €L�N„NØÐÑÔØÐÑ Ô Ø$Ð$Ñ&Ô&ð	Ð ð €L�N„NØÐÑÔØ%Ð%Ñ'Ô'Ø$Ð$Ñ&Ô&ð	Ð ð
ð 
ð 
ð 
ð 
˜ñ 
ô 
ð 
ð&Wð Wð Wð Wð WÐ 2ñ Wô Wð Wð
Wð Wð Wð Wð WÐ!3ñ Wô Wð Wð

ð 
ð 
ð 
ð 
Ð+=ñ 
ô 
ð 
ð8
ð 8
ð 8
ð 8
ð 8
˜<ñ 8
ô 8
ð 8
ð@ð ð ð8 ØØØØ
ØØ	/ð'ð 'ð 'ð 'ðD=ð =ð =ð ˆzÒÐØÐÐÐÐÐà€D�F„F€FØ	€E�G„G€GØˆdÐ6Ñ7Ô7€GØ	Ð	˜G¨1Ð	-Ñ	-Ô	-€BØ€DØ�ZŠZ‰\Œ\€FØ�HŠH�VÑÔ€EØð ð ˆØˆˆd‰Œˆˆð Ððð r(   