| 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/__pycache__/ |
Upload File : |
�
T�cz� � �x � d Z ddlZddlmZ ddlmZmZmZmZm Z ddl
mZ ddlm
Z
ddlmZmZ e G d� d � � � � Zd
� Z G d� dee� � Zd
� Zd� Ze G d� d� � � � Z G d� de� � Z G d� dee
� � Z G d� d� � Z G d� de� � Ze G d� d� � � � Z G d� d� � Z G d� d� � Z G d� d e� � Zd!� Zd"� Z d#� Z!d$� Z" ej# d%ej$ � � Z% ej# d&ej$ � � Z& ej# d'ej$ � � Z' ej# d(ej$ � � Z(d9d*�Z)d:d+�Z* ej# d,ej$ � � Z+d-� Z, ej# d.ej$ � � Z- ej# d/� � Z.d0� Z/d1� Z0d2� Z1d3� Z2d4� Z3d5� Z4d6� Z5e6d7k r
e5� � g d8�Z7dS );a�
Basic data classes for representing context free grammars. A
"grammar" specifies which trees can represent the structure of a
given text. Each of these trees is called a "parse tree" for the
text (or simply a "parse"). In a "context free" grammar, the set of
parse trees for any piece of a text can depend only on that piece, and
not on the rest of the text (i.e., the piece's context). Context free
grammars are often used to find possible syntactic structures for
sentences. In this context, the leaves of a parse tree are word
tokens; and the node values are phrasal categories, such as ``NP``
and ``VP``.
The ``CFG`` class is used to encode context free grammars. Each
``CFG`` consists of a start symbol and a set of productions.
The "start symbol" specifies the root node value for parse trees. For example,
the start symbol for syntactic parsing is usually ``S``. Start
symbols are encoded using the ``Nonterminal`` class, which is discussed
below.
A Grammar's "productions" specify what parent-child relationships a parse
tree can contain. Each production specifies that a particular
node can be the parent of a particular set of children. For example,
the production ``<S> -> <NP> <VP>`` specifies that an ``S`` node can
be the parent of an ``NP`` node and a ``VP`` node.
Grammar productions are implemented by the ``Production`` class.
Each ``Production`` consists of a left hand side and a right hand
side. The "left hand side" is a ``Nonterminal`` that specifies the
node type for a potential parent; and the "right hand side" is a list
that specifies allowable children for that parent. This lists
consists of ``Nonterminals`` and text types: each ``Nonterminal``
indicates that the corresponding child may be a ``TreeToken`` with the
specified node type; and each text type indicates that the
corresponding child may be a ``Token`` with the with that type.
The ``Nonterminal`` class is used to distinguish node values from leaf
values. This prevents the grammar from accidentally using a leaf
value (such as the English word "A") as the node of a subtree. Within
a ``CFG``, all node values are wrapped in the ``Nonterminal``
class. Note, however, that the trees that are specified by the grammar do
*not* include these ``Nonterminal`` wrappers.
Grammars can also be given a more procedural interpretation. According to
this interpretation, a Grammar specifies any tree structure *tree* that
can be produced by the following procedure:
| Set tree to the start symbol
| Repeat until tree contains no more nonterminal leaves:
| Choose a production prod with whose left hand side
| lhs is a nonterminal leaf of tree.
| Replace the nonterminal leaf with a subtree, whose node
| value is the value wrapped by the nonterminal lhs, and
| whose children are the right hand side of prod.
The operation of replacing the left hand side (*lhs*) of a production
with the right hand side (*rhs*) in a tree (*tree*) is known as
"expanding" *lhs* to *rhs* in *tree*.
� N)�total_ordering)�SLASH�TYPE�FeatDict�
FeatStruct�FeatStructReader)�raise_unorderable_types)�ImmutableProbabilisticMixIn)�invert_graph�transitive_closurec �N � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� Z
dS )
�Nonterminala.
A non-terminal symbol for a context free grammar. ``Nonterminal``
is a wrapper class for node values; it is used by ``Production``
objects to distinguish node values from leaf values.
The node value that is wrapped by a ``Nonterminal`` is known as its
"symbol". Symbols are typically strings representing phrasal
categories (such as ``"NP"`` or ``"VP"``). However, more complex
symbol types are sometimes used (e.g., for lexicalized grammars).
Since symbols are node values, they must be immutable and
hashable. Two ``Nonterminals`` are considered equal if their
symbols are equal.
:see: ``CFG``, ``Production``
:type _symbol: any
:ivar _symbol: The node value corresponding to this
``Nonterminal``. This value must be immutable and hashable.
c � � || _ dS )z�
Construct a new non-terminal from the given symbol.
:type symbol: any
:param symbol: The node value corresponding to this
``Nonterminal``. This value must be immutable and
hashable.
N��_symbol)�self�symbols �./usr/lib/python3/dist-packages/nltk/grammar.py�__init__zNonterminal.__init__h s � � ����� c � � | j S )ze
Return the node value corresponding to this ``Nonterminal``.
:rtype: (any)
r �r s r r zNonterminal.symbols s � � �|�r c �b � t | � � t |� � k o| j |j k S )z�
Return True if this non-terminal is equal to ``other``. In
particular, return True if ``other`` is a ``Nonterminal``
and this non-terminal's symbol is equal to ``other`` 's symbol.
:rtype: bool
)�typer �r �others r �__eq__zNonterminal.__eq__{ s) � � �D�z�z�T�%�[�[�(�J�T�\�U�]�-J�Jr c � � | |k S �N� r s r �__ne__zNonterminal.__ne__� � � ��5�=� � r c �n � t |t � � st d| |� � | j |j k S �N�<)�
isinstancer r r r s r �__lt__zNonterminal.__lt__� s5 � ��%��-�-� 6�#�C��u�5�5�5��|�e�m�+�+r c �* � t | j � � S r )�hashr r s r �__hash__zNonterminal.__hash__� s � ��D�L�!�!�!r c �x � t | j t � � r
d| j z S dt | j � � z S �z_
Return a string representation for this ``Nonterminal``.
:rtype: str
�%s�r&