403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/nltk/parse/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/nltk/parse/__pycache__/earleychart.cpython-311.pyc
�

 T�c:E����dZddlmZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZmZmZmZmZmZmZmZGd�de��ZGd�dee��ZGd	�d
e��ZGd�de��ZGd
�de��ZGd�de��ZGd�de��Z Gd�de��Z!Gd�de��Z"Gd�de��Z#Gd�de��Z$e��e��e��e��e��gZ%e��e��e��e��gZ&e��e
��e��e��gZ'e��e
��e��e��gZ(e��e��e ��gZ)Gd�de��Z*Gd�de*��Z+Gd�d e*��Z,Gd!�d"e*��Z-Gd#�d$e*��Z.Gd%�d&e*��Z/e��e��e"��e#��e$��gZ0e��e��e��e!��gZ1e��e��e��e!��gZ2e��e��e��e!��gZ3Gd'�d(e*e��Z4Gd)�d*e4��Z5Gd+�d,e4��Z6Gd-�d.e4��Z7Gd/�d0e4��Z8						d9d6�Z9e:d7kre9��d8Sd8S):a�
Data classes and parser implementations for *incremental* chart
parsers, which use dynamic programming to efficiently parse a text.
A "chart parser" derives parse trees for a text by iteratively adding
"edges" to a "chart".  Each "edge" represents a hypothesis about the tree
structure for a subsequence of the text.  The "chart" is a
"blackboard" for composing and combining these hypotheses.

A parser is "incremental", if it guarantees that for all i, j where i < j,
all edges ending at i are built before any edges ending at j.
This is appealing for, say, speech recognizer hypothesis filtering.

The main parser class is ``EarleyChartParser``, which is a top-down
algorithm, originally formulated by Jay Earley (1970).
�)�perf_counter)
�BottomUpPredictCombineRule�BottomUpPredictRule�CachedTopDownPredictRule�Chart�ChartParser�EdgeI�EmptyPredictRule�"FilteredBottomUpPredictCombineRule�!FilteredSingleEdgeFundamentalRule�LeafEdge�LeafInitRule�SingleEdgeFundamentalRule�TopDownInitRule)�!FeatureBottomUpPredictCombineRule�FeatureBottomUpPredictRule�FeatureChart�FeatureChartParser�FeatureEmptyPredictRule� FeatureSingleEdgeFundamentalRule�FeatureTopDownInitRule�FeatureTopDownPredictRulec�>�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�IncrementalChartc��td�|���D����|_i|_i|_dS)Nc3�K�|]}gV��dS�N���.0�xs  �8/usr/lib/python3/dist-packages/nltk/parse/earleychart.py�	<genexpr>z.IncrementalChart.initialize.<locals>.<genexpr>@s"����>�>�q��>�>�>�>�>�>�)�tuple�
_positions�
_edgelists�
_edge_to_cpls�_indexes��selfs r"�
initializezIncrementalChart.initialize>sA���>�>�D�O�O�,=�,=�>�>�>�>�>��� �����
�
�
r$c�D�t|�����Sr)�list�	iteredgesr*s r"�edgeszIncrementalChart.edgesIs���D�N�N�$�$�%�%�%r$c�$�d�|jD��S)Nc3�$K�|]}|D]}|V���dSrr)r �edgelist�edges   r"r#z-IncrementalChart.iteredges.<locals>.<genexpr>Ms/����J�J���J�J���J�J�J�J�J�J�Jr$)r'r*s r"r/zIncrementalChart.iteredgesLs��J�J�T�_�J�J�J�Jr$c���|j|}�ikrt|��St������}t	|��}||jvr|�|��t	�fd�|D����}t|j||�|g����S)Nc3�(�K�|]}�|V��
dSrr)r �key�restrictionss  �r"r#z*IncrementalChart.select.<locals>.<genexpr>^s(�����=�=�3�\�#�&�=�=�=�=�=�=r$�r'�iter�sorted�keysr%r)�
_add_index�get�r+�endr8r3�
restr_keys�valss  `   r"�selectzIncrementalChart.selectOs�����?�3�'���2�����>�>�!��L�-�-�/�/�0�0�
��:�&�&�
��T�]�*�*��O�O�J�'�'�'��=�=�=�=�*�=�=�=�=�=���D�M�*�-�c�2�6�6�t�R�@�@�A�A�Ar$c���|D])}tt|��std|z����*td�|���D����x}|j|<t
|j��D]V\}}||}|D]F�t�fd�|D����}|�|g���	����G�WdS)N�Bad restriction: %sc3�K�|]}iV��dSrrrs  r"r#z.IncrementalChart._add_index.<locals>.<genexpr>h�"����1P�1P��"�1P�1P�1P�1P�1P�1Pr$c3�H�K�|]}t�|����V��dSr��getattr�r r7r4s  �r"r#z.IncrementalChart._add_index.<locals>.<genexpr>ns6�����H�H�c�/�W�T�3�/�/�1�1�H�H�H�H�H�Hr$�
�hasattrr	�
ValueErrorr%r&r)�	enumerater'�
setdefault�append�	r+rAr7�indexr@r3�
this_indexrBr4s	        @r"r=zIncrementalChart._add_indexas����	>�	>�C��5�#�&�&�
>� �!6��!<�=�=�=�
>�-2�1P�1P�d�o�o�>O�>O�1P�1P�1P�,P�,P�P���
�j�)�'�t��7�7�	=�	=�M�C���s��J� �
=�
=���H�H�H�H�Z�H�H�H�H�H���%�%�d�B�/�/�6�6�t�<�<�<�<�
=�	=�	=r$c�������}|j���D]O\}}t�fd�|D����}||�|g�������PdS)Nc3�H�K�|]}t�|����V��dSrrIrKs  �r"r#z:IncrementalChart._register_with_indexes.<locals>.<genexpr>ts6�����D�D�#�+���s�+�+�-�-�D�D�D�D�D�Dr$�r@r)�itemsr%rPrQ�r+r4r@rArSrBs `    r"�_register_with_indexesz'IncrementalChart._register_with_indexesqs�����h�h�j�j��#'�=�#6�#6�#8�#8�	9�	9��Z���D�D�D�D��D�D�D�D�D�D��#�J�!�!�$��+�+�2�2�4�8�8�8�8�	9�	9r$c�j�|j|����|��dSr)r'r@rQ)r+r4s  r"�_append_edgezIncrementalChart._append_edgews+�������
�
�#�*�*�4�0�0�0�0�0r$c�J�t|���dz��S)N�)�range�
num_leavesr*s r"r&zIncrementalChart._positionszs���T�_�_�&�&��*�+�+�+r$N)�__name__�
__module__�__qualname__r,r0r/rCr=rZr\r&rr$r"rr=s�������	�	�	�&�&�&�K�K�K�B�B�B�$=�=�=� 9�9�9�1�1�1�,�,�,�,�,r$rc� �eZdZd�Zd�Zd�ZdS)�FeatureIncrementalChartc�����j|}�ikrt|��St������}t	|��}|�jvr��|��t	��fd�|D����}t�j||�|g����S)Nc3�N�K�|]}���|��V�� dSr)�_get_type_if_possible)r r7r8r+s  ��r"r#z1FeatureIncrementalChart.select.<locals>.<genexpr>�sG�����
�
�>A�D�&�&�|�C�'8�9�9�
�
�
�
�
�
r$r9r?s` `   r"rCzFeatureIncrementalChart.selects������?�3�'���2�����>�>�!��L�-�-�/�/�0�0�
��:�&�&�
��T�]�*�*��O�O�J�'�'�'��
�
�
�
�
�EO�
�
�
�
�
���D�M�*�-�c�2�6�6�t�R�@�@�A�A�Ar$c����|D])}tt|��std|z����*td�����D����x}�j|<t
�j��D]W\}}||}|D]G�t��fd�|D����}|�|g���	����H�XdS)NrEc3�K�|]}iV��dSrrrs  r"r#z5FeatureIncrementalChart._add_index.<locals>.<genexpr>�rGr$c3�n�K�|]/}��t�|������V��0dSr�rhrJ�r r7r4r+s  ��r"r#z5FeatureIncrementalChart._add_index.<locals>.<genexpr>�sX���������.�.�/A�w�t�S�/A�/A�/C�/C�D�D������r$rLrRs	`       @r"r=z"FeatureIncrementalChart._add_index�s�����	>�	>�C��5�#�&�&�
>� �!6��!<�=�=�=�
>�-2�1P�1P�d�o�o�>O�>O�1P�1P�1P�,P�,P�P���
�j�)�'�t��7�7�	=�	=�M�C���s��J� �
=�
=��������)��������%�%�d�B�/�/�6�6�t�<�<�<�<�
=�	=�	=r$c��������}�j���D]P\}}t��fd�|D����}||�|g�������QdS)Nc3�n�K�|]/}��t�|������V��0dSrrlrms  ��r"r#zAFeatureIncrementalChart._register_with_indexes.<locals>.<genexpr>�sU�������EH��*�*�+=�7�4��+=�+=�+?�+?�@�@������r$rWrYs``    r"rZz.FeatureIncrementalChart._register_with_indexes�s������h�h�j�j��#'�=�#6�#6�#8�#8�	9�	9��Z��������LV������D�
�#�J�!�!�$��+�+�2�2�4�8�8�8�8�		9�	9r$N)rarbrcrCr=rZrr$r"rere~sD������B�B�B�(=�=�=�&9�9�9�9�9r$rec��eZdZd�ZdS)�CompleteFundamentalRulec#�K�|���}|�||d|������D]D}|�|�����}|�|||��r|V��EdS�NT)�startr@�is_complete�lhs)r@rC�nextsym�move_dot_forward�insert_with_backpointer)r+�chart�grammar�	left_edger@�
right_edge�new_edges       r"�_apply_incompletez)CompleteFundamentalRule._apply_incomplete�s������m�m�o�o�� �,�,��3�D�i�6G�6G�6I�6I�'�
�
�	�	�J�!�1�1�*�.�.�2B�2B�C�C�H��,�,�X�y�*�M�M�
������	�	r$N�rarbrcrrr$r"rqrq�s#������	�	�	�	�	r$rqc�(�eZdZe��Zd�ZdS)�
CompleterRulec#�|K�t|t��s$|j�|||��Ed{V��dSdSr��
isinstancer
�_fundamental_rule�apply�r+rzr{r4s    r"r�zCompleterRule.apply�sX�����$��)�)�	J��-�3�3�E�7�D�I�I�I�I�I�I�I�I�I�I�I�	J�	Jr$N�rarbrcrqr�r�rr$r"r�r���7������/�/�1�1��J�J�J�J�Jr$r�c�(�eZdZe��Zd�ZdS)�ScannerRulec#�|K�t|t��r$|j�|||��Ed{V��dSdSrr�r�s    r"r�zScannerRule.apply�sX�����d�H�%�%�	J��-�3�3�E�7�D�I�I�I�I�I�I�I�I�I�I�I�	J�	Jr$Nr�rr$r"r�r��r�r$r�c��eZdZdS)�
PredictorRuleN�rarbrcrr$r"r�r����������Dr$r�c��eZdZd�ZdS)�FilteredCompleteFundamentalRulec#�pK�|���r|�|||��Ed{V��dSdSr)ru�_apply_completer�s    r"r�z%FilteredCompleteFundamentalRule.apply�sY���������	B��+�+�E�7�D�A�A�A�A�A�A�A�A�A�A�A�	B�	Br$N)rarbrcr�rr$r"r�r��s(������B�B�B�B�Br$r�c��eZdZd�ZdS)�FeatureCompleteFundamentalRulec#��K�|j}|���}|�||d|������D] }|�||||��Ed{V���!dSrs)r�r@rCrwr�)r+rzr{r|�frr@r}s       r"rz0FeatureCompleteFundamentalRule._apply_incomplete�s�����
�
#���m�m�o�o�� �,�,��3�D�i�6G�6G�6I�6I�'�
�
�	G�	G�J��x�x��w�	�:�F�F�F�F�F�F�F�F�F�F�	G�	Gr$Nr�rr$r"r�r��s(������G�G�G�G�Gr$r�c�"�eZdZe��ZdS)�FeatureCompleterRuleN�rarbrcr�r�rr$r"r�r���������6�6�8�8���r$r�c�"�eZdZe��ZdS)�FeatureScannerRuleNr�rr$r"r�r��r�r$r�c��eZdZdS)�FeaturePredictorRuleNr�rr$r"r�r��r�r$r�c�*�eZdZdZeddefd�Zdd�ZdS)�IncrementalChartParsera
    An *incremental* chart parser implementing Jay Earley's
    parsing algorithm:

    | For each index end in [0, 1, ..., N]:
    |   For each edge such that edge.end = end:
    |     If edge is incomplete and edge.next is not a part of speech:
    |       Apply PredictorRule to edge
    |     If edge is incomplete and edge.next is a part of speech:
    |       Apply ScannerRule to edge
    |     If edge is complete:
    |       Apply CompleterRule to edge
    | Return any complete parses in the chart
    r�2c��||_||_||_||_g|_g|_|D]\}|jdkr|j�|���(|jdkr|j�|���Ntd���dS)a�
        Create a new Earley chart parser, that uses ``grammar`` to
        parse texts.

        :type grammar: CFG
        :param grammar: The grammar used to parse texts.
        :type trace: int
        :param trace: The level of tracing that should be used when
            parsing a text.  ``0`` will generate no tracing output;
            and higher numbers will produce more verbose tracing
            output.
        :type trace_chart_width: int
        :param trace_chart_width: The default total width reserved for
            the chart in trace output.  The remainder of each line will
            be used to display edges.
        :param chart_class: The class that should be used to create
            the charts used by this parser.
        rr^z9Incremental inference rules must have NUM_EDGES == 0 or 1N)	�_grammar�_trace�_trace_chart_width�_chart_class�_axioms�_inference_rules�	NUM_EDGESrQrN)r+r{�strategy�trace�trace_chart_width�chart_class�rules       r"�__init__zIncrementalChartParser.__init__/s���4 ��
����"3���'������ "����	�	�D��~��"�"���#�#�D�)�)�)�)���1�$�$��%�,�,�T�2�2�2�2� �R����
	�	r$Nc	��|�|j}|j}t|��}|j�|��|�|��}|j}|j|���dzz}|r"t|�	|����|j
D]4}t|�||����}||||||���5|j}	t|���dz��D]�}
|dkrtd|
d��t|�|
�����}|r�|���}|	D]g}
t|
�|||����}|||
|||��|D]/}|���|
kr|�|���0�h|����|S)Nr^z
* Processing queue:�
)r@)r��_trace_new_edgesr.r��check_coverager�r�r`�print�pretty_format_leavesr�r�r�r_rC�popr@rQ)r+�tokensr��trace_new_edgesrzr{�trace_edge_width�axiom�	new_edges�inference_rulesr@�agendar4r�r~s               r"�chart_parsez"IncrementalChartParser.chart_parseZs����=��K�E��/���f�����
�$�$�V�,�,�,��!�!�&�)�)���-�� �2�u�7G�7G�7I�7I�A�7M�N���	@��%�,�,�-=�>�>�?�?�?��\�	N�	N�E��U�[�[���8�8�9�9�I��O�E�5�)�U�<L�M�M�M�M��/����)�)�+�+�a�/�0�0�	4�	4�C��q�y�y��-�s�D�9�9�9��%�,�,�3�,�/�/�0�0�F��
4��z�z�|�|��+�4�4�D� $�T�Z�Z��w��%E�%E� F� F�I�#�O�E�4��E�CS�T�T�T�$-�4�4��#�<�<�>�>�S�0�0�"�M�M�(�3�3�3��4��
4���r$r)rarbrc�__doc__�BU_LC_INCREMENTAL_STRATEGYrr�r�rr$r"r�r�sU������
�
�$,���$�
)�)�)�)�V!�!�!�!�!�!r$r�c��eZdZd�ZdS)�EarleyChartParserc�8�tj||tfi|��dSr)r�r��EARLEY_STRATEGY�r+r{�parser_argss   r"r�zEarleyChartParser.__init__s%���'��g��V�V�+�V�V�V�V�Vr$N�rarbrcr�rr$r"r�r�~s(������W�W�W�W�Wr$r�c��eZdZd�ZdS)�IncrementalTopDownChartParserc�8�tj||tfi|��dSr)r�r��TD_INCREMENTAL_STRATEGYr�s   r"r�z&IncrementalTopDownChartParser.__init__��6���'��'�2�	
�	
�6A�	
�	
�	
�	
�	
r$Nr�rr$r"r�r���#������
�
�
�
�
r$r�c��eZdZd�ZdS)�IncrementalBottomUpChartParserc�8�tj||tfi|��dSr)r�r��BU_INCREMENTAL_STRATEGYr�s   r"r�z'IncrementalBottomUpChartParser.__init__�r�r$Nr�rr$r"r�r��r�r$r�c��eZdZd�ZdS)�(IncrementalBottomUpLeftCornerChartParserc�8�tj||tfi|��dSr)r�r�r�r�s   r"r�z1IncrementalBottomUpLeftCornerChartParser.__init__�s6���'��'�5�	
�	
�9D�	
�	
�	
�	
�	
r$Nr�rr$r"r�r��r�r$r�c��eZdZd�ZdS)� IncrementalLeftCornerChartParserc�~�|���std���tj||tfi|��dS)NzNIncrementalLeftCornerParser only works for grammars without empty productions.)�is_nonemptyrNr�r��LC_INCREMENTAL_STRATEGYr�s   r"r�z)IncrementalLeftCornerChartParser.__init__�sc���"�"�$�$�	��-���
�	�'��'�2�	
�	
�6A�	
�	
�	
�	
�	
r$Nr�rr$r"r�r��s#������
�
�
�
�
r$r�c��eZdZedefd�ZdS)�FeatureIncrementalChartParser�c�4�tj||f|||d�|��dS)N)r�r�r�)r�r�)r+r{r�r�r�r�s      r"r�z&FeatureIncrementalChartParser.__init__�sH��	�'���	
��/�#�	
�	
��
	
�	
�	
�	
�	
r$N)rarbrc�"BU_LC_INCREMENTAL_FEATURE_STRATEGYrer�rr$r"r�r��s3������4��+�
�
�
�
�
�
r$r�c��eZdZd�ZdS)�FeatureEarleyChartParserc�8�tj||tfi|��dSr)r�r��EARLEY_FEATURE_STRATEGYr�s   r"r�z!FeatureEarleyChartParser.__init__�s6��%�.��'�2�	
�	
�6A�	
�	
�	
�	
�	
r$Nr�rr$r"r�r��r�r$r�c��eZdZd�ZdS)�$FeatureIncrementalTopDownChartParserc�8�tj||tfi|��dSr)r�r��TD_INCREMENTAL_FEATURE_STRATEGYr�s   r"r�z-FeatureIncrementalTopDownChartParser.__init__��6��%�.��'�:�	
�	
�>I�	
�	
�	
�	
�	
r$Nr�rr$r"r�r��r�r$r�c��eZdZd�ZdS)�%FeatureIncrementalBottomUpChartParserc�8�tj||tfi|��dSr)r�r��BU_INCREMENTAL_FEATURE_STRATEGYr�s   r"r�z.FeatureIncrementalBottomUpChartParser.__init__�r�r$Nr�rr$r"r�r��r�r$r�c��eZdZd�ZdS)�/FeatureIncrementalBottomUpLeftCornerChartParserc�8�tj||tfi|��dSr)r�r�r�r�s   r"r�z8FeatureIncrementalBottomUpLeftCornerChartParser.__init__�s6��%�.��'�=�	
�	
�AL�	
�	
�	
�	
�	
r$Nr�rr$r"r�r��r�r$r�TF��$I saw John with a dog with my cookie�c���ddl}ddl}ddlm}|��}	|rt	d��t	|	��t	d��t	|��|���}
t	|
��t	��t
|	|���}t��}|�|
��}
t|
�
|	�������}t��|z
}|rt|��|ks
Jd���|r|D]}t	|���nt	dt|����|rt	d	|��dSdS)
z0
    A demonstration of the Earley parsers.
    rN)�demo_grammarz	* Grammarz* Sentence:)r�zNot all parses foundz	Nr trees:zTime:)
�sys�time�nltk.parse.chartr�r��splitr�rr�r.�parsesrt�len)�print_times�
print_grammar�print_treesr��sent�	numparsesr�r�r�r{r��earley�trzr��trees                r"�demor�s����J�J�J��K�K�K�-�-�-�-�-�-��l�n�n�G���
�k����
�g����
�-����	�$�K�K�K�
�Z�Z�\�\�F�	�&�M�M�M�	�G�G�G��w�e�
4�
4�
4�F����A����v�&�&�E�
�%�,�,�w�}�}���/�/�
0�
0�F������A��@��6�{�{�i�'�'�'�)?�'�'�'��(��	�	�D��$�K�K�K�K�	�	�k�3�v�;�;�'�'�'���
�g�q�������r$�__main__N)TFTr�r�r�);r�r�rr�rrrrrr	r
rrr
rrr�nltk.parse.featurechartrrrrrrrrrrerqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrarr$r"�<module>rs?���� ������������������������������������	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	� >,�>,�>,�>,�>,�u�>,�>,�>,�B.9�.9�.9�.9�.9�.��.9�.9�.9�l
�
�
�
�
�7�
�
�
�J�J�J�J�J�+�J�J�J�J�J�J�J�J�)�J�J�J�	�	�	�	�	�,�	�	�	�B�B�B�B�B�&G�B�B�B�	G�	G�	G�	G�	G�%E�	G�	G�	G�9�9�9�9�9�=�9�9�9�9�9�9�9�9��9�9�9�	�	�	�	�	�4�	�	�	��L�N�N��O����M�O�O��K�M�M��M�O�O����L�N�N��O�����������	���L�N�N�������������	���L�N�N������� � �����	���L�N�N�&�&�(�(�#�#�%�%���\�\�\�\�\�[�\�\�\�~W�W�W�W�W�.�W�W�W�

�
�
�
�
�$:�
�
�
�
�
�
�
�
�%;�
�
�
�
�
�
�
�
�/E�
�
�
�	
�	
�	
�	
�	
�'=�	
�	
�	
�"�L�N�N��������������������L�N�N���������"�"�$�$�	#���L�N�N������� � �"�"�$�$�	#���L�N�N�����%�%�'�'�"�"�$�$�	&�"�
�
�
�
�
�$:�<N�
�
�
�&
�
�
�
�
�<�
�
�
�
�
�
�
�
�+H�
�
�
�
�
�
�
�
�,I�
�
�
�
�
�
�
�
�6S�
�
�
����
�	/��
-�-�-�-�`�z����D�F�F�F�F�F��r$

Youez - 2016 - github.com/yon3zu
LinuXploit