Files
old-nlp/venv/lib/python3.7/site-packages/nltk/__pycache__/featstruct.cpython-37.pyc

1006 lines
74 KiB
Plaintext
Raw Normal View History

2019-10-20 13:16:49 +02:00
B
D(<28>]<5D><><00> @sdZddlmZmZmZddlZddlZddlmZddl m
Z
m Z ddl m Z mZddlmZmZmZmZmZddlmZmZeGd d
<EFBFBD>d
e<12><03>Zd Zd Zdydd<0F>ZeGdd<11>dee<1C><04>ZGdd<13>dee<1E>Zdzdd<16>Z dd<18>Z!d{dd<1A>Z"dd<1C>Z#d|dd<1E>Z$dd <20>Z%d}d"d#<23>Z&d$d%<25>Z'd&d'<27>Z(d~d(d)<29>Z)d*d+<2B>Z*eGd,d-<2D>d-e+<2B><03>Z,e,<2C>Z-dd0d1<64>Z.Gd2d3<64>d3e/<2F>Z0d4d5<64>Z1d6d7<64>Z2d8d9<64>Z3d:d;<3B>Z4d<d=<3D>Z5d>d?<3F>Z6d@dA<64>Z7dBdC<64>Z8dDdE<64>Z9dFdG<64>Z:dHdI<64>Z;dJdK<64>Z<d<>dLdM<64>Z=dNdO<64>Z>dPdQ<64>Z?dRdS<64>Z@GdTdU<64>dUe<12>ZAeGdVdW<64>dWeAeB<65><04>ZCeGdXdY<64>dYeAeD<65><04>ZEeGdZd[<5B>d[eAeD<65><04>ZFeGd\d]<5D>d]eAeB<65><04>ZGd^d_<64>ZHeeGd`da<64>dae+<2B><03><01>ZIGdbdc<64>dceI<65>ZJGddde<64>deeI<65>ZKeJdfd.dfdg<64>ZLeIdhdidj<64>ZMeGdkdl<64>dle+<2B><03>ZNGdmdn<64>dne+<2B>ZOd<4F>dpdq<64>ZPd<50>drds<64>ZQd<51>dtdu<64>ZReSdvk<02>r<>eR<65>d
ddd1dKdMdadcdedwdxdng ZTdS)<29>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.
<EFBFBD>)<03>print_function<6F>unicode_literals<6C>divisionN)<01>total_ordering)<02> integer_types<65> string_types)<02>read_str<74>raise_unorderable_types)<05>Variable<6C>
Expression<EFBFBD>SubstituteBindingsI<73> LogicParser<65>LogicalExpressionException)<02>python_2_unicode_compatible<6C> unicode_reprcseZdZdZdZdB<64>fdd<05> Zdd<07>Zdd <09>Zd
d <0B>ZdCd d <0A>Z dd<0F>Z
dd<11>Z dd<13>Z dd<15>Z dd<17>Zdd<19>ZdZdd<1C>Zdd<1E>Zdd <20>ZdDd"d#<23>Zd$d%<25>Zd&d'<27>Zd(d)<29>Zd*d+<2B>Zd,d+<2B>Zd-d.<2E>Zd/d0<64>Zd1d2<64>Zd3d4<64>ZdEd6d7<64>Zd8d9<64>ZdFd:d;<3B>Zd<d=<3D>Z d>d?<3F>Z!d@dA<64>Z"<22>Z#S)G<>
FeatStructa<EFBFBD>
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 s<>|tkr<>|dkrtjtf|<02>St|<01>r6tjt|f|<02>S|rBtd<02><01>t|t<06>rztj<08> |<01>rhtjt|f|<02>St
jt
|f|<02>Sq<>t |<01>r<>t
<EFBFBD>t
|<01>Std<03><01>nt t|<00>j||f|<02>SdS)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<00>FeatDict<63>__new__<5F> _is_mapping<6E> TypeError<6F>
isinstancer<00>FeatStructReader<65>_START_FDICT_RE<52>match<63>FeatList<73> _is_sequence<63>super)<03>cls<6C>features<65> morefeatures)<01> __class__<5F><00>1/tmp/pip-install-4m6m_5d_/nltk/nltk/featstruct.pyr<00>s 
  
zFeatStruct.__new__cCs
t<00><00>dS)zNReturn an iterable of the feature identifiers used by this
FeatStruct.N)<01>NotImplementedError)<01>selfr!r!r"<00>_keys<79>szFeatStruct._keyscCs
t<00><00>dS)zUReturn an iterable of the feature values directly defined
by this FeatStruct.N)r#)r$r!r!r"<00>_values<65>szFeatStruct._valuescCs
t<00><00>dS)z<>Return an iterable of (fid,fval) pairs, where fid is a
feature identifier and fval is the corresponding feature
value, for all features defined by this FeatStruct.N)r#)r$r!r!r"<00>_items<6D>szFeatStruct._itemscCs|<00>||t<01>t<01>t<01><00>S)aB
Return True if ``self`` and ``other`` assign the same value to
to every feature. In particular, return true if
``self[p]==other[p]`` for every feature path *p* such
that ``self[p]`` or ``other[p]`` is a base value (i.e.,
not a nested feature structure).
:param check_reentrance: If True, then also return False if
there is any difference between the reentrances of ``self``
and ``other``.
:note: the ``==`` is equivalent to ``equal_values()`` with
``check_reentrance=True``.
)<02>_equal<61>set)r$<00>other<65>check_reentrancer!r!r"<00> equal_values<65>szFeatStruct.equal_valuescCs|<00>|dt<01>t<01>t<01><00>S)a
Return true if ``self`` and ``other`` are both feature structures,
assign the same values to all features, and contain the same
reentrances. I.e., return
``self.equal_values(other, check_reentrance=True)``.
:see: ``equal_values()``
T)r(r))r$r*r!r!r"<00>__eq__<5F>s zFeatStruct.__eq__cCs
||k S)Nr!)r$r*r!r!r"<00>__ne__szFeatStruct.__ne__cCs.t|t<01>s|jj|jjkSt|<00>t|<01>kSdS)N)rrr <00>__name__<5F>len)r$r*r!r!r"<00>__lt__s
zFeatStruct.__lt__cCs>|jstd<01><01>y|jStk
r8|<00>t<05><00>|_|jSXdS)zu
If this feature structure is frozen, return its hash value;
otherwise, raise ``TypeError``.
z5FeatStructs must be frozen before they can be hashed.N)<06>_frozenr<00>_hash<73>AttributeError<6F>_calculate_hashvaluer))r$r!r!r"<00>__hash__ szFeatStruct.__hash__c Cs||kr dS|j|jkrdSt|<00>t|<01>kr0dSt|<00><03><00>t|<01><03><00>krLdS|r~t|<00>|ksht|<01>|kr<>t|<00>t|<01>f|kSnt|<00>t|<01>f|kr<>dS|<03>t|<00><01>|<04>t|<01><01>|<05>t|<00>t|<01>f<02>xN|<00><06>D]B\}}||}t|t<08><02>r|<07> |||||<05><05>sdSq<>||kr<>dSq<>WdS)a<>
Return True iff self and other have equal values.
:param visited_self: A set containing the ids of all ``self``
feature structures we've already visited.
:param visited_other: A set containing the ids of all ``other``
feature structures we've already visited.
:param visited_pairs: A set containing ``(selfid, otherid)`` pairs
for all pairs of feature structures we've already visited.
TF)
r r0r)r%<00>id<69>addr'rrr() r$r*r+Z visited_selfZ visited_otherZ visited_pairs<72>fnameZ self_fvalZ
other_fvalr!r!r"r(s:  zFeatStruct._equalcCs<>t|<00>|krdS|<01>t|<00><01>d}xft|<00><03><00>D]V\}}|d9}|t|<03>7}|d9}t|t<06>rn||<04>|<01>7}n |t|<04>7}t|d@<00>}q0W|S)z<>
Return a hash value for this feature structure.
:require: ``self`` must be frozen.
:param visited: A set containing the ids of all feature
structures we've already visited while hashing.
<20>i<><00>%i<><69><EFBFBD>) r7r8<00>sortedr'<00>hashrrr5<00>int)r$<00>visitedZhashvalr9<00>fvalr!r!r"r5as  
 zFeatStruct._calculate_hashvaluez'Frozen FeatStructs may not be modified.cCs|jr
dS|<00>t<02><00>dS)a
Make this feature structure, and any feature structures it
contains, immutable. Note: this method does not attempt to
'freeze' any feature value that is not a ``FeatStruct``; it
is recommended that you use only immutable feature values.
N)r2<00>_freezer))r$r!r!r"<00>freeze<7A>szFeatStruct.freezecCs|jS)a$
Return True if this feature structure is immutable. Feature
structures can be made immutable with the ``freeze()`` method.
Immutable feature structures may not be made mutable again,
but new mutable copies can be produced with the ``copy()`` method.
)r2)r$r!r!r"<00>frozen<65>szFeatStruct.frozencCsVt|<00>|krdS|<01>t|<00><01>d|_x,t|<00><04><00>D]\}}t|t<06>r2|<03>|<01>q2WdS)z<>
Make this feature structure, and any feature structure it
contains, immutable.
:param visited: A set containing the ids of all feature
structures we've already visited while freezing.
NT)r7r8r2r<r'rrrA)r$r?r9r@r!r!r"rA<00>s 
zFeatStruct._freezeTcCs|rt<00>|<00>S|<00>|<00>SdS)z<>
Return a new copy of ``self``. The new copy will not be frozen.
:param deep: If true, create a deep copy; if false, create
a shallow copy.
N)<03>copy<70>deepcopyr )r$<00>deepr!r!r"rD<00>s
zFeatStruct.copycCs
t<00><00>dS)N)r#)r$<00>memor!r!r"<00> __deepcopy__<5F>szFeatStruct.__deepcopy__cCs|<00>i<00>t|<00>S)zH
Return True if this feature structure contains itself.
)<02>_find_reentrancesr7)r$r!r!r"<00>cyclic<69>szFeatStruct.cycliccCs |<00>t<01><00>S)z<>
Return an iterator that generates this feature structure, and
each feature structure it contains. Each feature structure will
be generated exactly once.
)<02>_walkr))r$r!r!r"<00>walk<6C>szFeatStruct.walkcCs
t<00><00>dS)z<>
Return an iterator that generates this feature structure, and
each feature structure it contains.
:param visited: A set containing the ids of all feature
structures we've already visited while freezing.
N)r#)r$r?r!r!r"rK<00>szFeatStruct._walkccs^t|<00>|krdS|<01>t|<00><01>|Vx4|<00><02>D](}t|t<04>r.x|<02>|<01>D]
}|VqHWq.WdS)N)r7r8r&rrrK)r$r?r@<00>eltr!r!r"rK<00>s 
cCsPt|<00>|krd|t|<00><n2d|t|<00><x$|<00><01>D]}t|t<03>r0|<02>|<01>q0W|S)z<>
Return a dictionary that maps from the ``id`` of each feature
structure contained in ``self`` (including ``self``) to a
boolean value, indicating whether it is reentrant or not.
TF)r7r&rrrI)r$<00> reentrancesr@r!r!r"rI<00>s  
zFeatStruct._find_reentrancescCs
t||<01>S)z/:see: ``nltk.featstruct.substitute_bindings()``)<01>substitute_bindings)r$<00>bindingsr!r!r"rO<00>szFeatStruct.substitute_bindingscCs
t||<01>S)z,:see: ``nltk.featstruct.retract_bindings()``)<01>retract_bindings)r$rPr!r!r"rQszFeatStruct.retract_bindingscCst|<00>S)z*:see: ``nltk.featstruct.find_variables()``)<01>find_variables)r$r!r!r"<00> variablesszFeatStruct.variablesr!cCst||||<03>S)z,:see: ``nltk.featstruct.rename_variables()``)<01>rename_variables)r$<00>vars<72> used_vars<72>new_varsr!r!r"rTszFeatStruct.rename_variablescCst|<00>S)z<>
Return the feature structure that is obtained by deleting
any feature whose value is a ``Variable``.
:rtype: FeatStruct
)<01>remove_variables)r$r!r!r"rX szFeatStruct.remove_variablescCst||||||<05>S)N)<01>unify)r$r*rP<00>trace<63>fail<69> rename_varsr!r!r"rYszFeatStruct.unifycCs
t||<01>S)z<>
Return True if ``self`` subsumes ``other``. I.e., return true
If unifying ``self`` with ``other`` would result in a feature
structure equal to ``other``.
)<01>subsumes)r$r*r!r!r"r]szFeatStruct.subsumescCs|<00>|<00>i<00>i<00>S)z<>
Display a single-line representation of this feature structure,
suitable for embedding in other representations.
)<02>_reprrI)r$r!r!r"<00>__repr__(szFeatStruct.__repr__cCs
t<00><00>dS)a
Return a string representation of this feature structure.
:param reentrances: A dictionary that maps from the ``id`` of
each feature value in self, indicating whether that value
is reentrant or not.
:param reentrance_ids: A dictionary mapping from each ``id``
of a feature value to a unique identifier. This is modified
by ``repr``: the first time a reentrant feature value is
displayed, an identifier is added to ``reentrance_ids`` for it.
N)r#)r$rN<00>reentrance_idsr!r!r"r^/s zFeatStruct._repr)N)F)T)Nr!N)NFNT)$r/<00>
__module__<EFBFBD> __qualname__<5F>__doc__r2rr%r&r'r,r-r.r1r6r(r5<00> _FROZEN_ERRORrBrCrArDrHrJrLrKrIrOrQrSrTrXrYr]r_r^<00> __classcell__r!r!)r r"rssB 
3
   G  

 

 rz'Frozen FeatStructs may not be modified.z'
%sIf self is frozen, raise ValueError.<2E>cs,<00>fdd<02>}<02>j|_<00>jpdt||_|S)z<>
Given a method function, return a new method function that first
checks if ``self._frozen`` is true; and if so, raises ``ValueError``
with an appropriate message. Otherwise, call the method and return
its result.
cs$|jrtt<02><01>n<10>|f|<01>|<02>SdS)N)r2<00>
ValueErrorrd)r$<00>args<67>kwargs)<01>methodr!r"<00>wrappedKs
z_check_frozen.<locals>.wrappedrf)r/rc<00>_FROZEN_NOTICE)rj<00>indentrkr!)rjr"<00> _check_frozenCs rnc@s<>eZdZdZd"dd<04>Zed<05>Zdd<07>Zd#dd <09>Zd
d <0B>Z d d <0A>Z
dd<0F>Z dd<11>Z e ej<0F>Ze ej<10>Ze ej<11>Ze ej<12>Zd$dd<13>Zdd<15>Zdd<17>Zdd<19>Zdd<1B>Zdd<1D>Zdd<1F>Zd d!<21>ZdS)%ra<>
A feature structure that acts like a Python dictionary. I.e., a
mapping from feature identifiers to feature values, where a feature
identifier can be a string or a ``Feature``; and where a feature value
can be either a basic value (such as a string or an integer), or a nested
feature structure. A feature identifiers for a ``FeatDict`` is
sometimes called a "feature name".
Two feature dicts are considered equal if they assign the same
values to all features, and have the same reentrances.
:see: ``FeatStruct`` for information about feature paths, reentrance,
cyclic feature structures, mutability, freezing, and hashing.
NcKs8t|t<01>r&t<02><00>||<00>|jf|<02>n|j|f|<02>dS)a3
Create a new feature dictionary, with the specified features.
:param features: The initial value for this feature
dictionary. If ``features`` is a ``FeatStruct``, then its
features are copied (shallow copy). If ``features`` is a
dict, then a feature is created for each item, mapping its
key to its value. If ``features`` is a string, then it is
processed using ``FeatStructReader``. If ``features`` is a list of
tuples ``(name, val)``, then a feature is created for each tuple.
:param morefeatures: Additional features for the new feature
dictionary. If a feature is listed under both ``features`` and
``morefeatures``, then the value from ``morefeatures`` will be
used.
N)rrr<00>
fromstring<EFBFBD>update)r$rrr!r!r"<00>__init__ls
zFeatDict.__init__z'Expected feature name or path. Got %r.c Cs<>t|ttf<02>rt<03>||<01>St|t<05>rty,|}x"|D]}t|t<06>sBt<07>||}q0W|Sttfk
rpt|<01><01>Yq<>Xnt |j
|<00><01>dS)zkIf the feature with the given name or path exists, return
its value; otherwise, raise ``KeyError``.N) rr<00>Feature<72>dict<63> __getitem__<5F>tupler<00>KeyError<6F>
IndexErrorr<00> _INDEX_ERROR)r$<00> name_or_path<74>val<61>fidr!r!r"rt<00>s 


 zFeatDict.__getitem__cCs"y||Stk
r|SXdS)zkIf the feature with the given name or path exists, return its
value; otherwise, return ``default``.N)rv)r$ry<00>defaultr!r!r"<00>get<65>sz FeatDict.getcCs&y ||dStk
r dSXdS)z<Return true if a feature with the given name or path exists.TFN)rv)r$ryr!r!r"<00> __contains__<5F>s
zFeatDict.__contains__cCs||kS)z<Return true if a feature with the given name or path exists.r!)r$ryr!r!r"<00>has_key<65>szFeatDict.has_keycCs<>|jrtt<02><01>t|ttf<02>r(t<06>||<01>St|t<08>rvt |<01>dkrHtd<02><01>q<>||dd<04>}t|t
<EFBFBD>sjt |<01><01>||d=nt |j |<00><01>dS)zkIf the feature with the given name or path exists, delete
its value; otherwise, raise ``KeyError``.rzThe path () can not be setN<74><4E><EFBFBD><EFBFBD><EFBFBD>)r2rgrdrrrrrs<00> __delitem__rur0rrvrrx)r$ry<00>parentr!r!r"r<><00>s 
 

 zFeatDict.__delitem__cCs<>|jrtt<02><01>t|ttf<02>r*t<06>|||<02>St|t<08>rzt |<01>dkrJtd<02><01>q<>||dd<04>}t|t
<EFBFBD>slt |<01><01>|||d<nt |j |<00><01>dS)z<>Set the value for the feature with the given name or path
to ``value``. If ``name_or_path`` is an invalid path, raise
``KeyError``.rzThe path () can not be setNr<4E>)r2rgrdrrrrrs<00> __setitem__rur0rrvrrx)r$ry<00>valuer<65>r!r!r"r<><00>s
 

zFeatDict.__setitem__cKs<>|jrtt<02><01>|dkrd}n6t|d<02>r:t|j<05>r:|<01><05>}nt|d<03>rJ|}ntd<04><01>x.|D]&\}}t|ttf<02>svt d<05><01>|||<qXWx2|<02><05>D]&\}}t|ttf<02>s<>t d<05><01>|||<q<>WdS)Nr!<00>items<6D>__iter__z"Expected mapping or list of tupleszFeature names must be strings)
r2rgrd<00>hasattr<74>callabler<65>rrrrr)r$rrr<><00>keyrzr!r!r"rp<00>s"

 zFeatDict.updatecCsF|<00><00>|t|<00><}x,|<00><02>D] \}}t<03>||<01>|t<03>||<01><qW|S)N)r r7r'rDrE)r$rG<00>selfcopyr<79>rzr!r!r"rH<00>szFeatDict.__deepcopy__cCs|<00><00>S)N)<01>keys)r$r!r!r"r%<00>szFeatDict._keyscCs|<00><00>S)N)<01>values)r$r!r!r"r&<00>szFeatDict._valuescCs|<00><00>S)N)r<>)r$r!r!r"r'szFeatDict._itemscCsd<01>|<00>|<00>i<00>i<00><02>S)zz
Display a multi-line representation of this feature dictionary
as an FVM (feature value matrix).
<20>
)<03>join<69>_strrI)r$r!r!r"<00>__str__szFeatDict.__str__c
Cs<>g}d}d}|t|<00>r@t|<00>|ks(t<01>tt|<02>d<00>|t|<00><<00>xZt|<00><05><00>D<00>]H\}}t|dd<00>}t|<07>|kr<>|<03>d||t|<07>f<00>qP|dkr<>|s<>t|t t
f<02>r<>d|}qP|dkr<>|s<>t|t <09>r<>d|j }n dt |<07>}qPt|t <09><02>r|<03>d ||j f<00>qP|d
k<08>r|<03>d |<00>qP|d k<08>r8|<03>d |<00>qPt|t <0A><02>rX|<03>d||f<00>qPt|t<0E><02>s||<03>d |t |<07>f<00>qP|<07>||<02>} |<03>d || f<00>qPW|t|<00><00>r<>d|t|<00>|f}d|d<11>|<03>|fS)Nrfr:<00>displayz%s->(%s)<29>prefixz%s<>slashz/%sz%s=%sTz+%sFz-%sz%s=<%s>z(%s)%sz%s[%s]%sz, )r7<00>AssertionError<6F>reprr0r<r<><00>getattr<74>appendrr
r<00>namerr rr^r<>)
r$rNr`<00>segmentsr<73><00>suffixr9r@r<><00> fval_reprr!r!r"r^sB   
 
  

   zFeatDict._reprc
s~|t|<00>r4t|<00>|kst<01>tt|<02>d<00>|t|<00><t|<00>dkrd|t|<00>r^d|t|<00>gSdgStdd<06>|<00><05>D<00><01><01>g}<03>xbt|<00><07><00>D<00>]P\}}d|<00><08><01>}t |t
<EFBFBD>r<>|<03> d||j f<00>q<>t |t <0A>r<>|<03> d ||f<00>q<>t |t<0E><02>r|<05>||<02>}|<03> d|t|<06>f<00>q<>t |t<11><02>s8|<03> d|t|<05>f<00>q<>t|<05>|k<06>rb|<03> d
||t|<05>f<00>q<>|<03>r<>|d d k<03>r<>|<03> d <0C>|<05>||<02>}<07>fd d<0E>|D<00>}t|<07>dd}|d||<00>dd<11>||<||7}|<03> d <0C>q<>W|d d k<02>r<>|<03><13>tdd<06>|D<00><01><01><02>fdd<0E>|D<00>}|t|<00><00>rzd|t|<00><00><00>fdd<0E>|D<00>}t|<03>dd} <09>|| t<03><00>d<11>|| <|S)aL
:return: A list of lines composing a string representation of
this feature dictionary.
:param reentrances: A dictionary that maps from the ``id`` of
each feature value in self, indicating whether that value
is reentrant or not.
:param reentrance_ids: A dictionary mapping from each ``id``
of a feature value to a unique identifier. This is modified
by ``repr``: the first time a reentrant feature value is
displayed, an identifier is added to ``reentrance_ids`` for
it.
r:rz(%s) []z[]css|]}td|<00>VqdS)z%sN)r0)<02>.0<EFBFBD>kr!r!r"<00> <genexpr>Xsz FeatDict._str.<locals>.<genexpr>z%sz%s = %sz %s = <%s>z
%s -> (%s)r<>rfcsg|]}d<00>d|<00>qS)<02> <20>r!)r<><00>l)<01> maxfnamelenr!r"<00>
<listcomp>|sz!FeatDict._str.<locals>.<listcomp><3E>z =Ncss|]}t|<01>VqdS)N)r0)r<><00>liner!r!r"r<><00>scs$g|]}d|d<01>t|<01>f<00>qS)z[ %s%s ]r<>)r0)r<>r<>)<01>maxlenr!r"r<><00>sz(%s) csg|]}dt<00><00>|<00>qS)r<>)r0)r<>r<>)<01>idstrr!r"r<><00>s)r7r<>r<>r0<00>maxr<78>r<r<><00>ljustrr
r<>r<>r rr^rrr<><00>pop)
r$rNr`<00>linesr9r@r<>Z
fval_linesZnamelineZidliner!)r<>r<>r<>r"r<>=sP   

   
  z FeatDict._str)N)N)N)r/rarbrcrq<00>strrxrtr}r~rr<>r<>rnrs<00>clearr<72><00>popitem<65>
setdefaultrprHr%r&r'r<>r^r<>r!r!r!r"r[s*







.rc@s<>eZdZdZddd<04>ZdZdd<07>Zdd <09>Zd
d <0B>Ze e
j <0B>Z e e
j <0C>Z e e
j <0A>Z e e
j<0E>Ze e
j<0F>Ze e
j<10>Ze e
j<11>Ze e
j<12>Ze e
j<13>Zd d <0A>Zdd<0F>Zdd<11>Zdd<13>Zdd<15>ZdS)ray
A list of feature values, where each feature value is either a
basic value (such as a string or an integer), or a nested feature
structure.
Feature lists may contain reentrant feature values. A "reentrant
feature value" is a single feature value that can be accessed via
multiple feature paths. Feature lists may also be cyclic.
Two feature lists are considered equal if they assign the same
values to all features, and have the same reentrances.
:see: ``FeatStruct`` for information about feature paths, reentrance,
cyclic feature structures, mutability, freezing, and hashing.
r!cCs*t|t<01>rt<02><00>||<00>n t<04>||<01>dS)aZ
Create a new feature list, with the specified features.
:param features: The initial list of features for this feature
list. If ``features`` is a string, then it is paresd using
``FeatStructReader``. Otherwise, it should be a sequence
of basic values and nested feature structures.
N)rrrro<00>listrq)r$rr!r!r"rq<00>s
zFeatList.__init__z&Expected int or feature path. Got %r.c Cs<>t|t<01>rt<02>||<01>St|t<04>rpy,|}x"|D]}t|t<05>s>t<06>||}q,W|Sttfk
rlt|<01><01>Yq~Xnt|j |<00><01>dS)N)
rrr<>rtrurrvrwrrx)r$ryrzr{r!r!r"rt<00>s
 


 zFeatList.__getitem__cCs<>|jrtt<02><01>t|ttf<02>r(t<06>||<01>St|t<08>rvt |<01>dkrHtd<02><01>q<>||dd<04>}t|t
<EFBFBD>sjt |<01><01>||d=nt |j |<00><01>dS)zkIf the feature with the given name or path exists, delete
its value; otherwise, raise ``KeyError``.rzThe path () can not be setNr<4E>)r2rgrdrr<00>slicer<65>r<>rur0rrvrrx)r$ryr<>r!r!r"r<><00>s 
 

 zFeatList.__delitem__cCs<>|jrtt<02><01>t|ttf<02>r*t<06>|||<02>St|t<08>rzt |<01>dkrJtd<02><01>q<>||dd<04>}t|t
<EFBFBD>slt |<01><01>|||d<nt |j |<00><01>dS)z<>Set the value for the feature with the given name or path
to ``value``. If ``name_or_path`` is an invalid path, raise
``KeyError``.rzThe path () can not be setNr<4E>)r2rgrdrrr<>r<>r<>rur0rrvrrx)r$ryr<>r<>r!r!r"r<><00>s
 

zFeatList.__setitem__cs0|<00><00><00>t|<00><}|<02><02>fdd<02>|D<00><01>|S)Nc3s|]}t<00>|<01><00>VqdS)N)rDrE)r<>r@)rGr!r"r<> sz(FeatList.__deepcopy__.<locals>.<genexpr>)r r7<00>extend)r$rGr<>r!)rGr"rH
szFeatList.__deepcopy__cCsttt|<00><01><01>S)N)r<><00>ranger0)r$r!r!r"r%szFeatList._keyscCs|S)Nr!)r$r!r!r"r&szFeatList._valuescCst|<00>S)N)<01> enumerate)r$r!r!r"r'szFeatList._itemscCs<>|t|<00>rFt|<00>|kst<01>tt|<02>d<00>|t|<00><d|t|<00>}nd}g}x<>|D]<5D>}t|<05>|kr||<04>d|t|<05><00>qTt|t<06>r<>|<04>|j<07>qTt|t<08>r<>|<04>d|<00>qTt|t <09>r<>|<04>|<05>
||<02><02>qT|<04>dt |<05><00>qTWd|d<07> |<04>fS)Nr:z(%s)rfz->(%s)z%sz%s[%s]z, ) r7r<>r<>r0r<>rr
r<>r rr^rr<>)r$rNr`r<>r<>r@r!r!r"r^!s" 
 


zFeatList._reprN)r!)r/rarbrcrqrxrtr<>r<>rnr<><00>__iadd__<5F>__imul__r<5F>r<><00>insertr<74><00>remove<76>reverse<73>sortrHr%r&r'r^r!r!r!r"r<00>s(









 rr|cCs.|dkrt|<00>}t<01>|<00>}t|||t<04><00>|S)a<>
Return the feature structure that is obtained by replacing each
variable bound by ``bindings`` with its binding. If a variable is
aliased to a bound variable, then it will be replaced by that
variable's value. If a variable is aliased to an unbound
variable, then it will be replaced by that variable.
:type bindings: dict(Variable -> any)
:param bindings: A dictionary mapping from variables to values.
r|)<05>_default_fs_classrDrE<00>_substitute_bindingsr))<03>fstructrP<00>fs_classr!r!r"rO@s

rOcCs<>t|<00>|krdS|<03>t|<00><01>t|<00>r0|<00><03>}nt|<00>rBt|<00>}ntd<01><01>xj|D]b\}}x&t|t<08>r~||kr~||}||<qZWt||<02>r<>t ||||<03>qPt|t
<EFBFBD>rP|<06> |<01>||<qPWdS)NzExpected mapping or sequence) r7r8rr<>rr<>rgrr
r<>r rO)r<>rPr<>r?r<>r9r@r!r!r"r<>Rs 



r<>cCsV|dkrt|<00>}t<01>||f<02>\}}|<01>|<03>tdd<03>|<01><05>D<00><01>}t|||t<07><00>|S)a<>
Return the feature structure that is obtained by replacing each
feature structure value that is bound by ``bindings`` with the
variable that binds it. A feature structure value must be
identical to a bound value (i.e., have equal id) to be replaced.
``bindings`` is modified to point to this new feature structure,
rather than the original feature structure. Feature structure
values in ``bindings`` may be modified if they are contained in
``fstruct``.
r|css|]\}}t|<02>|fVqdS)N)r7)r<><00>varrzr!r!r"r<>wsz#retract_bindings.<locals>.<genexpr>)r<>rDrErprsr<><00>_retract_bindingsr))r<>rPr<>Z new_bindings<67> inv_bindingsr!r!r"rQgs 
rQcCs<>t|<00>|krdS|<03>t|<00><01>t|<00>r0|<00><03>}nt|<00>rBt|<00>}ntd<01><01>xD|D]<\}}t||<02>rPt|<06>|kr~|t|<06>||<t||||<03>qPWdS)NzExpected mapping or sequence) r7r8rr<>rr<>rgrr<>)r<>r<>r<>r?r<>r9r@r!r!r"r<>|s 


 r<>cCs"|dkrt|<00>}t|t<02>|t<02><00>S)za
:return: The set of variables used by this feature structure.
:rtype: set(Variable)
r|)r<><00>
_variablesr))r<>r<>r!r!r"rR<00>srRcCs<>t|<00>|krdS|<03>t|<00><01>t|<00>r0|<00><03>}nt|<00>rBt|<00>}ntd<01><01>xX|D]P\}}t|t<08>rn|<01>|<06>qPt||<02>r<>t ||||<03>qPt|t
<EFBFBD>rP|<01> |<06> <0C><00>qPW|S)NzExpected mapping or sequence) r7r8rr<>rr<>rgrr
r<>r rprS)r<>rUr<>r?r<>r9r@r!r!r"r<><00>s  


 

r<>r!cCsb|dkrt|<00>}|dkri}|dkr0t||<04>}nt|<01>}t||<04><02>|<02>}tt<05>|<00>||||t<02><00>S)a<>
Return the feature structure that is obtained by replacing
any of this feature structure's variables that are in ``vars``
with new variables. The names for these new variables will be
names that are not used by any variable in ``vars``, or in
``used_vars``, or in this feature structure.
:type vars: set
:param vars: The set of variables that should be renamed.
If not specified, ``find_variables(fstruct)`` is used; i.e., all
variables will be given new names.
:type used_vars: set
:param used_vars: A set of variables whose names should not be
used by the new variables.
:type new_vars: dict(Variable -> Variable)
:param new_vars: A dictionary that is used to hold the mapping
from old variables to new variables. For each variable *v*
in this feature structure:
- If ``new_vars`` maps *v* to *v'*, then *v* will be
replaced by *v'*.
- If ``new_vars`` does not contain *v*, but ``vars``
does contain *v*, then a new entry will be added to
``new_vars``, mapping *v* to the new variable that is used
to replace it.
To consistently rename the variables in a set of feature
structures, simply apply rename_variables to each one, using
the same dictionary:
>>> from nltk.featstruct import FeatStruct
>>> fstruct1 = FeatStruct('[subj=[agr=[gender=?y]], obj=[agr=[gender=?y]]]')
>>> fstruct2 = FeatStruct('[subj=[agr=[number=?z,gender=?y]], obj=[agr=[number=?z,gender=?y]]]')
>>> new_vars = {} # Maps old vars to alpha-renamed vars
>>> fstruct1.rename_variables(new_vars=new_vars)
[obj=[agr=[gender=?y2]], subj=[agr=[gender=?y2]]]
>>> fstruct2.rename_variables(new_vars=new_vars)
[obj=[agr=[gender=?y2, number=?z2]], subj=[agr=[gender=?y2, number=?z2]]]
If new_vars is not specified, then an empty dictionary is used.
r|N)r<>rRr)<00>union<6F>_rename_variablesrDrE)r<>rUrVrWr<>r!r!r"rT<00>s, rTc
Cs&t|<00>|krdS|<05>t|<00><01>t|<00>r0|<00><03>}nt|<00>rBt|<00>}ntd<01><01>x<>|D]<5D>\}}t|t<08>r<>||krx||||<n0||kr<>t ||<02>||<||||<|<02>||<00>qPt||<04>r<>t
||||||<05>qPt|t <0B>rPx<|<08> <0C>D]0} | |kr<>| |kr<>t | |<02>|| <|<02>|| <00>q<>W|<08> |<03>||<qPW|S)NzExpected mapping or sequence)r7r8rr<>rr<>rgrr
<00>_rename_variabler<65>r rSrO)
r<EFBFBD>rUrVrWr<>r?r<>r9r@r<>r!r!r"r<><00>s2 


 

r<>cCsPt<00>dd|j<02>d}}|sd}x td||f<00>|kr>|d7}q Wtd||f<00>S)Nz\d+$rfr<><00>?z%s%sr:)<04>re<72>subr<62>r
)r<>rVr<><00>nr!r!r"r<>s  r<>cCs$|dkrt|<00>}tt<02>|<00>|t<04><00>S)z<>
:rtype: FeatStruct
:return: The feature structure that is obtained by deleting
all features whose values are ``Variables``.
r|)r<><00>_remove_variablesrDrEr))r<>r<>r!r!r"rXsrXcCs<>t|<00>|krdS|<02>t|<00><01>t|<00>r4t|<00><04><00>}nt|<00>rJtt|<00><01>}ntd<01><01>x8|D]0\}}t|t <09>rr||=qXt||<01>rXt
|||<02>qXW|S)NzExpected mapping or sequence) r7r8rr<>r<>rr<>rgrr
r<>)r<>r<>r?r<>r9r@r!r!r"r<>#s 

r<>c@seZdZdd<02>ZdS)<04>_UnificationFailurecCsdS)Nz"nltk.featstruct.UnificationFailurer!)r$r!r!r"r_>sz_UnificationFailure.__repr__N)r/rarbr_r!r!r!r"r<><sr<>FTc Csd|dkr$t|<00>}t|<01>|kr$td<02><01>t||<06>s2t<03>t||<06>s@t<03>|dk }|dkrTi}t<04>|||f<03>\}} }
|<02>|
<EFBFBD>|r<>t||<06>} t| |<06>} t| | | i|t <09><00>i} |r<>t
d|| <09>yt || || |||d<04>}Wnt k
r<EFBFBD>dSX|t k<08>r|dk<08>r<>dS||| d<04>St|| |t <09><00>}|<07>r(t| |<02>t|<02>t|||t <09><00>|<03>rPtd|<0E>|<03>r`td|<02>|S)a!
Unify ``fstruct1`` with ``fstruct2``, and return the resulting feature
structure. This unified feature structure is the minimal
feature structure that contains all feature value assignments from both
``fstruct1`` and ``fstruct2``, and that preserves all reentrancies.
If no such feature structure exists (because ``fstruct1`` and
``fstruct2`` specify incompatible values for some feature), then
unification fails, and ``unify`` returns None.
Bound variables are replaced by their values. Aliased
variables are replaced by their representative variable
(if unbound) or the value of their representative variable
(if bound). I.e., if variable *v* is in ``bindings``,
then *v* is replaced by ``bindings[v]``. This will
be repeated until the variable is replaced by an unbound
variable or a non-variable value.
Unbound variables are bound when they are unified with
values; and aliased when they are unified with variables.
I.e., if variable *v* is not in ``bindings``, and is
unified with a variable or value *x*, then
``bindings[v]`` is set to *x*.
If ``bindings`` is unspecified, then all variables are
assumed to be unbound. I.e., ``bindings`` defaults to an
empty dict.
>>> from nltk.featstruct import FeatStruct
>>> FeatStruct('[a=?x]').unify(FeatStruct('[b=?x]'))
[a=?x, b=?x2]
:type bindings: dict(Variable -> any)
:param bindings: A set of variable bindings to be used and
updated during unification.
:type trace: bool
:param trace: If true, generate trace output.
:type rename_vars: bool
:param rename_vars: If True, then rename any variables in
``fstruct2`` that are also used in ``fstruct1``, in order to
avoid collisions on variable names.
r|zGMixing FeatStruct objects with Python dicts and lists is not supported.Nr!)r<>rgrr<>rDrErprRr<>r)<00>_trace_unify_start<72>_destructively_unify<66>_UnificationFailureError<6F>UnificationFailure<72>_apply_forwards<64>_apply_forwards_to_bindings<67>_resolve_aliasesr<73><00>_trace_unify_succeed<65>_trace_bindings)<0F>fstruct1<74>fstruct2rPrZr[r\r<>Z user_bindingsZ fstruct1copyZ fstruct2copyZ bindings_copyZvars1Zvars2<73>forward<72>resultr!r!r"rYMsN5 


 

 


rYc@seZdZdZdS)r<>zmAn exception that is used by ``_destructively_unify`` to abort
unification when a failure is encountered.N)r/rarbrcr!r!r!r"r<><00>sr<>c Cs<>||kr|rt||<00>|S||t|<01><t|<00>r<>t|<01>r<>x*|D]"}t|dd<02>dk r<|<01>||j<05>q<Wx*|D]"}t|dd<02>dk rh|<00>||j<05>qhWxPt|<01><07><00>D]@\}} ||kr<>t|||| |||||||f<00> ||<q<>| ||<q<>W|St |<00><01>rTt |<01><01>rTt
|<00>t
|<01>k<03>rt Sx@t t
|<00><01>D]0}
t|
||
||
|||||||
f<00> ||
<<00>qW|St |<00><01>sht|<00><01>r<>t |<01><01>s|t|<01><01>r<>t St d<03><01>dS)aC
Attempt to unify ``fstruct1`` and ``fstruct2`` by modifying them
in-place. If the unification succeeds, then ``fstruct1`` will
contain the unified value, the value of ``fstruct2`` is undefined,
and forward[id(fstruct2)] is set to fstruct1. If the unification
fails, then a _UnificationFailureError is raised, and the
values of ``fstruct1`` and ``fstruct2`` are undefined.
:param bindings: A dictionary mapping variables to values.
:param forward: A dictionary mapping feature structures ids
to replacement structures. When two feature structures
are merged, a mapping from one to the other will be added
to the forward dictionary; and changes will be made only
to the target of the forward dictionary.
``_destructively_unify`` will always 'follow' any links
in the forward dictionary for fstruct1 and fstruct2 before
actually unifying them.
:param trace: If true, generate trace output
:param path: The feature path that led us to this unification
step. Used for trace output.
r|NzExpected mappings or sequences)<0E>_trace_unify_identityr7rr<>r<>r|r<r<><00>_unify_feature_valuesrr0r<>r<>r) r<>r<>rPr<>rZr[r<><00>pathr9<00>fval2Zfindexr!r!r"r<><00>sZ
 

 r<>c Cs<>|rt|||<02>xt|<01>|kr,|t|<01>}qWxt|<02>|krJ|t|<02>}q0Wd} }
x"t|t<03>rv||krv|} ||}qVWx"t|t<03>r<>||kr<>|}
||}qzWt||<07>r<>t||<07>r<>t||||||||<08>} <0B>nVt|t<03>r<>t|t<03>r<>||kr<>|||<|} <0B>n*t|t<03><02>r|||<|} <0B>nt|t<03><02>r,|||<|} n<>t||<07><02>sDt||<07><02>rJt} n<>t|t<06><02>rf|<00>|||<03>} nzt|t<08><02>r<>|<01> |<02>} t|t<08><02>r<>| |<02> |<01>k<03>r<>t
d||| |<02> |<01>f<00><01>n,t|t<08><02>r<>|<02> |<01>} n||k<02>r<>|} nt} | tk <09>r | dk <09>r| || <| } |
dk <09>r |
| k<03>r | ||
<|
} | tk<08>rf|dk <09>r@||||<08>} |<05>rXt |dd<03>| <0B>| tk<08>rft <0C>t| |<07><02>r<>t | ||t<0E><00>} |<05>r<>t|| <0B>|<05>r<>t| |<07><02>r<>t||<03>| S)a<>
Attempt to unify ``fval1`` and and ``fval2``, and return the
resulting unified value. The method of unification will depend on
the types of ``fval1`` and ``fval2``:
1. If they're both feature structures, then destructively
unify them (see ``_destructively_unify()``.
2. If they're both unbound variables, then alias one variable
to the other (by setting bindings[v2]=v1).
3. If one is an unbound variable, and the other is a value,
then bind the unbound variable to the value.
4. If one is a feature structure, and the other is a base value,
then fail.
5. If they're both base values, then unify them. By default,
this will succeed if they are equal, and fail otherwise.
NzPCustomFeatureValue objects %r and %r disagree about unification value: %r vs. %rr<72>)r<>r7rr
r<>r<>rr<00>unify_base_values<65>CustomFeatureValuerYr<><00>_trace_unify_failr<6C>r<>r)r<>r<>) r9<00>fval1r<31>rPr<>rZr[r<>ZfpathZfvar1Zfvar2r<32>r!r!r"r<>3s|       
  




 
 

r<>cCs@x:|<01><00>D].\}}xt|<03>|kr.|t|<03>}qW|||<q
WdS)z<>
Replace any feature structure that has a forward pointer with
the target of its forward pointer (to preserve reentrancy).
N)r<>r7)r<>rPr<>r<>r!r!r"r<><00>sr<>cCs<>xt|<00>|kr|t|<00>}qWt|<00>|kr.dS|<03>t|<00><01>t|<00>rN|<00><03>}nt|<00>r`t|<00>}ntd<02><01>xN|D]F\}}t||<02>rnxt|<06>|kr<>|t|<06>}q<>W|||<t||||<03>qnW|S)z<>
Replace any feature structure that has a forward pointer with
the target of its forward pointer (to preserve reentrancy).
NzExpected mapping or sequence) r7r8rr<>rr<>rgrr<>)r<>r<>r<>r?r<>r9r@r!r!r"r<><00>s" 


r<>cCsBx<|<00><00>D]0\}}x&t|t<02>r8||kr8||}||<qWq
WdS)z<>
Replace any bound aliased vars with their binding; and replace
any unbound aliased vars with their representative var.
N)r<>rr
)rPr<>r<>r!r!r"r<><00>sr<>cCs<>|dkrtd<02>nPd<03>dd<05>|D<00><01>}tddt|<00>dd <00>tddt|<00>dd
|<00>tddt|<00>d t|<01><00>tddt|<00>d t|<02><00>dS) Nr!z
Unification trace:<3A>.css|]}d|VqdS)z%sNr!)r<>r<>r!r!r"r<><00>sz%_trace_unify_start.<locals>.<genexpr>z z| r:<00>|z| Unify feature: %sz / z|\ )<04>printr<74>r0<00>_trace_valrepr)r<>r<>r<><00>fullnamer!r!r"r<><00>s
  r<>cCsltddt|<00>d<00>tddt|<00>d<00>tddt|<00>d<00>tddt|<00>dt|<01><00>dS)Nz z| r<>z| (identical objects)z+-->)r<>r0r)r<>r<>r!r!r"r<><00>sr<>cCsJ|tkrd}nd}tddt|<00>d<00>tddt|<00>d|<00>dS)Nrfz (nonfatal)z z| z| |zX zX X <-- FAIL)r<>r<>r0)r<>r<><00>resumer!r!r"r<><00>s
r<>cCs<tddt|<00>d<00>tddt|<00>dt|<01><00>dS)Nz z| r<>z+-->)r<>r0r)r<>r<>r!r!r"r<><00>sr<>cCsXt|<01>dkrTt|<01><02>dd<03>d<04>}dd<06>dd<08>|D<00><01>}td d
t|<00>d |<00>dS) NrcSs
|djS)Nr)r<>)<01>vr!r!r"<00><lambda><00>z!_trace_bindings.<locals>.<lambda>)r<>z{%s}z, css"|]\}}d|t|<02>fVqdS)z%s: %sN)r<>)r<>r<>rzr!r!r"r<>sz"_trace_bindings.<locals>.<genexpr>z z| z Bindings: )r0r<r<>r<>r<>)r<>rPZ binditemsZbindstrr!r!r"r<>s
 r<>cCs"t|t<01>rd|Sdt|<00>SdS)Nz%s)rr
r)rzr!r!r"r<> s
r<>cCs|t||<01>kS)z<>
Return True if ``fstruct1`` subsumes ``fstruct2``. I.e., return
true if unifying ``fstruct1`` with ``fstruct2`` would result in a
feature structure equal to ``fstruct2.``
:rtype: bool
)rY)r<>r<>r!r!r"r]sr]cs$g<00><00>fdd<02>}t||||d<03><00>S)z<>
Return a list of the feature paths of all features which are
assigned incompatible values by ``fstruct1`` and ``fstruct2``.
:rtype: list(tuple)
cs<00><00>|<02>|S)N)r<>)r<>r<>r<>)<01> conflict_listr!r"<00> add_conflict's
zconflicts.<locals>.add_conflict)r[rZ)rY)r<>r<>rZr<>r!)r<>r"<00> conflictss r<>cCst|d<01>ot|d<02>S)Nr~r<>)r<>)r<>r!r!r"r4srcCs t|d<01>ot|d<02>ot|t<02> S)Nr<4E><00>__len__)r<>rr)r<>r!r!r"r8s

rcCs8t|t<01>rtSt|ttf<02>r$ttfStd|jj<00><01>dS)NzBTo unify objects of type %s, you must specify fs_class explicitly.)rrrsr<>rgr r/)<01>objr!r!r"r<>@s
r<>c@s(eZdZdZdd<03>Zdd<05>Zdd<07>ZdS) <09>SubstituteBindingsSequencez<65>
A mixin class for sequence clases that distributes variables() and
substitute_bindings() over the object's elements.
cCs"dd<02>|D<00>tdd<02>|D<00>g<00>S)NcSsg|]}t|t<01>r|<01>qSr!)rr
)r<>rMr!r!r"r<>Xsz8SubstituteBindingsSequence.variables.<locals>.<listcomp>cSs"g|]}t|t<01>rt|<01><03><00><01>qSr!)rr r<>rS)r<>rMr!r!r"r<>Zs)<01>sum)r$r!r!r"rSWsz$SubstituteBindingsSequence.variablescs<00><01><00><00>fdd<02><08>D<00><01>S)Ncsg|]}<01><01>|<01><00><02>qSr!)<01>subst)r<>r<>)rPr$r!r"r<>bszBSubstituteBindingsSequence.substitute_bindings.<locals>.<listcomp>)r )r$rPr!)rPr$r"rOasz.SubstituteBindingsSequence.substitute_bindingscCs$t|t<01>r|<01>|<02>S|<02>||<01>SdS)N)rr rOr})r$r<>rPr!r!r"r<>ds

z SubstituteBindingsSequence.substN)r/rarbrcrSrOr<>r!r!r!r"r<>Qs
r<>c@seZdZdZdd<03>ZdS)<05>FeatureValueTuplea
A base feature value that is a tuple of other base feature values.
FeatureValueTuple implements ``SubstituteBindingsI``, so it any
variable substitutions will be propagated to the elements
contained by the set. A ``FeatureValueTuple`` is immutable.
cCs(t|<00>dkrdSdd<04>dd<06>|D<00><01>S)Nrz()z(%s)z, css|]}d|fVqdS)z%sNr!)r<><00>br!r!r"r<>wsz-FeatureValueTuple.__repr__.<locals>.<genexpr>)r0r<>)r$r!r!r"r_ts zFeatureValueTuple.__repr__N)r/rarbrcr_r!r!r!r"r<>ksr<>c@seZdZdZdd<03>ZeZdS)<05>FeatureValueSeta 
A base feature value that is a set of other base feature values.
FeatureValueSet implements ``SubstituteBindingsI``, so it any
variable substitutions will be propagated to the elements
contained by the set. A ``FeatureValueSet`` is immutable.
cCs,t|<00>dkrdSdd<04>tdd<06>|D<00><01><01>S)Nrz{/}z{%s}z, css|]}d|fVqdS)z%sNr!)r<>r<>r!r!r"r<><00>sz+FeatureValueSet.__repr__.<locals>.<genexpr>)r0r<>r<)r$r!r!r"r_<00>s zFeatureValueSet.__repr__N)r/rarbrcr_r<>r!r!r!r"r<>zsr<>c@s eZdZdZdd<03>Zdd<05>ZdS)<07>FeatureValueUnionzp
A base feature value that represents the union of two or more
``FeatureValueSet`` or ``Variable``.
cCsVt|t<01>}tdd<02>|D<00><01>dkr2t|t<03>}t|<01>St|<01>dkrJt|<01>dSt<06>||<01>S)Ncss|]}t|t<01>VqdS)N)rr
)r<>r<>r!r!r"r<><00>sz,FeatureValueUnion.__new__.<locals>.<genexpr>rr:)<08>_flattenr<6E>r<>r<>r0r<><00> frozensetr)rr<>r!r!r"r<00>s

  zFeatureValueUnion.__new__cCsdd<02>tdd<04>|D<00><01><01>S)Nz{%s}<7D>+css|]}d|fVqdS)z%sNr!)r<>r<>r!r!r"r<><00>sz-FeatureValueUnion.__repr__.<locals>.<genexpr>)r<>r<)r$r!r!r"r_<00>szFeatureValueUnion.__repr__N)r/rarbrcrr_r!r!r!r"r<><00>sr<>c@s eZdZdZdd<03>Zdd<05>ZdS)<07>FeatureValueConcatzz
A base feature value that represents the concatenation of two or
more ``FeatureValueTuple`` or ``Variable``.
cCsVt|t<01>}tdd<02>|D<00><01>dkr2t|t<03>}t|<01>St|<01>dkrJt|<01>dSt<06>||<01>S)Ncss|]}t|t<01>VqdS)N)rr
)r<>r<>r!r!r"r<><00>sz-FeatureValueConcat.__new__.<locals>.<genexpr>rr:)r<>r<>r<>r<>r0r<>rur)rr<>r!r!r"r<00>s

  zFeatureValueConcat.__new__cCsdd<02>dd<04>|D<00><01>S)Nz(%s)r<>css|]}d|fVqdS)z%sNr!)r<>r<>r!r!r"r<><00>sz.FeatureValueConcat.__repr__.<locals>.<genexpr>)r<>)r$r!r!r"r_<00>szFeatureValueConcat.__repr__N)r/rarbrcrr_r!r!r!r"r<><00>sr<>cCs6g}x,|D]$}t||<01>r$|<02>|<03>q
|<02>|<03>q
W|S)z}
Helper function -- return a copy of list, with all elements of
type ``cls`` spliced in rather than appended in.
)rr<>r<>)<04>lstrr<>rMr!r!r"r<><00>s 

 r<>c@sveZdZdZddd<04>Zedd<06><00>Zedd<08><00>Zed d
<EFBFBD><00>Zd d <0C>Z d d<0E>Z
dd<10>Z dd<12>Z dd<14>Z dd<16>Zdd<18>ZdS)rrzi
A feature identifier that's specialized to put additional
constraints, default values, etc.
NcCs^|dks t<00>||_||_||_|jdkr6d|jf|_n$|jdkrNd|jf|_n d|jf|_dS)N)Nr<4E>r<>r<>r<>r<>r:r)r<><00>_name<6D>_default<6C>_display<61>_sortkey)r$r<>r|r<>r!r!r"rq<00>s 

zFeature.__init__cCs|jS)zThe name of this feature.)r<>)r$r!r!r"r<><00>sz Feature.namecCs|jS)zDefault value for this feature.)r<>)r$r!r!r"r|<00>szFeature.defaultcCs|jS)z1Custom display location: can be prefix, or slash.)r<>)r$r!r!r"r<><00>szFeature.displaycCs
d|jS)Nz*%s*)r<>)r$r!r!r"r_szFeature.__repr__cCs0t|t<01>rdSt|t<02>s$td||<01>|j|jkS)NT<4E><)rrrrr r<>)r$r*r!r!r"r1s


 zFeature.__lt__cCst|<00>t|<01>ko|j|jkS)N)<02>typer<65>)r$r*r!r!r"r- szFeature.__eq__cCs
||k S)Nr!)r$r*r!r!r"r.szFeature.__ne__cCs
t|j<01>S)N)r=r<>)r$r!r!r"r6szFeature.__hash__cCs|<04>|||<03>S)N)<01>
read_value)r$<00>s<>positionrN<00>parserr!r!r"rszFeature.read_valuecCs||kr |StSdS)zp
If possible, return a single value.. If not, return
the value ``UnificationFailure``.
N)r<>)r$r<>r<>rPr!r!r"r<>szFeature.unify_base_values)NN)r/rarbrcrq<00>propertyr<79>r|r<>r_r1r-r.r6rr<>r!r!r!r"rr<00>s
   rrc@seZdZdd<02>ZdS)<04> SlashFeaturecCs|<04>|||<03>S)N)<01> read_partial)r$rrrNrr!r!r"r'szSlashFeature.read_valueN)r/rarbrr!r!r!r"r&src@s&eZdZe<03>d<01>Zdd<03>Zdd<05>ZdS)<07> RangeFeaturez(-?\d+):(-?\d+)cCs@|j<00>||<02>}|std|<02><02>t|<05>d<02><01>t|<05>d<03><01>f|<05><05>fS)Nr<4E>r:r<>)<06>RANGE_RErrgr><00>group<75>end)r$rrrNr<00>mr!r!r"r.s
zRangeFeature.read_valuecCsT|dkr |S|dkr|St|d|d<00>t|d|d<00>f}|d|dkrPtS|S)Nrr:)r<><00>minr<6E>)r$r<>r<>rP<00>rngr!r!r"r<>4s$zRangeFeature.unify_base_valuesN)r/rarbr<><00>compiler rr<>r!r!r!r"r+s
rr<>)r|r<>rr<>)r<>c@s8eZdZdZdd<03>Zdd<05>Zdd<07>Zdd <09>Zd
d <0B>Zd S) r<>a<>
An abstract base class for base values that define a custom
unification method. The custom unification method of
``CustomFeatureValue`` will be used during unification if:
- The ``CustomFeatureValue`` is unified with another base value.
- The ``CustomFeatureValue`` is not the value of a customized
``Feature`` (which defines its own unification method).
If two ``CustomFeatureValue`` objects are unified with one another
during feature structure unification, then the unified base values
they return *must* be equal; otherwise, an ``AssertionError`` will
be raised.
Subclasses must define ``unify()``, ``__eq__()`` and ``__lt__()``.
Subclasses may also wish to define ``__hash__()``.
cCs td<01><01>dS)z<>
If this base value unifies with ``other``, then return the
unified value. Otherwise, return ``UnificationFailure``.
zabstract base classN)r#)r$r*r!r!r"rY\szCustomFeatureValue.unifycCs td<01><01>dS)Nzabstract base class)r#)r$r*r!r!r"r-cszCustomFeatureValue.__eq__cCs
||k S)Nr!)r$r*r!r!r"r.fszCustomFeatureValue.__ne__cCs td<01><01>dS)Nzabstract base class)r#)r$r*r!r!r"r1iszCustomFeatureValue.__lt__cCstd|jj<00><01>dS)Nz%s objects or unhashable)rr r/)r$r!r!r"r6lszCustomFeatureValue.__hash__N) r/rarbrcrYr-r.r1r6r!r!r!r"r<>Hs r<>c @s<>eZdZeefeedfdd<03>ZdIdd<05>Ze <09>
d<06>Z e <09>
d<07>Z e <09>
d<08>Z e <09>
d <09>Ze <09>
d
<EFBFBD>Ze <09>
d <0B>Ze <09>
d <0C>Ze <09>
d <0A>Ze <09>
d<0E>Ze <09>
deje jejejf<00>ZdJdd<12>ZdKdd<14>Zdd<16>Zdd<18>Zdd<1A>Zdd<1C>Zdd<1E>Zdd <20>Zd!e fd"e <09>
d#<23>fd$e <09>
d%<25>fd&e <09>
d'<27>fd(e <09>
d)<29>fd*e <09>
d+<2B>fd,e <09>
d-<2D>fd.e <09>
d/<2F>fd0e <09>
d1<EFBFBD>fg Zd2d3<64>Zd4d5<64>Z d6d7<64>Z!d8d9<64>Z"dd:d;d<<3C>Z#d=d><3E>Z$d?d@<40>Z%dAdB<64>Z&dCdD<64>Z'dEdF<64>Z(dGdH<64>Z)dS)LrNcCs<>tdd<02>|D<00><01>|_||_||_d|_d|_xH|D]@}|jdkrT|jrNtd<04><01>||_|jdkr2|jrltd<06><01>||_q2Wdd<08>|D<00>|_|dkr<>t <09>}||_
dS) Ncss|]}|j|fVqdS)N)r<>)r<><00>fr!r!r"r<>}sz,FeatStructReader.__init__.<locals>.<genexpr>r<>z"Multiple features w/ display=slashr<68>z#Multiple features w/ display=prefixcSsg|]}|jdk r|<01>qS)N)r|)r<><00>featurer!r!r"r<><00>sz-FeatStructReader.__init__.<locals>.<listcomp>) rs<00> _features<65> _fdict_class<73> _flist_class<73>_prefix_feature<72>_slash_featurer<65>rgZ_features_with_defaultsr <00> _logic_parser)r$rZ fdict_classZ flist_classZ logic_parserrr!r!r"rqvs$



zFeatStructReader.__init__cCs:|<01><00>}|<00>|di|<02>\}}|t|<01>kr6|<00>|d|<04>|S)aK
Convert a string representation of a feature structure (as
displayed by repr) into a ``FeatStruct``. This process
imposes the following restrictions on the string
representation:
- Feature names cannot contain any of the following:
whitespace, parentheses, quote marks, equals signs,
dashes, commas, and square brackets. Feature names may
not begin with plus signs or minus signs.
- Only the following basic feature value are supported:
strings, integers, variables, None, and unquoted
alphanumeric strings.
- For reentrant values, the first mention must specify
a reentrance identifier and a value; and any subsequent
mentions must use arrows (``'->'``) to reference the
reentrance identifier.
rz end of string)<04>striprr0<00>_error)r$rr<>r<>rr!r!r"ro<00>s
 zFeatStructReader.fromstringz$\s*(?:\((\d+)\)\s*)?(\??[\w-]+)?(\[)z\s*]\s*<2A>/z&\s*([+-]?)([^\s\(\)<>"\'\-=\[\],]+)\s*z\s*->\s*z\s*\((\d+)\)\s*z\s*=\s*z\s*,\s*z$\s*(?:\((\d+)\)\s*)?(\??[\w-]+\s*)()z#(%s)|(%s\s*(%s\s*(=|->)|[+-]%s|\]))rc
Csf|dkr i}y|<00>||||<04>Stk
r`}z&t|j<03>dkr><3E>|j|f|j<03><02>Wdd}~XYnXdS)a<>
Helper function that reads in a feature structure.
:param s: The string to read.
:param position: The position in the string to start parsing.
:param reentrances: A dictionary from reentrance ids to values.
Defaults to an empty dictionary.
:return: A tuple (val, pos) of the feature structure created by
parsing and the position where the parsed feature structure ends.
:rtype: bool
Nr<4E>)<05> _read_partialrgr0rhr)r$rrrNr<><00>er!r!r"r<00>s zFeatStructReader.read_partialcCs<>|dkr(|j<00>||<02>r |<00><02>}n|<00><03>}|j<04>||<02>}|sV|j<05>||<02>}|sVtd|<02><02>|<05><07>}|<05>d<02>r<>|<05>d<02>}||kr<>td|<05> d<02><01><02>|||<t
|t <0B>r<>|<04> <0C>|<00> |||||<04>S|dd<00>=|<00>|||||<04>SdS)Nzopen bracket or identifierr:znew identifier)rrrr<00>_START_FSTRUCT_RE<52>_BARE_PREFIX_RErgr r
<00>startrrr<><00>_read_partial_featdict<63>_read_partial_featlist)r$rrrNr<>r<00>
identifierr!r!r"r<00>s(





zFeatStructReader._read_partialcCs*|<03>d<01>rtd<02><01>|<03>d<03>s$td<02><01>x<>|t|<01>k<00>r|j<03>||<02>}|dk rV||<03><05>fS|j<06>||<02>}|r<>|<03><05>}|j<07>||<02>}|s<>td|<02><02>|<03>d<05>}||kr<>td|<02><02>|<03><05>}|<05>||<00>n|<00> d|||<04>\}}|<05>|<07>|j<03>||<02>r<>q&|j
<EFBFBD>||<02>}|dk<08>rtd|<02><02>|<03><05>}q&Wtd |<02><02>dS)
Nr<EFBFBD>z open bracketr<74>r"r:zbound identifierr<00>commaz close bracket) r
rgr0<00>_END_FSTRUCT_RErr <00>_REENTRANCE_RE<52>
_TARGET_REr<EFBFBD><00> _read_value<75> _COMMA_RE)r$rrrrNr<><00>targetr<74>r!r!r"r!<00>s8

 





 z'FeatStructReader._read_partial_featlistc
Cs<>|<03>d<01>rN|jdkr$td|<03>d<01><01><02>|<03>d<01><01><04>}|<06>d<03>rDt|<06>}|||j<|<03>d<04>sl|<00>||<03><08>||<05>S<00>x|t |<01>k<00>rpd}}|j
<EFBFBD> ||<02>}|dk r<>|<00>||<03><08>||<05>S|j <0C> ||<02>}|dkr<>td|<02><02>|<03>d<01>}|<03><08>}|ddk<02>r,|ddk<02>r,|j <0A>|d d<08><00>}|dk<08>r,td
|<03>d<01><01><02>||k<06>rFtd |<03>d<01><01><02>|<03>d <09>d k<02>rZd }|<03>d <09>dk<02>rnd}|dk<08>r<>|j<0F> ||<02>}|dk <09>r<>|<03><08>}|j<10> ||<02>}|<03>s<>td|<02><02>|<03>d <09>} | |k<07>r<>td|<02><02>|<03><08>}|| }|dk<08>r*|j<11> ||<02>}|<03>r |<03><08>}|<00>||||<04>\}}n
td|<02><02>|||<|j
<EFBFBD> ||<02><02>rDqp|j<13> ||<02>}|dk<08>rftd|<02><02>|<03><08>}qpWtd|<02><02>dS)Nr<4E>zopen bracket or identifierr<72>r<>z feature namer<00>*r<>r:zknown special featureznew namer<65>T<>-Fr"zbound identifierz equals signr#z close bracket)r
rrgrr<00>
startswithr
<00> _finalizer r0r$r<00>_FEATURE_NAME_RErr}r%r&<00>
_ASSIGN_REr'r()
r$rrrrNr<>Z prefixvalr<6C>r<>r)r!r!r"r  sn


















 z'FeatStructReader._read_partial_featdictcCs@|j<00>||<02>}|r8|j}|<00>|||<05><04>|<03>\}}|||<||fS)zw
Called when we see the close brace -- checks for a slash feature,
and adds in default values.
)<05> _SLASH_RErrr'r )r$r<00>posrNr<>rr<>r<>r!r!r"r-} s zFeatStructReader._finalizecCs,t|t<01>r|<01>||||<00>S|<00>|||<04>SdS)N)rrrr)r$r<>rrrNr!r!r"r'<00> s
zFeatStructReader._read_valuecCsJx:|jD]0\}}|<05>||<02>}|rt||<04>}|||||<06>SqWtd|<02><02>dS)Nr<4E>)<04>VALUE_HANDLERSrr<>rg)r$rrrN<00>handler<65>regexprZ handler_funcr!r!r"r<00> s  
zFeatStructReader.read_valuecCsf|<01>d<01>}x*|t|d<00>kr4|t|<04>d<02><01>d8}q Wd|ddd|dd|}t|<05><01>dS) Nr<4E>rr:z$Error parsing feature structure
z
r<>z^ z Expected %s)<04>splitr0r<>rg)r$r<00>expectedrr<>Zestrr!r!r"r<00> s

$zFeatStructReader._error<6F>read_fstruct_value<75>read_var_valuez\?[a-zA-Z_][a-zA-Z0-9_]*<2A>read_str_valuez[uU]?[rR]?(['"])<29>read_int_valuez-?\d+<2B>read_sym_valuez[a-zA-Z_][a-zA-Z0-9_]*<2A>read_app_valuez0<(app)\((\?[a-z][a-z]*)\s*,\s*(\?[a-z][a-z]*)\)><3E>read_logic_valuez <(.*?)(?<!-)><3E>read_set_value<75>{<7B>read_tuple_valuez\(cCs|<00>|||<03>S)N)r)r$rrrNrr!r!r"r7<00> sz#FeatStructReader.read_fstruct_valuecCs
t||<02>S)N)r)r$rrrNrr!r!r"r9<00> szFeatStructReader.read_str_valuecCst|<04><01><00>|<04><02>fS)N)r>r
r )r$rrrNrr!r!r"r:<00> szFeatStructReader.read_int_valuecCst|<04><01><00>|<04><02>fS)N)r
r
r )r$rrrNrr!r!r"r8<00> szFeatStructReader.read_var_valueTF)<03>None<6E>True<75>FalsecCs$|<04><00>|<04><01>}}|j<02>||<05>|fS)N)r
r <00> _SYM_CONSTSr})r$rrrNrrzr r!r!r"r;<00> szFeatStructReader.read_sym_valuecCs |j<00>d|<04>dd<03><00>|<04><03>fS)z%Mainly included for backwards compat.z%s(%s)r<>r<>)r<00>parser
r )r$rrrNrr!r!r"r<<00> szFeatStructReader.read_app_valuecCshy>y|j<00>|<04>d<01><01>}Wntk
r2t<04><00>YnX||<04><05>fStk
rbtd|<04>d<01><01><02>YnXdS)Nr:zlogic expression)rrEr
rrgr r)r$rrrNr<00>exprr!r!r"r=<00> s  z!FeatStructReader.read_logic_valuec Cs|<00>||||dtt<02>S)N<>))<03>_read_seq_valuer<65>r<>)r$rrrNrr!r!r"r@<00> sz!FeatStructReader.read_tuple_valuec Cs|<00>||||dtt<02>S)N<>})rHr<>r<>)r$rrrNrr!r!r"r><00> szFeatStructReader.read_set_valuec Cs<>t<00>|<05>}|<04><02>}t<00>d|<00><01>||<02>} | r:|<06>| <09><02>fSg}
d} x<>t<00>d|<00><01>||<02>} | r<>| rr||
<EFBFBD>| <09><02>fS||
<EFBFBD>| <09><02>fS|<00>|||<03>\} }|
<EFBFBD>| <0C>t<00>d|<00><01>||<02>} | s<>td||<02><02>| <09>d<06>dkr<>d} | <09><02>}qDWd S)
zN
Helper function used by read_tuple_value and read_set_value.
z
\s*/?\s*%sFz\s*%sz\s*(,|\+|(?=%s))\s*z',' or '+' or '%s'r:r<>TN) r<><00>escaper rrrr<>rgr
) r$rrrNrZ close_parenZ seq_classZ
plus_class<EFBFBD>cpr r<>Z seen_plusrzr!r!r"rH<00> s*

z FeatStructReader._read_seq_value)N)rNN)N)*r/rarb<00>SLASH<53>TYPErrrqror<>rrr$r0r.r%r&r/r(r<00>patternrrrr!r r-r'rrr2r7r9r:r8rDr;r<r=r@r>rHr!r!r!r"rusb 









 

.]    
   
r<00> c
s<>d|<00>d<02>}d|<00>d<02>}t|<03>t|<04>kr\ddt|d<00>dd}||gt|<03>7}n.ddt|d<00>dd}||gt|<04>7}x*t||<04>D]\}}t<03>|d|<00>q<>Wt<03>d t|d<00>dd t|d<00><00>t|d<00>dd
<00>t<03>d <0B><04><01><00>t<03>d <0C><04><01><00>t<03>d <0A><04><01><00>t<03>d<0E><04><01><00>i}|<00>||<08>} | dk<08>rlt<03>d<0F><04><01><00>nRtd<02><06><00>fdd<11>d| <00>d<02>D<00><01><01>|<08>r<>t|<08><07><00>dk<04>r<>tt|<08><01><04><01><01>| S)Nz%sr<73><00>[r<>rr<><00>]z r+r<>z| |z+-----UNIFY-----+r<><00>Vz(FAILED)c3s|]}<01>|<01><00><01>VqdS)N)<01>center)r<>r<>)rm<00>linelenr!r"r<>9
sz&display_unification.<locals>.<genexpr>) r5r0<00>zipr<70>rSrYr<>Zbound_variablesr<73>)
<EFBFBD>fs1<73>fs2rmZ fs1_linesZ fs2_linesZ blanklineZfs1_lineZfs2_linerPr<>r!)rmrTr"<00>display_unification
s0, 
&rXcs>ddl}ddl}d}td<03>td<04>|j<03><04>ddddd d
d d d dddddg<0E><00>fdd<14>tt<06><00><01>D<00>}dd<16>}<05>x<>d}t|<04>|kr<>t|<01>||<06><02>}n|}td<18>td<19>||<07>ddg}x<>dD]<5D>\} }
x<EFBFBD>||
dk<08>r<>td| t|<04>fdd<1D>y<>|j<03><04><00> <09>} | dk<06>rdS| dk<06>r,| }td |<00>w<>| d!k<06>rHt|t|<07><00>w<>| d"k<06>r\||<04>w<>t
| <0B>d#} || d#||
<t<02>Wq<>td$<24>w<>Yq<>Xq<>Wq<>W|<00>r<>|dj |d#d#d%<25>} nt |d|d#<00>} | dk <09>rx8|D]\}
}t | <0A>t |<0E>k<02>r<>P<00>q<>W|<04>t|<04>| f<02>td&<26>|j<03><04><00> <09>} | dkrtdSqtWdS)'Nrz<>
1-%d: Select the corresponding feature structure
q: Quit
t: Turn tracing on or off
l: List all feature structures
?: Help
a<>
This demo will repeatedly present you with a list of feature
structures, and ask you to choose two for unification. Whenever a
new feature structure is generated, it is added to the list of
choices that you can pick from. However, since this can be a
large number of feature structures, the demo will only print out a
random subset for you to choose between at a given time. If you
want to see the complete lists, type "l". For a list of valid
commands, type "?".
zPress "Enter" to continue...z [agr=[number=sing, gender=masc]]z[agr=[gender=masc, person=3]]z[agr=[gender=fem, person=3]]z[subj=[agr=(1)[]], agr->(1)]z[obj=?x]z [subj=?x]z[/=None]z[/=NP]z[cat=NP]z[cat=VP]z[cat=PP]z/[subj=[agr=[gender=?y]], obj=[agr=[gender=?y]]]z[gender=masc, agr=?C]z%[gender=?S, agr=[gender=?S,person=3]]csg|]}|t<00>|<00>f<02>qSr!)r)r<><00>i)<01>fstruct_stringsr!r"r<>l
sz$interactive_demo.<locals>.<listcomp>cSsjx^|D]V\}}t<00>d|<00>d<02>}td|d|df<00>x |dd<00>D]}td|<00>qHWqWt<00>dS)Nz%sr<73>z%3d: %sr:rz )r<>r5)<05>fstructsrYr<>r<>r<>r!r!r"<00> list_fstructso
sz'interactive_demo.<locals>.list_fstructs<74>ZK___________________________________________________________________________z'Choose two feature structures to unify:))ZFirstr)ZSecondr:z%%s feature structure (1-%d,q,t,l,?): r<>)r )<04>q<>Q<>x<>X)<02>t<>Tz Trace = %s)<03>h<>Hr<48>)r<><00>Lr:zBad sentence number)rZz3
Type "Enter" to continue unifying; or "q" to quit.)<0F>random<6F>sysr<73><00>stdin<69>readliner<65>r0r<<00>samplerr>rYrXr<>r<>)rZrgrhZHELP<4C> all_fstructsr\Z MAX_CHOICESr[<00>selectedZnthrY<00>input<75>numr<6D>r<>r!)rZr"<00>interactive_demo@
s<>

   

 

 

rpcCsfddddddddd d
d d d dg}dd<10>|D<00>}x2|D]*}x$|D]}td||t||<04>f<00>q>Wq4WdS)z
Just for testing
z [agr=[number=sing, gender=masc]]z[agr=[gender=masc, person=3]]z[agr=[gender=fem, person=3]]z[subj=[agr=(1)[]], agr->(1)]z[obj=?x]z [subj=?x]z[/=None]z[/=NP]z[cat=NP]z[cat=VP]z[cat=PP]z/[subj=[agr=[gender=?y]], obj=[agr=[gender=?y]]]z[gender=masc, agr=?C]z%[gender=?S, agr=[gender=?S,person=3]]cSsg|] }t|<01><01>qSr!)r)r<>Zfssr!r!r"r<><00>
szdemo.<locals>.<listcomp>z:
*******************
fs1 is:
%s
fs2 is:
%s
result is:
%sN)r<>rY)rZrZrlrVrWr!r!r"<00>demo<6D>
s(

rq<00>__main__rLrM)rf)r|)r|)r|)Nr!Nr|)r|)NFNTr|)r)rO)F)F)Urc<00>
__future__rrrr<>rD<00> functoolsr<00>sixrrZnltk.internalsrr Znltk.sem.logicr
r r r rZ nltk.compatrrrrdrlrnrsrr<>rrOr<>rQr<>rRr<>rTr<>r<>rXr<><00>objectr<74>r<>rY<00> Exceptionr<6E>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r]r<>rrr<>r<>rur<>r<>r<>r<>r<>r<>rrrrrLrMr<>rrXrprqr/<00>__all__r!r!r!r"<00><module>Zs<>  N
 
G



?!
 
sgy  
  

 
 
 
 
 
H  ,,
"
u
'