| 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 : /usr/lib/python3/dist-packages/nltk/tree/__pycache__/ |
Upload File : |
�
T�c�� � �\ � d Z ddlZddlmZmZ ddlmZ G d� de� � Zd� Z d� Z
dgZdS ) zh
Class for representing hierarchical language structures, such as
syntax trees and morphological trees.
� N)�Nonterminal�
Production)�
deprecatedc � � e Zd ZdZdAd�Zd� Zd� Zd� Zd� Zd� Z d � Z
d
� Zd� Zd� Z
d
� Zd� Zd� Zd� Z ed� � d� � � Z ed� � d� � � Z eee� � Zd� Zd� Zd� Zd� Zd� ZdBd�ZdAd�Zd� Zd� Zd� Z d � Z! dCd%�Z" dDd(�Z#dEd*�Z$e%d+� � � Z&d,� Z'd-� Z(dFd.�Z)d/� Z*dAd0�Z+e% dGd2�� � Z,e%d3� � � Z-e%d4� � � Z.d5� Z/dHd7�Z0d8� Z1d9� Z2d:� Z3d;� Z4dId>�Z5d?� Z6d@� Z7dS )J�Treeai
A Tree represents a hierarchical grouping of leaves and subtrees.
For example, each constituent in a syntax tree is represented by a single Tree.
A tree's children are encoded as a list of leaves and subtrees,
where a leaf is a basic (non-tree) value; and a subtree is a
nested Tree.
>>> from nltk.tree import Tree
>>> print(Tree(1, [2, Tree(3, [4]), 5]))
(1 2 (3 4) 5)
>>> vp = Tree('VP', [Tree('V', ['saw']),
... Tree('NP', ['him'])])
>>> s = Tree('S', [Tree('NP', ['I']), vp])
>>> print(s)
(S (NP I) (VP (V saw) (NP him)))
>>> print(s[1])
(VP (V saw) (NP him))
>>> print(s[1,1])
(NP him)
>>> t = Tree.fromstring("(S (NP I) (VP (V saw) (NP him)))")
>>> s == t
True
>>> t[1][1].set_label('X')
>>> t[1][1].label()
'X'
>>> print(t)
(S (NP I) (VP (V saw) (X him)))
>>> t[0], t[1,1] = t[1,1], t[0]
>>> print(t)
(S (X him) (VP (V saw) (NP I)))
The length of a tree is the number of children it has.
>>> len(t)
2
The set_label() and label() methods allow individual constituents
to be labeled. For example, syntax trees use this label to specify
phrase tags, such as "NP" and "VP".
Several Tree methods use "tree positions" to specify
children or descendants of a tree. Tree positions are defined as
follows:
- The tree position *i* specifies a Tree's *i*\ th child.
- The tree position ``()`` specifies the Tree itself.
- If *p* is the tree position of descendant *d*, then
*p+i* specifies the *i*\ th child of *d*.
I.e., every tree position is either a single index *i*,
specifying ``tree[i]``; or a sequence *i1, i2, ..., iN*,
specifying ``tree[i1][i2]...[iN]``.
Construct a new tree. This constructor can be called in one
of two ways:
- ``Tree(label, children)`` constructs a new tree with the
specified label and list of children.
- ``Tree.fromstring(s)`` constructs a new tree by parsing the string ``s``.
Nc � � |�$t dt | � � j z � � �t |t � � r$t dt | � � j z � � �t
� | |� � || _ d S )Nz)%s: Expected a node value and child list z.%s() argument 2 should be a list, not a string)� TypeError�type�__name__�
isinstance�str�list�__init__�_label)�self�node�childrens �0/usr/lib/python3/dist-packages/nltk/tree/tree.pyr z
Tree.__init__\ s� � ����;�d�4�j�j�>Q�Q�� �
� ��#�
&�
&� �����:�:�.�/�� �
�
�M�M�$��)�)�)��D�K�K�K� c �z � | j |j u o-| j t | � � f|j t |� � fk S �N)� __class__r r �r �others r �__eq__zTree.__eq__n s@ � ��~���0�
�d�k�4��:�:�5N��L���K�K�S
� 6
�
r c � � t |t � � s| j j |j j k S | j |j u r.| j t | � � f|j t |� � fk S | j j |j j k S r )r r r r r r r s r �__lt__zTree.__lt__t su � ��%��&�&� F� �>�*�U�_�-E�E�E�
�^�u��
.�
.��K��d���,���d�5�k�k�/J�J�J��>�*�U�_�-E�E�Er c � � | |k S r � r s r �<lambda>z
Tree.<lambda>� s
� �T�U�]�!2� r c � � | |k p| |k S r r r s r r z
Tree.<lambda>� s � �d�U�l�&C�d�e�m�!D� r c � � | |k p| |k S r r r s r r z
Tree.<lambda>� s � ����!>���� r c � � | |k S r r r s r r z
Tree.<lambda>� s
� �T�E�\�!1� r c � � t d� � ��Nz$Tree does not support multiplication�r �r �vs r �__mul__zTree.__mul__� � � ��>�?�?�?r c � � t d� � �r% r&