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

705 lines
55 KiB
Plaintext
Raw Normal View History

2019-10-20 13:16:49 +02:00
B
D(<28>]<5D><00> @srdZddlmZmZddlZddlZddlmZmZddl m
Z
m Z ddl m Z mZddlmZddlmZdd lmZmZdd
lmZeGd d <0C>d e<18><03>ZGd d<0E>de<19>Ze e<07>Gdd<10>de<19><03>ZGdd<12>de<1B>ZGdd<14>de<1B>ZGdd<16>dee<1C>ZGdd<18>dee<1D>ZeGdd<1A>dee<10><04>Z eGdd<1C>dee<10><04>Z!dd<1E>Z"dd <20>Z#d!d"<22>Z$d#d$<24>Z%ddd%dd d d"ddddg Z&dS)&zh
Class for representing hierarchical language structures, such as
syntax trees and morphological trees.
<EFBFBD>)<02>print_function<6F>unicode_literalsN)<02>ABCMeta<74>abstractmethod)<02> string_types<65> add_metaclass)<02>
Production<EFBFBD> Nonterminal)<01>ProbabilisticMixIn)<01> slice_bounds)<02>python_2_unicode_compatible<6C> unicode_repr)<01>raise_unorderable_typesc@s<>eZdZdZdjdd<04>Zdd<06>Zdd<08>Zd d
<EFBFBD>Zd d
<EFBFBD>Zd d
<EFBFBD>Z d d
<EFBFBD>Z
dd<0F>Z dd<11>Z dd<13>Z dd<15>Zdd<17>Zdd<19>Zdd<1B>Zdd<1D>Zdd<1F>Zeee<13>Zd d!<21>Zd"d#<23>Zd$d%<25>Zd&d'<27>Zd(d)<29>Zdkd+d,<2C>Zdld-d.<2E>Zd/d0<64>Zd1d2<64>Zd3d4<64>Zd5d6<64>Z dmd;d<<3C>Z!dnd?d@<40>Z"dodBdC<64>Z#e$dDdE<64><00>Z%dFdG<64>Z&dHdI<64>Z'dpdJdK<64>Z(dLdM<64>Z)dqdNdO<64>Z*e$drdQdR<64><01>Z+e$dSdT<64><00>Z,dUdV<64>Z-dsdXdY<64>Z.dZd[<5B>Z/d\d]<5D>Z0d^d_<64>Z1d`da<64>Z2dtddde<64>Z3dfdg<64>Z4dhdi<64>Z5dS)u<>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``.
NcCsP|dkrtdt|<00>j<00><01>n0t|t<04>r:tdt|<00>j<00><01>nt<05>||<02>||_dS)Nz)%s: Expected a node value and child list z.%s() argument 2 should be a list, not a string)<08> TypeError<6F>type<70>__name__<5F>
isinstancer<00>list<73>__init__<5F>_label)<03>self<6C>node<64>children<65>r<00>+/tmp/pip-install-4m6m_5d_/nltk/nltk/tree.pyrfs
 z Tree.__init__cCs(|j|jko&|jt|<00>f|jt|<01>fkS)N)<03> __class__rr)r<00>otherrrr<00>__eq__xsz Tree.__eq__cCsVt|t<01>s|jj|jjkS|j|jkrB|jt|<00>f|jt|<01>fkS|jj|jjkSdS)N)rrrrrr)rrrrr<00>__lt__~s

 z Tree.__lt__cCs
||k S)Nr)rrrrr<00><lambda><3E><00>z Tree.<lambda>cCs||kp||k S)Nr)rrrrrr <00>r!cCs||kp||kS)Nr)rrrrrr <00>r!cCs
||k S)Nr)rrrrrr <00>r!cCs td<01><01>dS)Nz$Tree does not support multiplication)r)r<00>vrrr<00>__mul__<5F>sz Tree.__mul__cCs td<01><01>dS)Nz$Tree does not support multiplication)r)rr"rrr<00>__rmul__<5F>sz Tree.__rmul__cCs td<01><01>dS)NzTree does not support addition)r)rr"rrr<00>__add__<5F>sz Tree.__add__cCs td<01><01>dS)NzTree does not support addition)r)rr"rrr<00>__radd__<5F>sz Tree.__radd__cCs<>t|ttf<02>rt<03>||<01>St|ttf<02>rjt|<01>dkr8|St|<01>dkrP||dS||d|dd<00>Sntdt|<00>j t|<01>j f<00><01>dS)Nr<00>z#%s indices must be integers, not %s)
r<00>int<6E>slicer<00> __getitem__<5F>tuple<6C>lenrrr)r<00>indexrrrr*<00>s    zTree.__getitem__cCs<>t|ttf<02>rt<03>|||<02>St|ttf<02>rtt|<01>dkr@td<02><01>q<>t|<01>dkrZ|||d<q<>|||d|dd<00><ntdt |<00>j
t |<01>j
f<00><01>dS)Nrz,The tree position () may not be assigned to.r'z#%s indices must be integers, not %s) rr(r)r<00> __setitem__r+r,<00>
IndexErrorrrr)rr-<00>valuerrrr.<00>s 
 zTree.__setitem__cCs<>t|ttf<02>rt<03>||<01>St|ttf<02>rnt|<01>dkr>td<02><01>q<>t|<01>dkrV||d=q<>||d|dd<00>=ntdt |<00>j
t |<01>j
f<00><01>dS)Nrz(The tree position () may not be deleted.r'z#%s indices must be integers, not %s) rr(r)r<00> __delitem__r+r,r/rrr)rr-rrrr1<00>s  
  zTree.__delitem__cCs td<01><01>dS)zIOutdated method to access the node value; use the label() method instead.z#Use label() to access a node label.N)<01>NotImplementedError)rrrr<00> _get_node<64>szTree._get_nodecCs td<01><01>dS)zJOutdated method to set the node value; use the set_label() method instead.z+Use set_label() method to set a node label.N)r2)rr0rrr<00> _set_node<64>szTree._set_nodecCs|jS)a
Return the node label of the tree.
>>> t = Tree.fromstring('(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))')
>>> t.label()
'S'
:return: the node label (typically a string)
:rtype: any
)r)rrrr<00>label<65>s z
Tree.labelcCs
||_dS)ao
Set the node label of the tree.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.set_label("T")
>>> print(t)
(T (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))
:param label: the node label (typically a string)
:type label: any
N)r)rr5rrr<00> set_label<65>s zTree.set_labelcCs:g}x0|D](}t|t<01>r(|<01>|<02><03><00>q
|<01>|<02>q
W|S)a<>
Return the leaves of the tree.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.leaves()
['the', 'dog', 'chased', 'the', 'cat']
:return: a list containing this tree's leaves.
The order reflects the order of the
leaves in the tree's hierarchical structure.
:rtype: list
)rr<00>extend<6E>leaves<65>append)rr8<00>childrrrr8<00>s 

z Tree.leavescCst|<00><01>|<00><02><00>S)a<>
Return a flat version of the tree, with all non-root non-terminals removed.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> print(t.flatten())
(S the dog chased the cat)
:return: a tree consisting of this tree's root connected directly to
its leaves, omitting all intervening non-terminal nodes.
:rtype: Tree
)rr5r8)rrrr<00>flattens z Tree.flattencCs>d}x0|D](}t|t<01>r(t||<02><03><00>}q
t|d<02>}q
Wd|S)aG
Return the height of the tree.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.height()
5
>>> print(t[0,0])
(D the)
>>> t[0,0].height()
2
:return: The height of this tree. The height of a tree
containing no children is 1; the height of a tree
containing only leaves is 2; and the height of any other
tree is one plus the maximum of its children's
heights.
:rtype: int
rr')rr<00>max<61>height)rZmax_child_heightr:rrrr=s 

z Tree.height<68>preordercs|g}|dkr|<02>d<02>xNt|<00>D]B\<02>}t|t<03>rV|<03>|<01>}|<02><05>fdd<04>|D<00><01>q |<02><00>f<01>q W|dkrx|<02>d<02>|S)a.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.treepositions() # doctest: +ELLIPSIS
[(), (0,), (0, 0), (0, 0, 0), (0, 1), (0, 1, 0), (1,), (1, 0), (1, 0, 0), ...]
>>> for pos in t.treepositions('leaves'):
... t[pos] = t[pos][::-1].upper()
>>> print(t)
(S (NP (D EHT) (N GOD)) (VP (V DESAHC) (NP (D EHT) (N TAC))))
:param order: One of: ``preorder``, ``postorder``, ``bothorder``,
``leaves``.
)r><00> bothorderrc3s|]}<01>f|VqdS)Nr)<02>.0<EFBFBD>p)<01>irr<00> <genexpr>Msz%Tree.treepositions.<locals>.<genexpr>)Z postorderr?)r9<00> enumeraterr<00> treepositionsr7)r<00>orderZ positionsr:<00>childposr)rBrrE:s 



zTree.treepositionsccsH|r ||<00>r|Vx0|D](}t|t<01>rx|<02>|<01>D]
}|Vq2WqWdS)a
Generate all the subtrees of this tree, optionally restricted
to trees matching the filter function.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> for s in t.subtrees(lambda t: t.height() == 2):
... print(s)
(D the)
(N dog)
(V chased)
(D the)
(N cat)
:type filter: function
:param filter: the function to filter all local trees
N)rr<00>subtrees)r<00>filterr:ZsubtreerrrrHTs  

z Tree.subtreescCsRt|jt<02>std<01><01>tt|j<01>t|<00><01>g}x"|D]}t|t<07>r0||<02><08>7}q0W|S)a
Generate the productions that correspond to the non-terminal nodes of the tree.
For each subtree of the form (P: C1 C2 ... Cn) this produces a production of the
form P -> C1 C2 ... Cn.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.productions()
[S -> NP VP, NP -> D N, D -> 'the', N -> 'dog', VP -> V NP, V -> 'chased',
NP -> D N, D -> 'the', N -> 'cat']
:rtype: list(Production)
zPProductions can only be generated from trees having node labels that are strings) rrrrrr <00> _child_namesr<00> productions)rZprodsr:rrrrKls 

zTree.productionscCs@g}x6|D].}t|t<01>r(|<01>|<02><03><00>q
|<01>||jf<02>q
W|S)a<>
Return a sequence of pos-tagged words extracted from the tree.
>>> t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))")
>>> t.pos()
[('the', 'D'), ('dog', 'N'), ('chased', 'V'), ('the', 'D'), ('cat', 'N')]
:return: a list of tuples containing leaves and pre-terminals (part-of-speech tags).
The order reflects the order of the leaves in the tree's hierarchical structure.
:rtype: list(tuple)
)rrr7<00>posr9r)rrLr:rrrrL<00>s 

zTree.poscCs<>|dkrtd<02><01>|dfg}xj|r<>|<02><01>\}}t|t<03>sL|dkrB|S|d8}qx4tt|<03>ddd<05>D]}|<02>||||ff<02>qbWqWtd<06><01>dS)a,
:return: The tree position of the ``index``-th leaf in this
tree. I.e., if ``tp=self.leaf_treeposition(i)``, then
``self[tp]==self.leaves()[i]``.
:raise IndexError: If this tree contains fewer than ``index+1``
leaves, or if ``index<0``.
rzindex must be non-negativerr'<00><><EFBFBD><EFBFBD><EFBFBD>z-index must be less than or equal to len(self)N)r/<00>poprr<00>ranger,r9)rr-<00>stackr0<00>treeposrBrrr<00>leaf_treeposition<6F>s 
 

 zTree.leaf_treepositioncCsj||krtd<01><01>|<00>|<01>}|<00>|d<00>}x<tt|<03><01>D],}|t|<04>ksV||||kr6|d|<05>Sq6W|S)z<>
:return: The tree position of the lowest descendant of this
tree that dominates ``self.leaves()[start:end]``.
:raise ValueError: if ``end <= start``
zend must be greater than startr'N)<04>
ValueErrorrRrOr,)r<00>start<72>endZ start_treeposZ end_treeposrBrrr<00>treeposition_spanning_leaves<65>s
z!Tree.treeposition_spanning_leaves<65>rightr<00>|<7C>^cCs"ddlm}|||||||<05>dS)a<>
This method can modify a tree in three ways:
1. Convert a tree into its Chomsky Normal Form (CNF)
equivalent -- Every subtree has either two non-terminals
or one terminal as its children. This process requires
the creation of more"artificial" non-terminal nodes.
2. Markov (vertical) smoothing of children in new artificial
nodes
3. Horizontal (parent) annotation of nodes
:param factor: Right or left factoring method (default = "right")
:type factor: str = [left|right]
:param horzMarkov: Markov order for sibling smoothing in artificial nodes (None (default) = include all siblings)
:type horzMarkov: int | None
:param vertMarkov: Markov order for parent smoothing (0 (default) = no vertical annotation)
:type vertMarkov: int | None
:param childChar: A string used in construction of the artificial nodes, separating the head of the
original subtree from the child nodes that have yet to be expanded (default = "|")
:type childChar: str
:param parentChar: A string used to separate the node representation from its vertical annotation
:type parentChar: str
r)<01>chomsky_normal_formN)<02>nltk.treetransformsrZ)rZfactorZ
horzMarkovZ
vertMarkov<EFBFBD> childChar<61>
parentCharrZrrrrZ<00>s zTree.chomsky_normal_formT<6D>+cCs ddlm}||||||<04>dS)al
This method modifies the tree in three ways:
1. Transforms a tree in Chomsky Normal Form back to its
original structure (branching greater than two)
2. Removes any parent annotation (if it exists)
3. (optional) expands unary subtrees (if previously
collapsed with collapseUnary(...) )
:param expandUnary: Flag to expand unary or not (default = True)
:type expandUnary: bool
:param childChar: A string separating the head node from its children in an artificial node (default = "|")
:type childChar: str
:param parentChar: A sting separating the node label from its parent annotation (default = "^")
:type parentChar: str
:param unaryChar: A string joining two non-terminals in a unary production (default = "+")
:type unaryChar: str
r)<01>un_chomsky_normal_formN)r[r_)rZ expandUnaryr\r]Z unaryCharr_rrrr_<00>s zTree.un_chomsky_normal_formFcCsddlm}|||||<03>dS)a
Collapse subtrees with a single child (ie. unary productions)
into a new non-terminal (Tree node) joined by 'joinChar'.
This is useful when working with algorithms that do not allow
unary productions, and completely removing the unary productions
would require loss of useful information. The Tree is modified
directly (since it is passed by reference) and no value is returned.
:param collapsePOS: 'False' (default) will not collapse the parent of leaf nodes (ie.
Part-of-Speech tags) since they are always unary productions
:type collapsePOS: bool
:param collapseRoot: 'False' (default) will not modify the root production
if it is unary. For the Penn WSJ treebank corpus, this corresponds
to the TOP -> productions.
:type collapseRoot: bool
:param joinChar: A string used to connect collapsed node values (default = "+")
:type joinChar: str
r)<01>collapse_unaryN)r[r`)rZ collapsePOSZ collapseRootZjoinCharr`rrrr`s zTree.collapse_unarycs0t|t<01>r(<28>fdd<02>|D<00>}<02>|j|<02>S|SdS)a
Convert a tree between different subtypes of Tree. ``cls`` determines
which class will be used to encode the new tree.
:type tree: Tree
:param tree: The tree that should be converted.
:return: The new Tree.
csg|]}<01><00>|<01><01>qSr)<01>convert)r@r:)<01>clsrr<00>
<listcomp>+sz Tree.convert.<locals>.<listcomp>N)rrr)rb<00>treerr)rbrra s
 z Tree.convertcCs|<00><00>S)N)<01>copy)rrrr<00>__copy__0sz Tree.__copy__cCs |jdd<02>S)NT)<01>deep)re)r<00>memorrr<00> __deepcopy__3szTree.__deepcopy__cCs&|st|<00>|j|<00>St|<00><01>|<00>SdS)N)rrra)rrgrrrre6sz Tree.copycCstS)N)<01> ImmutableTree)rrrr<00> _frozen_class=szTree._frozen_classcCsb|<00><00>}|dkr|<02>|<00>}n:|jdd<02>}x"|<03>d<03>D]}|||<00>||<q4W|<02>|<03>}t|<03>|S)NT)rgr8)rkrarerE<00>hash)rZ leaf_freezerZ frozen_classZnewcopyrLrrr<00>freeze@s  
z Tree.freeze<7A>()cCs<>t|t<01>rt|<02>dkrtd<02><01>t<04>d|<02>r2td<04><01>|\}} t<04>|<08>t<04>| <09>}
} |dkrdd|
| f}|dkrxd|
| f}t<04>d|
|| |f<00>} dgfg} <0A>x<| <0C>|<01>D<00>],}|<0E> <09>}|d|k<02>r"t| <0A>d kr<>t| dd <00>dkr<>|<00>
||d
<EFBFBD>|d d<05><00> <0B>}|dk <09>r||<10>}| <0A> |gf<02>q<>|| k<02>r<>t| <0A>d k<02>rnt| dd <00>dk<02>r`|<00>
|||<08>n|<00>
||d
<EFBFBD>| <0A> <0A>\}}| d d <00> |||<11><02>q<>t| <0A>d k<02>r<>|<00>
|||<08>|dk <09>r<>||<0F>}| d d <00> |<0F>q<>Wt| <0A>d k<04>r<>|<00>
|d
| <09>nVt| dd <00>dk<02>r|<00>
|d
|<08>n0| dddk<08>s2t<0E>t| dd <00>d k<02>sLt<0E>| dd d}|<07>r<>|jd k<02>r<>t|<12>d k<02>r<>|d}|S) a'
Read a bracketed tree string and return the resulting tree.
Trees are represented as nested brackettings, such as::
(S (NP (NNP John)) (VP (V runs)))
:type s: str
:param s: The string to read
:type brackets: str (length=2)
:param brackets: The bracket characters used to mark the
beginning and end of trees and subtrees.
:type read_node: function
:type read_leaf: function
:param read_node, read_leaf: If specified, these functions
are applied to the substrings of ``s`` corresponding to
nodes and leaves (respectively) to obtain the values for
those nodes and leaves. They should have the following
signature:
read_node(str) -> value
For example, these functions could be used to process nodes
and leaves whose values should be some type other than
string (such as ``FeatStruct``).
Note that by default, node strings and leaf strings are
delimited by whitespace and brackets; to override this
default, use the ``node_pattern`` and ``leaf_pattern``
arguments.
:type node_pattern: str
:type leaf_pattern: str
:param node_pattern, leaf_pattern: Regular expression patterns
used to find node and leaf substrings in ``s``. By
default, both nodes patterns are defined to match any
sequence of non-whitespace non-bracket characters.
:type remove_empty_top_bracketing: bool
:param remove_empty_top_bracketing: If the resulting tree has
an empty node label, and is length one, then return its
single child instead. This is useful for treebank trees,
which sometimes contain an extra level of bracketing.
:return: A tree corresponding to the string representation ``s``.
If this class method is called using a subclass of Tree,
then it will return a tree of that type.
:rtype: Tree
<20>z"brackets must be a length-2 stringz\szwhitespace brackets not allowedNz
[^\s%s%s]+z%s\s*(%s)?|%s|(%s)rr'z end-of-stringrM<00>)rrr,r<00>re<72>search<63>escape<70>compile<6C>finditer<65>group<75> _parse_error<6F>lstripr9rN<00>AssertionErrorr)rb<00>sZbracketsZ read_nodeZ read_leafZ node_patternZ leaf_pattern<72>remove_empty_top_bracketingZopen_bZclose_bZ open_patternZ close_patternZtoken_rerP<00>match<63>tokenr5rrdrrr<00>
fromstringPsZ<   
 

 
 zTree.fromstringcCs<>|dkrt|<01>d}}n|<02><01>|<02><02>}}d|j||d|f}|<01>dd<05><02>dd<05>}|}t|<01>|dkrz|d|d<00>d }|dkr<>d ||dd<08>}d
}|d d |dd |f7}t|<06><01>dS)z<>
Display a friendly error message when parsing a tree string fails.
:param s: The string we're parsing.
:param match: regexp match of the problem token.
:param expecting: what we expected to see instead.
z end-of-stringz0%s.read(): expected %r but got %r
%sat index %d.z <20>
<EFBFBD> <20> <09>
Nz...<2E> z
%s"%s"
%s^z <20>)r,rTrvr<00>replacerS)rbrzr|Z expectingrLr}<00>msg<73>offsetrrrrw<00>s$ zTree._parse_errorcCsddlm}||<00>dS)zP
Open a new window containing a graphical diagram of this tree.
r)<01>
draw_treesN)<02>nltk.draw.treer<65>)rr<>rrr<00>draw<61>s z Tree.drawrcKs,ddlm}t||||<02>jf|<04>|d<03>dS)z<>
Pretty-print this tree as ASCII or Unicode art.
For explanation of the arguments, see the documentation for
`nltk.treeprettyprinter.TreePrettyPrinter`.
r)<01>TreePrettyPrinter)<01>fileN)Znltk.treeprettyprinterr<72><00>print<6E>text)rZsentenceZ highlight<68>stream<61>kwargsr<73>rrr<00> pretty_print<6E>s zTree.pretty_printcCs.d<01>dd<03>|D<00><01>}dt|<00>jt|j<04>|fS)Nz, css|]}t|<01>VqdS)N)r )r@<00>crrrrC<00>sz Tree.__repr__.<locals>.<genexpr>z %s(%s, [%s]))<05>joinrrr r)rZchildstrrrr<00>__repr__<5F>s
z Tree.__repr__c
Csjddl}ddl}ddl}ddl}ddlm}ddlm}ddlm }|<06>}||<08>
<EFBFBD>|<00>} |<08> | <09>| <09> <0C>\}
} } } dd| | f|<08>
<EFBFBD>d<|<04> <0A><00><>}d<07>|j<0F>}d<08>|j<0F>}|<08>|<0F>|<08>| <09>y2|<03>|d d
d gd gd d<0E>gd<0F>||<0F><02><13><00>Wn0tk
<EFBFBD>rtd<10>}t|tjd<11>t<14>YnXt|d<12><02>}|<12><1A>}WdQRX|<01>|<0F>|<01>|<10>|<02>|<13><01><1D>SQRXdS)z<>
Draws and outputs in PNG for ipython.
PNG is used instead of PDF, since it can be displayed in the qt console and
has wider browser support.
rN)<01>tree_to_treesegment)<01> CanvasFrame)<01> find_binaryZ scrollregionz{0:}.psz{0:}.pngZgsz gswin32c.exez gswin64c.exe<78>PATHF)Z binary_namesZenv_vars<72>verbosezz-q -dEPSCrop -sDEVICE=png16m -r90 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dSAFER -dBATCH -dNOPAUSE -sOutputFile={0:} {1:}z<>The Ghostscript executable isn't found.
See http://web.mit.edu/ghostscript/www/Install.htm
If you're using a Mac, you can try installing
https://docs.brew.sh/Installation then `brew install ghostscript`)r<><00>rb)<1E>os<6F>base64<36>
subprocess<EFBFBD>tempfiler<65>r<>Znltk.draw.utilr<6C><00>nltk.internalsr<73>ZcanvasZ
add_widgetZbbox<6F>NamedTemporaryFile<6C>format<61>nameZ print_to_fileZdestroy_widget<65>call<6C>split<69> LookupError<6F>strr<72><00>sys<79>stderr<72>open<65>read<61>remove<76> b64encode<64>decode)rr<>r<>r<>r<>r<>r<>r<>Z _canvas_frameZwidget<65>x<>y<>w<>hr<68>Zin_pathZout_pathZpre_error_message<67>sr<73>resrrr<00>
_repr_png_sF   

  


 

zTree._repr_png_cCs|<00><00>S)N)<01>pformat)rrrr<00>__str__;sz Tree.__str__cKs4d|kr|d}|d=nd}t|jf|<01>|d<03>dS)zH
Print a string representation of this Tree to 'stream'
r<>N)r<>)r<>r<>)rr<>r<>rrr<00>pprint>s
z Tree.pprint<6E>Frpc
Cs|<00>|||<05>}t|<06>||kr"|St|jt<04>rDd|d|j|f}nd|dt|j<03>|f}x<>|D]<5D>}t|t<06>r<>|dd|d|<07>||d|||<05>7}qbt|t<08>r<>|dd|dd<06> |<07>7}qbt|t<04>r<>|s<>|dd|dd|7}qb|dd|dt|<07>7}qbW||dS) aI
:return: A pretty-printed string representation of this tree.
:rtype: str
:param margin: The right margin at which to do line-wrapping.
:type margin: int
:param indent: The indentation level at which printing
begins. This number is used to decide how far to indent
subsequent lines.
:type indent: int
:param nodesep: A string that is used to separate the node
from the children. E.g., the default value ``':'`` gives
trees like ``(S: (NP: I) (VP: (V: saw) (NP: it)))``.
z%s%s%srrr<>ro<00>/z%sr')
<EFBFBD> _pformat_flatr,rrrr rr<>r+r<>)r<00>margin<69>indent<6E>nodesep<65>parens<6E>quotesrzr:rrrr<>Js  

*
  z Tree.pformatcCs,t<00>d<01>}|jdddd<05>}dt<00>|d|<02>S)a<>
Returns a representation of the tree compatible with the
LaTeX qtree package. This consists of the string ``\Tree``
followed by the tree represented in bracketed notation.
For example, the following result was generated from a parse tree of
the sentence ``The announcement astounded us``::
\Tree [.I'' [.N'' [.D The ] [.N' [.N announcement ] ] ]
[.I' [.V'' [.V' [.V astounded ] [.N'' [.N' [.N us ] ] ] ] ] ] ]
See http://www.ling.upenn.edu/advice/latex.html for the LaTeX
style file for the qtree package.
:return: A latex qtree representation of this tree.
:rtype: str
z([#\$%&~_\{\}])<29>rp)z[.z ])r<>r<>r<>z\Tree z\\\1)rqrtr<><00>sub)rZreserved_charsr<73>rrr<00>pformat_latex_qtreers
zTree.pformat_latex_qtreecCs<>g}xt|D]l}t|t<01>r.|<04>|<05>|||<03><03>q
t|t<04>rJ|<04>d<01>|<05><01>q
t|t<06>rh|sh|<04>d|<00>q
|<04>t|<05><01>q
Wt|jt<06>r<>d|d|j|d<05>|<04>|dfSd|dt|j<08>|d<05>|<04>|dfSdS)Nr<4E>z%sz %s%s%s %s%srr<>r') rrr9r<>r+r<>rr r)rr<>r<>r<>Z childstrsr:rrrr<><00>s,


  zTree._pformat_flat)N)r>)N)rWNrrXrY)TrXrYr^)FFr^)F)N)rnNNNNF)NrN)r<>rrprnF)6r<00>
__module__<EFBFBD> __qualname__<5F>__doc__rrr<00>__ne__<5F>__gt__<5F>__le__<5F>__ge__r#r$r%r&r*r.r1r3r4<00>propertyrr5r6r8r;r=rErHrKrLrRrVrZr_r`<00> classmethodrarfrirerkrmr~rwr<>r<>r<>r<>r<>r<>r<>r<>r<>rrrrr%sv?
 
 




 

 p #
5
(rcs<>eZdZd <20>fdd<03> Zdd<05>Zdd<07>Zdd <09>Zd
d <0B>Zd d <0A>Zdd<0F>Z dd<11>Z
dd<13>Z d!dd<15>Z dd<17>Z dd<19>Zdd<1B>Zdd<1D>Zdd<1F>Z<11>ZS)"rjNc sZtt|<00><02>||<02>yt|jt|<00>f<02>|_Wn*ttfk
rTtdt |<00>j
<00><01>YnXdS)Nz-%s: node value and children must be immutable) <0B>superrjrrlrr+<00>_hashrrSrr)rrr)rrrr<00>s zImmutableTree.__init__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr-r0rrrr.<00>szImmutableTree.__setitem__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrB<00>jr0rrr<00> __setslice__<5F>szImmutableTree.__setslice__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr-rrrr1<00>szImmutableTree.__delitem__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrBr<>rrr<00> __delslice__<5F>szImmutableTree.__delslice__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrrrr<00>__iadd__<5F>szImmutableTree.__iadd__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrrrr<00>__imul__<5F>szImmutableTree.__imul__cCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr"rrrr9<00>szImmutableTree.appendcCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr"rrrr7<00>szImmutableTree.extendcCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr"rrrrN<00>szImmutableTree.popcCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rr"rrrr<><00>szImmutableTree.removecCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrrr<00>reverse<73>szImmutableTree.reversecCstdt|<00>j<00><01>dS)Nz%s may not be modified)rSrr)rrrr<00>sort<72>szImmutableTree.sortcCs|jS)N)r<>)rrrr<00>__hash__<5F>szImmutableTree.__hash__cCs&t|d<01>rtdt|<00>j<00><01>||_dS)z<>
Set the node label. This will only succeed the first time the
node label is set, which should occur in ImmutableTree.__init__().
rz%s may not be modifiedN)<05>hasattrrSrrr)rr0rrrr6<00>s
zImmutableTree.set_label)N)N)rr<>r<>rr.r<>r1r<>r<>r<>r9r7rNr<>r<>r<>r<>r6<00> __classcell__rr)rrrj<00>s 
rjcs<>eZdZdZd <20>fdd<04> Zed!dd<07><01>Zedd <09><00>Z<07>fd
d <0B>Z<08>fd d <0A>Z <09>fdd<0F>Z
<EFBFBD>fdd<11>Z <0B>fdd<13>Z d"<22>fdd<16> Z <0A>fdd<18>Zeed<19>r<>dd<1B>Zdd<1D>Zdd<1F>Z<13>ZS)#<23>AbstractParentedTreea<65>
An abstract base class for a ``Tree`` that automatically maintains
pointers to parent nodes. These parent pointers are updated
whenever any change is made to a tree's structure. Two subclasses
are currently defined:
- ``ParentedTree`` is used for tree structures where each subtree
has at most one parent. This class should be used in cases
where there is no"sharing" of subtrees.
- ``MultiParentedTree`` is used for tree structures where a
subtree may have zero or more parents. This class should be
used in cases where subtrees may be shared.
Subclassing
===========
The ``AbstractParentedTree`` class redefines all operations that
modify a tree's structure to call two methods, which are used by
subclasses to update parent information:
- ``_setparent()`` is called whenever a new child is added.
- ``_delparent()`` is called whenever a child is removed.
Ncsztt|<00><02>||<02>|dk rvx.t|<00>D]"\}}t|t<05>r$|j||dd<02>q$Wx*t|<00>D]\}}t|t<05>rT|<00>||<03>qTWdS)NT)<01>dry_run)r<>r<>rrDrr<00>
_setparent)rrrrBr:)rrrrs

zAbstractParentedTree.__init__FcCsdS)a<>
Update the parent pointer of ``child`` to point to ``self``. This
method is only called if the type of ``child`` is ``Tree``;
i.e., it is not called when adding a leaf to a tree. This method
is always called before the child is actually added to the
child list of ``self``.
:type child: Tree
:type index: int
:param index: The index of ``child`` in ``self``.
:raise TypeError: If ``child`` is a tree with an impropriate
type. Typically, if ``child`` is a tree, then its type needs
to match the type of ``self``. This prevents mixing of
different tree types (single-parented, multi-parented, and
non-parented).
:param dry_run: If true, the don't actually set the child's
parent pointer; just check for any error conditions, and
raise an exception if one is found.
Nr)rr:r-r<>rrrr<>szAbstractParentedTree._setparentcCsdS)a<>
Update the parent pointer of ``child`` to not point to self. This
method is only called if the type of ``child`` is ``Tree``; i.e., it
is not called when removing a leaf from a tree. This method
is always called before the child is actually removed from the
child list of ``self``.
:type child: Tree
:type index: int
:param index: The index of ``child`` in ``self``.
Nr)rr:r-rrr<00>
_delparent(s zAbstractParentedTree._delparentcs:t|t<01>rdt||dd<02>\}}}x2t|||<04>D]"}t||t<04>r,|<00>|||<05>q,Wtt|<00><02>|<01>n<>t|t <09>r<>|dkr<>|t
|<00>7}|dkr<>t d<04><01>t||t<04>r<>|<00>|||<01>tt|<00><02>|<01>ntt|t t f<02><02>rt
|<01>dkr<>t d<05><01>n0t
|<01>dk<02>r||d=n||d|dd<00>=ntdt|<00>jt|<01>jf<00><01>dS)NT)<01>
allow_steprzindex out of rangez(The tree position () may not be deleted.r'z#%s indices must be integers, not %s)rr)r rOrr<>r<>r<>r1r(r,r/rr+rrr)rr-rT<00>stop<6F>steprB)rrrr1<s.

  
 z AbstractParentedTree.__delitem__cs<>t|t<01>r<>t||dd<02>\}}}t|ttf<02>s4t|<02>}x6t|<02>D]*\}}t|t<06>r>|j||||dd<03>q>Wx2t|||<05>D]"}t||t<06>rz|<00> |||<06>qzWx2t|<02>D]&\}}t|t<06>r<>|<00>||||<00>q<>Wt
t |<00><02> ||<02><00>n t|t <0A><02>r||dk<00>r |t|<00>7}|dk<00>rtd<05><01>|||k<08>r0dSt|t<06><02>rH|<00>||<01>t||t<06><02>rh|<00> |||<01>t
t |<00><02> ||<02>nzt|ttf<02><02>r<>t|<01>dk<02>r<>td<06><01>n4t|<01>dk<02>r<>|||d<n|||d|dd<00><ntdt|<00>jt|<01>jf<00><01>dS) NT)r<>)r<>rzindex out of rangez,The tree position () may not be assigned to.r'z#%s indices must be integers, not %s)rr)r rr+rDrr<>rOr<>r<>r<>r.r(r,r/rrr)rr-r0rTr<>r<>rBr:)rrrr.dsF


 
 
  
z AbstractParentedTree.__setitem__cs.t|t<01>r|<00>|t|<00><01>tt|<00><02>|<01>dS)N)rrr<>r,r<>r<>r9)rr:)rrrr9<00>s
zAbstractParentedTree.appendcs<x6|D].}t|t<01>r$|<00>|t|<00><01>tt|<00><02>|<02>qWdS)N)rrr<>r,r<>r<>r9)rrr:)rrrr7<00>s

zAbstractParentedTree.extendcsL|dkr|t|<00>7}|dkr d}t|t<02>r6|<00>||<01>tt|<00><02>||<02>dS)Nr)r,rrr<>r<>r<><00>insert)rr-r:)rrrr<><00>s 
 zAbstractParentedTree.insertrMcsR|dkr|t|<00>7}|dkr$td<02><01>t||t<03>rB|<00>|||<01>tt|<00><02>|<01>S)Nrzindex out of range)r,r/rrr<>r<>r<>rN)rr-)rrrrN<00>s zAbstractParentedTree.popcs<|<00>|<01>}t||t<02>r(|<00>|||<02>tt|<00><02>|<01>dS)N)r-rrr<>r<>r<>r<>)rr:r-)rrrr<><00>s
zAbstractParentedTree.remove<76> __getslice__cCs|<00>ttd|<01>td|<02><02><02>S)Nr)r*r)r<)rrTr<>rrrr<><00>sz!AbstractParentedTree.__getslice__cCs|<00>ttd|<01>td|<02><02><02>S)Nr)r1r)r<)rrTr<>rrrr<><00>sz!AbstractParentedTree.__delslice__cCs|<00>ttd|<01>td|<02><02>|<03>S)Nr)r.r)r<)rrTr<>r0rrrr<><00>sz!AbstractParentedTree.__setslice__)N)F)rM)rr<>r<>r<>rrr<>r<>r1r.r9r7r<>rNr<>r<>rr<>r<>r<>r<>rr)rrr<><00>s    ( <   
r<>csleZdZdZd<18>fdd<04> Zdd<06>Zdd<08>Zd d
<EFBFBD>Zd d <0C>Zd d<0E>Z dd<10>Z
dd<12>Z dd<14>Z ddd<17>Z <0A>ZS)<1A> ParentedTreea 
A ``Tree`` that automatically maintains parent pointers for
single-parented trees. The following are methods for querying
the structure of a parented tree: ``parent``, ``parent_index``,
``left_sibling``, ``right_sibling``, ``root``, ``treeposition``.
Each ``ParentedTree`` may have at most one parent. In
particular, subtrees may not be shared. Any attempt to reuse a
single ``ParentedTree`` as a child of more than one parent (or
as multiple children of the same parent) will cause a
``ValueError`` exception to be raised.
``ParentedTrees`` should never be used in the same tree as ``Trees``
or ``MultiParentedTrees``. Mixing tree implementations may result
in incorrect parent pointers and in ``TypeError`` exceptions.
NcsVd|_tt|<00><02>||<02>|dkrRx0t|<00>D]$\}}t|t<06>r*d|_|<00>||<03>q*WdS)N)<08>_parentr<74>r<>rrDrrr<>)rrrrBr:)rrrr<00>s
zParentedTree.__init__cCstS)N)<01>ImmutableParentedTree)rrrrrk<00>szParentedTree._frozen_classcCs|jS)z5The parent of this tree, or None if it has no parent.)r<>)rrrr<00>parentszParentedTree.parentcCsB|jdkrdSx"t|j<00>D]\}}||kr|SqWds>td<03><01>dS)aD
The index of this tree in its parent. I.e.,
``ptree.parent()[ptree.parent_index()] is ptree``. Note that
``ptree.parent_index()`` is not necessarily equal to
``ptree.parent.index(ptree)``, since the ``index()`` method
returns the first child that is equal to its argument.
NFz&expected to find self in self._parent!)r<>rDry)rrBr:rrr<00> parent_indexs 
zParentedTree.parent_indexcCs(|<00><00>}|jr$|dkr$|j|dSdS)z6The left sibling of this tree, or None if it has none.rr'N)r<>r<>)rr<>rrr<00> left_siblingszParentedTree.left_siblingcCs2|<00><00>}|jr.|t|j<01>dkr.|j|dSdS)z7The right sibling of this tree, or None if it has none.r'N)r<>r<>r,)rr<>rrr<00> right_siblingszParentedTree.right_siblingcCs"|}x|<01><00>dk r|<01><00>}qW|S)z<>
The root of this tree. I.e., the unique ancestor of this tree
whose parent is None. If ``ptree.parent()`` is None, then
``ptree`` is its own root.
N)r<>)r<00>rootrrrr<>#s zParentedTree.rootcCs*|<00><00>dkrdS|<00><00><00><01>|<00><02>fSdS)z<>
The tree position of this tree, relative to the root of the
tree. I.e., ``ptree.root[ptree.treeposition] is ptree``.
Nr)r<><00> treepositionr<6E>)rrrrr<>.s zParentedTree.treepositioncCs6t|t<01>st<02>|||kst<02>|j|ks,t<02>d|_dS)N)rr<>ryr<>)rr:r-rrrr<><szParentedTree._delparentFcCs2t|t<01>std<01><01>|jdk r$td<02><01>|s.||_dS)Nz5Can not insert a non-ParentedTree into a ParentedTreez3Can not insert a subtree that already has a parent.)rr<>rr<>rS)rr:r-r<>rrrr<>Es

zParentedTree._setparent)N)F)rr<>r<>r<>rrkr<>r<>r<>r<>r<>r<>r<>r<>r<>rr)rrr<><00>s  r<>cs|eZdZdZd<1C>fdd<04> Zdd<06>Zdd<08>Zd d
<EFBFBD>Zd d <0C>Zd d<0E>Z dd<10>Z
dd<12>Z dd<14>Z dd<16>Z dd<18>Zddd<1B>Z<0F>ZS)<1E>MultiParentedTreea 
A ``Tree`` that automatically maintains parent pointers for
multi-parented trees. The following are methods for querying the
structure of a multi-parented tree: ``parents()``, ``parent_indices()``,
``left_siblings()``, ``right_siblings()``, ``roots``, ``treepositions``.
Each ``MultiParentedTree`` may have zero or more parents. In
particular, subtrees may be shared. If a single
``MultiParentedTree`` is used as multiple children of the same
parent, then that parent will appear multiple times in its
``parents()`` method.
``MultiParentedTrees`` should never be used in the same tree as
``Trees`` or ``ParentedTrees``. Mixing tree implementations may
result in incorrect parent pointers and in ``TypeError`` exceptions.
NcsVg|_tt|<00><02>||<02>|dkrRx0t|<00>D]$\}}t|t<06>r*g|_|<00>||<03>q*WdS)N)<08>_parentsr<73>r<>rrDrrr<>)rrrrBr:)rrrrgs
zMultiParentedTree.__init__cCstS)N)<01>ImmutableMultiParentedTree)rrrrrkwszMultiParentedTree._frozen_classcCs
t|j<01>S)a
The set of parents of this tree. If this tree has no parents,
then ``parents`` is the empty set. To check if a tree is used
as multiple children of the same parent, use the
``parent_indices()`` method.
:type: list(MultiParentedTree)
)rr<>)rrrr<00>parents~s zMultiParentedTree.parentscCsdd<02>|<00><00>D<00>S)a}
A list of all left siblings of this tree, in any of its parent
trees. A tree may be its own left sibling if it is used as
multiple contiguous children of the same parent. A tree may
appear multiple times in this list if it is the left sibling
of this tree with respect to multiple parents.
:type: list(MultiParentedTree)
cSs$g|]\}}|dkr||d<00>qS)rr'r)r@r<>r-rrrrc<00>sz3MultiParentedTree.left_siblings.<locals>.<listcomp>)<01>_get_parent_indices)rrrr<00> left_siblings<67>s zMultiParentedTree.left_siblingscCsdd<02>|<00><00>D<00>S)a<>
A list of all right siblings of this tree, in any of its parent
trees. A tree may be its own right sibling if it is used as
multiple contiguous children of the same parent. A tree may
appear multiple times in this list if it is the right sibling
of this tree with respect to multiple parents.
:type: list(MultiParentedTree)
cSs,g|]$\}}|t|<01>dkr||d<00>qS)r')r,)r@r<>r-rrrrc<00>sz4MultiParentedTree.right_siblings.<locals>.<listcomp>)r<>)rrrr<00>right_siblings<67>s z MultiParentedTree.right_siblingscs<00>fdd<02><08>jD<00>S)Ncs.g|]&}t|<01>D]\}}|<03>kr||f<02>qqSr)rD)r@r<>r-r:)rrrrc<00>sz9MultiParentedTree._get_parent_indices.<locals>.<listcomp>)r<>)rr)rrr<><00>s
z%MultiParentedTree._get_parent_indicescCst|<00>i<00><01><02><00>S)z<>
The set of all roots of this tree. This set is formed by
tracing all possible parent paths until trees with no parents
are found.
:type: list(MultiParentedTree)
)r<00>_get_roots_helper<65>values)rrrr<00>roots<74>szMultiParentedTree.rootscCs2|jr"x&|jD]}|<02>|<01>qWn ||t|<00><|S)N)r<>r<><00>id)r<00>resultr<74>rrrr<><00>s
  z#MultiParentedTree._get_roots_helpercs(|<01>jkrgS<00>fdd<02>t|<01>D<00>SdS)aY
Return a list of the indices where this tree occurs as a child
of ``parent``. If this child does not occur as a child of
``parent``, then the empty list is returned. The following is
always true::
for parent_index in ptree.parent_indices(parent):
parent[parent_index] is ptree
csg|]\}}|<02>kr|<01>qSrr)r@r-r:)rrrrc<00>sz4MultiParentedTree.parent_indices.<locals>.<listcomp>N)r<>rD)rr<>r)rr<00>parent_indices<65>s
z MultiParentedTree.parent_indicescs(<00><01>krdgS<00><00>fdd<03><08>jD<00>SdS)a
Return a list of all tree positions that can be used to reach
this multi-parented tree starting from ``root``. I.e., the
following is always true::
for treepos in ptree.treepositions(root):
root[treepos] is ptree
rcs@g|]8}|<01><00><00>D](}t|<01>D]\}}|<04>kr||f<00>qqqSr)rErD)r@r<>rQr-r:)r<>rrrrc<00>sz3MultiParentedTree.treepositions.<locals>.<listcomp>N)r<>)rr<>r)r<>rrrE<00>s  zMultiParentedTree.treepositionscsvt|t<01>st<02><01>||kst<02>t<03>fdd<02>|jD<00><01>dks>t<02>x2t<05><00>D]\}}||krH||krHPqHW|j<04><06><00>dS)Ncsg|]}|<01>kr|<01>qSrr)r@rA)rrrrc<00>sz0MultiParentedTree._delparent.<locals>.<listcomp>r')rr<>ryr,r<>rDr<>)rr:r-rBr<>r)rrr<><00>s zMultiParentedTree._delparentFcCs@t|t<01>std<01><01>|s<x$|jD]}||krPqW|j<03>|<00>dS)Nz?Can not insert a non-MultiParentedTree into a MultiParentedTree)rr<>rr<>r9)rr:r-r<>r<>rrrr<><00>s
 zMultiParentedTree._setparent)N)F)rr<>r<>r<>rrkr<>r<>r<>r<>r<>r<>r<>rEr<>r<>r<>rr)rrr<>Us 
r<>c@s eZdZdS)r<>N)rr<>r<>rrrrr<>sr<>c@s eZdZdS)r<>N)rr<>r<>rrrrr<> sr<>c@sTeZdZddd<03>Zdd<05>Zdd<07>Zdd <09>Zdd d <0C>Zed d<0E><00>Z dd<10>Z
dd<12>Z dS)<15>ProbabilisticTreeNcKs t<00>|||<02>tj|f|<03>dS)N)rrr
)rrr<00> prob_kwargsrrrrszProbabilisticTree.__init__cCstS)N)<01>ImmutableProbabilisticTree)rrrrrkszProbabilisticTree._frozen_classcCsdt<00>|<00>|<00><02>fS)Nz %s (p=%r))rr <00>prob)rrrrr<>szProbabilisticTree.__repr__cCsd|jdd<03>|<00><01>fS)Nz %s (p=%.6g)<29><)r<>)r<>r<>)rrrrr<>"szProbabilisticTree.__str__FcCs.|st|<00>|j||<00><02>d<01>St|<00><01>|<00>SdS)N)r<>)rrr<>ra)rrgrrrre%szProbabilisticTree.copycsTt|t<01>rL<72>fdd<02>|D<00>}t|t<02>r:<3A>|j||<01><04>d<03>S<00>|j|dd<03>Sn|SdS)Ncsg|]}<01><00>|<01><01>qSr)ra)r@r:)rbrrrc.sz-ProbabilisticTree.convert.<locals>.<listcomp>)r<>g<00>?)rrr
rr<>)rb<00>valrr)rbrra+s 

zProbabilisticTree.convertcCs4|j|jko2|jt|<00>|<00><03>f|jt|<01>|<01><03>fkS)N)rrrr<>)rrrrrr6s
 zProbabilisticTree.__eq__cCs^t|t<01>std||<01>|j|jkrJ|jt|<00>|<00><06>f|jt|<01>|<01><06>fkS|jj|jjkSdS)N<><)rrrrrrr<>r)rrrrrr=s
   zProbabilisticTree.__lt__)N)F) rr<>r<>rrkr<>r<>rer<>rarrrrrrr<>s

 r<>c@sDeZdZddd<03>Zdd<05>Zdd<07>Zdd <09>Zdd d <0C>Zed d<0E><00>Z dS)r<>NcKs:t<00>|||<02>tj|f|<03>t|jt|<00>|<00><06>f<03>|_dS)N)rjrr
rlrr+r<>r<>)rrrr<>rrrrLsz#ImmutableProbabilisticTree.__init__cCstS)N)r<>)rrrrrkRsz(ImmutableProbabilisticTree._frozen_classcCsdt<00>|<00>|<00><02>fS)Nz%s [%s])rr r<>)rrrrr<>Usz#ImmutableProbabilisticTree.__repr__cCsd|jdd<03>|<00><01>fS)Nz%s [%s]r<>)r<>)r<>r<>)rrrrr<>Xsz"ImmutableProbabilisticTree.__str__FcCs.|st|<00>|j||<00><02>d<01>St|<00><01>|<00>SdS)N)r<>)rrr<>ra)rrgrrrre[szImmutableProbabilisticTree.copycsTt|t<01>rL<72>fdd<02>|D<00>}t|t<02>r:<3A>|j||<01><04>d<03>S<00>|j|dd<03>Sn|SdS)Ncsg|]}<01><00>|<01><01>qSr)ra)r@r:)rbrrrcdsz6ImmutableProbabilisticTree.convert.<locals>.<listcomp>)r<>g<00>?)rrr
rr<>)rbr<>rr)rbrraas 

z"ImmutableProbabilisticTree.convert)N)F)
rr<>r<>rrkr<>r<>rer<>rarrrrr<>Js 

r<>cCs<g}x2|D]*}t|t<01>r*|<01>t|j<04><01>q
|<01>|<02>q
W|S)N)rrr9r r)rd<00>namesr:rrrrJms 

rJcCs td<01><01>dS)zE
Use Tree.read(s, remove_empty_top_bracketing=True) instead.
z;Use Tree.read(s, remove_empty_top_bracketing=True) instead.N)<01> NameError)rzrrr<00> bracket_parse|srcCs<>t<00>d|<00>}x<>tt|<01><01>D]<5D>}||dkrN||||d||d<||<qd||kr<>||<00>d<04>}t|<03>dkr<>|d||<q<>d|dd|dd ||<q||d
krd ||<qWd<07>|<01>}tj|d d <0A>S)a<>
Parse a Sinica Treebank string and return a tree. Trees are represented as nested brackettings,
as shown in the following example (X represents a Chinese character):
S(goal:NP(Head:Nep:XX)|theme:NP(Head:Nhaa:X)|quantity:Dab:X|Head:VL2:X)#0(PERIODCATEGORY)
:return: A tree corresponding to the string representation.
:rtype: Tree
:param s: The string to be converted
:type s: str
z([()| ])<29>(r'<00>:ro<00><><EFBFBD><EFBFBD><EFBFBD>r<EFBFBD>rM<00>)rXrpT)r{)rqr<>rOr,r<>rr~)rz<00>tokensrB<00>fieldsZtreebank_stringrrr<00> sinica_parse<73>s    "  
rcCs<>ddlm}m}d}|<00>|<02>}td<04>t|<03>t|<03><05><00>td<05>t|<03><06><00>t|d<00>t|d<00>t|<03><07><00>t|<03><08><00>t|d<00>t|d<00>t|d<00>|d}|<04> d|<00>d <09><01>td
<EFBFBD>t|<03>|<00>d <0B>|d <t|<03>t<04>td <0A>|<03>
<EFBFBD>t|<03>td<0E>|<03> <0B>t|<03>t<04>|dddgdd<13>}td<14>t|<05>t<04>|<00>|<03> <0C><00>}td<15>t|<03>t<04>td<16>t|<03> <0A><00>t<04>td<17>t|<03><0E><00>t<04>|<03>d<18>t|<03>dS)z<>
A demonstration showing how Trees and Trees can be
used. This demonstration creates a Tree, and loads a
Tree from the Treebank corpus,
and shows the results of calling several of their methods.
r)rr<>zA(S (NP (DT the) (NN cat)) (VP (VBD ate) (NP (DT a) (NN cookie))))z#Convert bracketed string into tree:zDisplay tree properties:r')r'r')r'r'rz(JJ big)zTree modification:z (NN cake))r'r'r'zCollapse unary:zChomsky normal form:r<>r<><00>zg<00>?)r<>zProbabilistic Tree:z0Convert tree to bracketed string and back again:z LaTeX output:zProduction output:)<02>test<73>N)Znltkrr<>r~r<>r<>r5r=r8r<>r`rZr<>r<>rKr6)rr<>rz<00>tZthe_cat<61>ptrrr<00>demo<6D>sZ
           
r r
)'r<><00>
__future__rrrqr<><00>abcrr<00>sixrrZ nltk.grammarrr Znltk.probabilityr
Z nltk.utilr Z nltk.compatr r r<>rrrrjr<>r<>r<>r<>r<>r<>r<>rJrrr <00>__all__rrrr<00><module>s^   @uz4 
4 
")I