| 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/__pycache__/ |
Upload File : |
�
T�c�� � � � d Z ddlZddlZddlmZ ddlmZmZ ddlm Z m
Z
mZmZm
Z
e G d� de� � � � ZdZd ZdTd�Z G d� d
ee� � Z G d� dee� � ZdUd�Zd� ZdUd�Zd� ZdUd�Zd� Z dVd�Zd� Zd� ZdUd�Zd� Z G d� d� � Z! e!� � Z" dWd!�Z# G d"� d#e$� � Z%d$� Z&d%� Z'd&� Z(d'� Z)d(� Z*d)� Z+d*� Z,d+� Z-d,� Z.d-� Z/d.� Z0d/� Z1dXd0�Z2d1� Z3d2� Z4d3� Z5 G d4� d5e� � Z6 G d6� d7e6e7� � Z8 G d8� d9e6e9� � Z: G d:� d;e6e9� � Z; G d<� d=e6e7� � Z<d>� Z=e G d?� d@� � � � Z> G dA� dBe>� � Z? G dC� dDe>� � Z@ e?dEddE�F� � ZA e>dGdH�I� � ZBe G dJ� dK� � � � ZC G dL� dM� � ZDdYdO�ZEdZdP�ZFdZdQ�ZGeHdRk r
eG� � g dS�ZIdS )[aY
Basic data classes for representing feature structures, and for
performing basic operations on those feature structures. A feature
structure is a mapping from feature identifiers to feature values,
where each feature value is either a basic value (such as a string or
an integer), or a nested feature structure. There are two types of
feature structure, implemented by two subclasses of ``FeatStruct``:
- feature dictionaries, implemented by ``FeatDict``, act like
Python dictionaries. Feature identifiers may be strings or
instances of the ``Feature`` class.
- feature lists, implemented by ``FeatList``, act like Python
lists. Feature identifiers are integers.
Feature structures are typically used to represent partial information
about objects. A feature identifier that is not mapped to a value
stands for a feature whose value is unknown (*not* a feature without
a value). Two feature structures that represent (potentially
overlapping) information about the same object can be combined by
unification. When two inconsistent feature structures are unified,
the unification fails and returns None.
Features can be specified using "feature paths", or tuples of feature
identifiers that specify path through the nested feature structures to
a value. Feature structures may contain reentrant feature values. A
"reentrant feature value" is a single feature value that can be
accessed via multiple feature paths. Unification preserves the
reentrance relations imposed by both of the unified feature
structures. In the feature structure resulting from unification, any
modifications to a reentrant feature value will be visible using any
of its feature paths.
Feature structure variables are encoded using the ``nltk.sem.Variable``
class. The variables' values are tracked using a bindings
dictionary, which maps variables to their values. When two feature
structures are unified, a fresh bindings dictionary is created to
track their values; and before unification completes, all bound
variables are replaced by their values. Thus, the bindings
dictionaries are usually strictly internal to the unification process.
However, it is possible to track the bindings of variables if you
choose to, by supplying your own initial bindings dictionary to the
``unify()`` function.
When unbound variables are unified with one another, they become
aliased. This is encoded by binding one variable to the other.
Lightweight Feature Structures
==============================
Many of the functions defined by ``nltk.featstruct`` can be applied
directly to simple Python dictionaries and lists, rather than to
full-fledged ``FeatDict`` and ``FeatList`` objects. In other words,
Python ``dicts`` and ``lists`` can be used as "light-weight" feature
structures.
>>> from nltk.featstruct import unify
>>> unify(dict(x=1, y=dict()), dict(a='a', y=dict(b='b'))) # doctest: +SKIP
{'y': {'b': 'b'}, 'x': 1, 'a': 'a'}
However, you should keep in mind the following caveats:
- Python dictionaries & lists ignore reentrance when checking for
equality between values. But two FeatStructs with different
reentrances are considered nonequal, even if all their base
values are equal.
- FeatStructs can be easily frozen, allowing them to be used as
keys in hash tables. Python dictionaries and lists can not.
- FeatStructs display reentrance in their string representations;
Python dictionaries and lists do not.
- FeatStructs may *not* be mixed with Python dictionaries and lists
(e.g., when performing unification).
- FeatStructs provide a number of useful methods, such as ``walk()``
and ``cyclic()``, which are not available for Python dicts and lists.
In general, if your feature structures will contain any reentrances,
or if you plan to use them as dictionary keys, it is strongly
recommended that you use full-fledged ``FeatStruct`` objects.
� N)�total_ordering)�raise_unorderable_types�read_str)�
Expression�LogicalExpressionException�LogicParser�SubstituteBindingsI�Variablec �� � � e Zd ZdZdZ d%� fd� Zd� Zd� Zd� Zd&d�Z d � Z
d
� Zd� Zd� Z
d
� Zd� ZdZd� Zd� Zd� Zd'd�Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd(d�Zd � Zd)d!�Zd"� Z d#� Z!d$� Z"� xZ#S )*�
FeatStructa�
A mapping from feature identifiers to feature values, where each
feature value is either a basic value (such as a string or an
integer), or a nested feature structure. There are two types of
feature structure:
- feature dictionaries, implemented by ``FeatDict``, act like
Python dictionaries. Feature identifiers may be strings or
instances of the ``Feature`` class.
- feature lists, implemented by ``FeatList``, act like Python
lists. Feature identifiers are integers.
Feature structures may be indexed using either simple feature
identifiers or 'feature paths.' A feature path is a sequence
of feature identifiers that stand for a corresponding sequence of
indexing operations. In particular, ``fstruct[(f1,f2,...,fn)]`` is
equivalent to ``fstruct[f1][f2]...[fn]``.
Feature structures may contain reentrant feature structures. A
"reentrant feature structure" is a single feature structure
object that can be accessed via multiple feature paths. Feature
structures may also be cyclic. A feature structure is "cyclic"
if there is any feature path from the feature structure to itself.
Two feature structures are considered equal if they assign the
same values to all features, and have the same reentrancies.
By default, feature structures are mutable. They may be made
immutable with the ``freeze()`` method. Once they have been
frozen, they may be hashed, and thus used as dictionary keys.
FNc �2 �� | t u r�|�t j t fi |��S t |� � rt j t |fi |��S |rt d� � �t |t � � rOt j � |� � rt j t |fi |��S t j t |fi |��S t |� � r t � t |� � S t d� � � t � � j | |fi |��S )a�
Construct and return a new feature structure. If this
constructor is called directly, then the returned feature
structure will be an instance of either the ``FeatDict`` class
or the ``FeatList`` class.
:param features: The initial feature values for this feature
structure:
- FeatStruct(string) -> FeatStructReader().read(string)
- FeatStruct(mapping) -> FeatDict(mapping)
- FeatStruct(sequence) -> FeatList(sequence)
- FeatStruct() -> FeatDict()
:param morefeatures: If ``features`` is a mapping or None,
then ``morefeatures`` provides additional features for the
``FeatDict`` constructor.
NzLKeyword arguments may only be specified if features is None or is a mapping.z&Expected string or mapping or sequence)
r �FeatDict�__new__�_is_mapping� TypeError�
isinstance�str�FeatStructReader�_START_FDICT_RE�match�FeatList�_is_sequence�super)�cls�features�morefeatures� __class__s ��1/usr/lib/python3/dist-packages/nltk/featstruct.pyr zFeatStruct.__new__� s6 �� �* �*������'��A�A�L�A�A�A��X�&�&�
��'��(�K�K�l�K�K�K��
��;�� � � �(�C�(�(�
J�#�3�9�9�(�C�C� P�#�+�H�h�O�O�,�O�O�O�#�+�H�h�O�O�,�O�O�O��h�'�'�
J��'�'��(�;�;�;�� H�I�I�I� #�5�7�7�?�3��A�A�L�A�A�A� c � � t � � �)zNReturn an iterable of the feature identifiers used by this
FeatStruct.��NotImplementedError��selfs r �_keyszFeatStruct._keys� � � � "�#�#�#r c � � t � � �)zUReturn an iterable of the feature values directly defined
by this FeatStruct.r! r# s r �_valueszFeatStruct._values� r&