d?Z;e<d@kre;ndS(Au Data classes and parser implementations for "chart parsers", which use dynamic programming to efficiently parse a text. A chart parser derives parse trees for a text by iteratively adding "edges" to a "chart." Each edge represents a hypothesis about the tree structure for a subsequence of the text. The chart is a "blackboard" for composing and combining these hypotheses. When a chart parser begins parsing a text, it creates a new (empty) chart, spanning the text. It then incrementally adds new edges to the chart. A set of "chart rules" specifies the conditions under which new edges should be added to the chart. Once the chart reaches a stage where none of the chart rules adds any new edges, parsing is complete. Charts are encoded with the ``Chart`` class, and edges are encoded with the ``TreeEdge`` and ``LeafEdge`` classes. The chart parser module defines three chart parsers: - ``ChartParser`` is a simple and flexible chart parser. Given a set of chart rules, it will apply those rules to the chart until no more edges are added. - ``SteppingChartParser`` is a subclass of ``ChartParser`` that can be used to step through the parsing process. i(tprint_functiontdivisiontunicode_literalsN(tcompat(tTree(tPCFGtis_nonterminalt is_terminal(t OrderedDict(traise_unorderable_types(ttotal_orderingtpython_2_unicode_compatiblet unicode_repr(tParserItEdgeIcB seZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZRS(u A hypothesis about the structure of part of a sentence. Each edge records the fact that a structure is (partially) consistent with the sentence. An edge contains: - A span, indicating what part of the sentence is consistent with the hypothesized structure. - A left-hand side, specifying what kind of structure is hypothesized. - A right-hand side, specifying the contents of the hypothesized structure. - A dot position, indicating how much of the hypothesized structure is consistent with the sentence. Every edge is either complete or incomplete: - An edge is complete if its structure is fully consistent with the sentence. - An edge is incomplete if its structure is partially consistent with the sentence. For every incomplete edge, the span specifies a possible prefix for the edge's structure. There are two kinds of edge: - A ``TreeEdge`` records which trees have been found to be (partially) consistent with the text. - A ``LeafEdge`` records the tokens occurring in the text. The ``EdgeI`` interface provides a common interface to both types of edge, allowing chart parsers to treat them in a uniform manner. cC s"|jtkrtdndS(NuEdge is an abstract interface(t __class__Rt TypeError(tself((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__init__\scC s tdS(u Return a tuple ``(s, e)``, where ``tokens[s:e]`` is the portion of the sentence that is consistent with this edge's structure. :rtype: tuple(int, int) N(tNotImplementedError(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytspandscC s tdS(uR Return the start index of this edge's span. :rtype: int N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytstartnscC s tdS(uP Return the end index of this edge's span. :rtype: int N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytendvscC s tdS(uM Return the length of this edge's span. :rtype: int N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytlength~scC s tdS(u Return this edge's left-hand side, which specifies what kind of structure is hypothesized by this edge. :see: ``TreeEdge`` and ``LeafEdge`` for a description of the left-hand side values for each edge type. N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytlhsscC s tdS(u Return this edge's right-hand side, which specifies the content of the structure hypothesized by this edge. :see: ``TreeEdge`` and ``LeafEdge`` for a description of the right-hand side values for each edge type. N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytrhsscC s tdS(u Return this edge's dot position, which indicates how much of the hypothesized structure is consistent with the sentence. In particular, ``self.rhs[:dot]`` is consistent with ``tokens[self.start():self.end()]``. :rtype: int N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytdots cC s tdS(u Return the element of this edge's right-hand side that immediately follows its dot. :rtype: Nonterminal or terminal or None N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytnextsymscC s tdS(uw Return True if this edge's structure is fully consistent with the text. :rtype: bool N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt is_completescC s tdS(u{ Return True if this edge's structure is partially consistent with the text. :rtype: bool N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt is_incompletescC s"|j|jko!|j|jkS(N(Rt_comparison_key(Rtother((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__eq__scC s ||k S(N((RR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__ne__scC s^t|ts"td||n|j|jkrD|j|jkS|jj|jjkSdS(Nu<(t isinstanceRR RRt__name__(RR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__lt__s cC s9y |jSWn'tk r4t|j|_|jSXdS(N(t_hashtAttributeErrorthashR(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__hash__s   (R#t __module__t__doc__RRRRRRRRRRRR R!R$R((((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR;s         tTreeEdgecB seZdZddZedZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZRS(u An edge that records the fact that a tree is (partially) consistent with the sentence. A tree edge consists of: - A span, indicating what part of the sentence is consistent with the hypothesized tree. - A left-hand side, specifying the hypothesized tree's node value. - A right-hand side, specifying the hypothesized tree's children. Each element of the right-hand side is either a terminal, specifying a token with that terminal as its leaf value; or a nonterminal, specifying a subtree with that nonterminal's symbol as its node value. - A dot position, indicating which children are consistent with part of the sentence. In particular, if ``dot`` is the dot position, ``rhs`` is the right-hand size, ``(start,end)`` is the span, and ``sentence`` is the list of tokens in the sentence, then ``tokens[start:end]`` can be spanned by the children specified by ``rhs[:dot]``. For more information about edges, see the ``EdgeI`` interface. icC sI||_||_t|}||_||_||||f|_dS(u Construct a new ``TreeEdge``. :type span: tuple(int, int) :param span: A tuple ``(s, e)``, where ``tokens[s:e]`` is the portion of the sentence that is consistent with the new edge's structure. :type lhs: Nonterminal :param lhs: The new edge's left-hand side, specifying the hypothesized tree's node value. :type rhs: list(Nonterminal and str) :param rhs: The new edge's right-hand side, specifying the hypothesized tree's children. :type dot: int :param dot: The position of the new edge's dot. This position specifies what prefix of the production's right hand side is consistent with the text. In particular, if ``sentence`` is the list of tokens in the sentence, then ``okens[span[0]:span[1]]`` can be spanned by the children specified by ``rhs[:dot]``. N(t_spant_lhsttuplet_rhst_dotR(RRRRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs      c C s1td||fd|jd|jddS(u Return a new ``TreeEdge`` formed from the given production. The new edge's left-hand side and right-hand side will be taken from ``production``; its span will be ``(index,index)``; and its dot position will be ``0``. :rtype: TreeEdge RRRRi(R+RR(t productiontindex((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytfrom_productions c C s9td|jd|fd|jd|jd|jdS(u Return a new ``TreeEdge`` formed from this edge. The new edge's dot position is increased by ``1``, and its end index will be replaced by ``new_end``. :param new_end: The new end index. :type new_end: int :rtype: TreeEdge RiRRRi(R+R,R-R/R0(Rtnew_end((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytmove_dot_forward%s cC s|jS(N(R-(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR4scC s|jS(N(R,(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR5scC s |jdS(Ni(R,(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR6scC s |jdS(Ni(R,(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR7scC s|jd|jdS(Nii(R,(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR8scC s|jS(N(R/(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR9scC s|jS(N(R0(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR:scC s|jt|jkS(N(R0tlenR/(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR;scC s|jt|jkS(N(R0R6R/(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR<scC s.|jt|jkrdS|j|jSdS(N(R0R6R/tNone(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR=scC sd|jd|jdf}|d|jf7}xTtt|jD]=}||jkrj|d7}n|dt|j|7}qHWt|j|jkr|d7}n|S(Nu[%s:%s] iiu%-2r ->u *u %s(R,R-trangeR6R/R0R (Rtstrti((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__str__Bs  cC sd|S(Nu [Edge: %s]((R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt__repr__Ls(R#R)R*Rt staticmethodR3R5RRRRRRRRRRR;R<(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR+s              tLeafEdgecB seZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZRS(u An edge that records the fact that a leaf value is consistent with a word in the sentence. A leaf edge consists of: - An index, indicating the position of the word. - A leaf, specifying the word's content. A leaf edge's left-hand side is its leaf value, and its right hand side is ``()``. Its span is ``[index, index+1]``, and its dot position is ``0``. cC s%||_||_||f|_dS(u Construct a new ``LeafEdge``. :param leaf: The new edge's leaf value, specifying the word that is recorded by this edge. :param index: The new edge's index, specifying the position of the word that is recorded by this edge. N(t_leaft_indexR(RtleafR2((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR]s  cC s|jS(N(R?(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRkscC s|j|jdfS(Ni(R@(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRlscC s|jS(N(R@(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRmscC s |jdS(Ni(R@(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRnscC sdS(Ni((R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRoscC sdS(N(((R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRpscC sdS(Ni((R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRqscC stS(N(tTrue(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRrscC stS(N(tFalse(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRsscC sdS(N(R7(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRtscC s$d|j|jdt|jfS(Nu [%s:%s] %si(R@R R?(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR;wscC sd|S(Nu [Edge: %s]((R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR<ys(R#R)R*RRRRRRRRRRRR;R<(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR>Ps             tChartcB seZdZdZdZdZdZdZdZdZ e Z dZ d Z d Z d Zd Zd ZdZedZeedZdZdZddZddZddZdZRS(u A blackboard for hypotheses about the syntactic constituents of a sentence. A chart contains a set of edges, and each edge encodes a single hypothesis about the structure of some portion of the sentence. The ``select`` method can be used to select a specific collection of edges. For example ``chart.select(is_complete=True, start=0)`` yields all complete edges whose start indices are 0. To ensure the efficiency of these selection operations, ``Chart`` dynamically creates and maintains an index for each set of attributes that have been selected on. In order to reconstruct the trees that are represented by an edge, the chart associates each edge with a set of child pointer lists. A child pointer list is a list of the edges that license an edge's right-hand side. :ivar _tokens: The sentence that the chart covers. :ivar _num_leaves: The number of tokens. :ivar _edges: A list of the edges in the chart :ivar _edge_to_cpls: A dictionary mapping each edge to a set of child pointer lists that are associated with that edge. :ivar _indexes: A dictionary mapping tuples of edge attributes to indices, where each index maps the corresponding edge attribute values to lists of edges. cC s/t||_t|j|_|jdS(u Construct a new chart. The chart is initialized with the leaf edges corresponding to the terminal leaves. :type tokens: list :param tokens: The sentence that this chart will be used to parse. N(R.t_tokensR6t _num_leavest initialize(Rttokens((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs cC sg|_i|_i|_dS(u" Clear the chart. N(t_edgest _edge_to_cplst_indexes(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRGs  cC s|jS(u[ Return the number of words in this chart's sentence. :rtype: int (RF(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt num_leavesscC s |j|S(u\ Return the leaf value of the word at the given index. :rtype: str (RE(RR2((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRAscC s|jS(u{ Return a list of the leaf values of each word in the chart's sentence. :rtype: list(str) (RE(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytleavesscC s|jS(u Return a list of all edges in this chart. New edges that are added to the chart after the call to edges() will *not* be contained in this list. :rtype: list(EdgeI) :see: ``iteredges``, ``select`` (RI(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytedgess cC s t|jS(u Return an iterator over the edges in this chart. It is not guaranteed that new edges which are added to the chart before the iterator is exhausted will also be generated. :rtype: iter(EdgeI) :see: ``edges``, ``select`` (titerRI(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt iteredgess cC s t|jS(uZ Return the number of edges contained in this chart. :rtype: int (R6RJ(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt num_edgessc sikrt|jStj}t|}||jkrV|j|ntfd|D}t|j|j|gS(u` Return an iterator over the edges in this chart. Any new edges that are added to the chart before the iterator is exahusted will also be generated. ``restrictions`` can be used to restrict the set of edges that will be generated. :param span: Only generate edges ``e`` where ``e.span()==span`` :param start: Only generate edges ``e`` where ``e.start()==start`` :param end: Only generate edges ``e`` where ``e.end()==end`` :param length: Only generate edges ``e`` where ``e.length()==length`` :param lhs: Only generate edges ``e`` where ``e.lhs()==lhs`` :param rhs: Only generate edges ``e`` where ``e.rhs()==rhs`` :param nextsym: Only generate edges ``e`` where ``e.nextsym()==nextsym`` :param dot: Only generate edges ``e`` where ``e.dot()==dot`` :param is_complete: Only generate edges ``e`` where ``e.is_complete()==is_complete`` :param is_incomplete: Only generate edges ``e`` where ``e.is_incomplete()==is_incomplete`` :rtype: iter(EdgeI) c3 s|]}|VqdS(N((t.0tkey(t restrictions(sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pys s(RORItsortedtkeysR.RKt _add_indextget(RRTt restr_keystvals((RTsb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytselects  c sx0|D](}tt|std|qqWi}|j|/sN(thasattrRt ValueErrorRKRIR.t setdefaulttappend(RRYRSR2RZ((R]sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRW s c sYxR|jjD]A\}}tfd|D}|j|gjqWdS(us A helper function for ``insert``, which registers the new edge with all existing indexes. c3 s!|]}t|VqdS(N(R\(RRRS(R](sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pys 8sN(RKtitemsR.R`Ra(RR]RYR2RZ((R]sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt_register_with_indexes2scC s?|j|}g|D]}||f^q}|j||S(uT Add a new edge to the chart, using a pointer to the previous edge. (tchild_pointer_liststinsert(Rtnew_edget previous_edget child_edgetcplstcpltnew_cpls((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytinsert_with_backpointer?s cG s||jkr,|j||j|n|jj|t}t}x9|D]1}t|}||krQt||RERRtsymbolRdRwt itertoolstproductRaRRtextend(RR]RqRvRpRARrRRjtcpt child_choicestchildrenteltt unexpandedRt((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRws.   ( /  cC s|jj|ijS(u Return the set of child pointer lists for the given edge. Each child pointer list is a list of edges that have been used to form this edge. :rtype: list(list(EdgeI)) (RJRXRV(RR]((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRds cC sx|dkr#d|jd}n|j|j}}ddd|d|}||kr|jr{|d7}qK|d7}n|jr|jd|jfkr|d d |||dd |dd 7}nk|jr|d d |||dd |dd 7}n.|d d |||dd |dd7}|d|dd|j|7}|d |S(u Return a pretty-printed string representation of a given edge in this chart. :rtype: str :param width: The number of characters allotted to each index in the sentence. i2iu|u.u u#u>iu[u=u]u-u| %sN(R7RLRRRRRF(RR]twidthRRR9((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytpretty_format_edges    '1 1.!cC s|dkr#d|jd}n|jdk r|dkrd}x4|jD])}|||d j|dd7}qNW|d7}nd}|S(u Return a pretty-printed string representation of this chart's leaves. This string can be used as a header for calls to ``pretty_format_edge``. i2iu|.u.u|uN(R7RLREtcenter(RRtheaderttok((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytpretty_format_leavess ' c sdkr#djdntgD]!}|j|j|f^q-}g|D]\}}}|^q^}jddjfd|DS(u Return a pretty-printed string representation of this chart. :param width: The number of characters allotted to each index in the sentence. :rtype: str i2iu c3 s!|]}j|VqdS(N(R(RRR](RR(sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pys sN(R7RLRURRRtjoin(RRteRNt_((RRsb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt pretty_formats  4"c C sd}|d7}|d7}|d7}xt|jddD]}|dkr\|d7}nx{t|jdD]c}|dks||j|djks||j|djkrs|d ||f7}qsqsWq=W|d 7}xt|jdD]}|d 7}x{t|jdD]c}|dksr||j|djksr||j|djkr&|d ||f7}q&q&W|d 7}qW|d7}|d7}|d7}x;t|jD]'}|d|j||df7}qW|d7}|d7}xt|D]\}}x@t|jD],}|d||d|d|df7}q7W|d|j|d|j|d|f7}xIt|j|jD],}|d||d|d|df7}qWqW|d 7}|S(Nudigraph nltk_chart { u rankdir=LR; u node [height=0.1,width=0.1]; u* node [style=filled, color="lightgray"]; iiu& node [style=filled, color="black"]; iu %04d.%04d [label=""]; u/ x [style=invis]; x->0000.0000 [style=invis]; u {rank=same;u %04d.%04du} u" edge [style=invis, weight=100]; u node [shape=plaintext] u 0000.0000u->%s->%04d.0000u; u edge [style=solid, weight=1]; u* %04d.%04d -> %04d.%04d [style="invis"]; u' %04d.%04d -> %04d.%04d [label="%s"]; (R8RQRLRIRRRAt enumerate(RtstytxR]((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt dot_digraphsJ     )  )   %  $+"( N(R#R)R*RRGRLRARMRNRPt__iter__RQR[RWRcRlReRmRRuRCRrRwRdR7RRRR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRDs0       %   !   8    t ChartRuleIcB s eZdZdZdZRS(u A rule that specifies what new edges are licensed by any given set of existing edges. Each chart rule expects a fixed number of edges, as indicated by the class variable ``NUM_EDGES``. In particular: - A chart rule with ``NUM_EDGES=0`` specifies what new edges are licensed, regardless of existing edges. - A chart rule with ``NUM_EDGES=1`` specifies what new edges are licensed by a single existing edge. - A chart rule with ``NUM_EDGES=2`` specifies what new edges are licensed by a pair of existing edges. :type NUM_EDGES: int :cvar NUM_EDGES: The number of existing edges that this rule uses to license new edges. Typically, this number ranges from zero to two. cG s tdS(u Return a generator that will add edges licensed by this rule and the given edges to the chart, one at a time. Each time the generator is resumed, it will either add a new edge and yield that edge; or return. :type edges: list(EdgeI) :param edges: A set of existing edges. The number of edges that should be passed to ``apply()`` is specified by the ``NUM_EDGES`` class variable. :rtype: iter(EdgeI) N(R(RtcharttgrammarRN((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytapply_s cC s tdS(u+ Return a generator that will add all edges licensed by this rule, given the edges that are currently in the chart, one at a time. Each time the generator is resumed, it will either add a new edge and yield that edge; or return. :rtype: iter(EdgeI) N(R(RRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytapply_everywherens (R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRLs tAbstractChartRulecB s)eZdZdZdZdZRS(uo An abstract base class for chart rules. ``AbstractChartRule`` provides: - A default implementation for ``apply``. - A default implementation for ``apply_everywhere``, (Currently, this implementation assumes that ``NUM_EDGES``<=3.) - A default implementation for ``__str__``, which returns a name based on the rule's class name. cG s tdS(N(R(RRRRN((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRsc c sX|jdkr4xB|j||D] }|Vq"Wn |jdkr|x|D]+}x"|j|||D] }|VqfWqJWn|jdkrx|D]?}x6|D].}x%|j||||D] }|VqWqWqWn||jdkrHxj|D]S}xJ|D]B}x9|D]1}x(|j|||||D] }|Vq*WqWqWqWn tddS(Niiiiu&NUM_EDGES>3 is not currently supported(t NUM_EDGESRtAssertionError(RRRRfte1te2te3((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs&       "cC stjdd|jjS(Nu([a-z])([A-Z])u\1 \2(tretsubRR#(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR;s(R#R)R*RRR;(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRzs   tFundamentalRulecB seZdZdZdZRS(u A rule that joins two adjacent edges to form a single combined edge. In particular, this rule specifies that any pair of edges - ``[A -> alpha \* B beta][i:j]`` - ``[B -> gamma \*][j:k]`` licenses the edge: - ``[A -> alpha B * beta][i:j]`` icc s|joE|joE|j|jkoE|j|jksLdS|j|j}|j|||r~|VndS(N(RRRRRRR5Rl(RRRt left_edget right_edgeRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs  (R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs tSingleEdgeFundamentalRulecB s/eZdZdZdZdZdZRS(u A rule that joins a given edge with adjacent edges in the chart, to form combined edges. In particular, this rule specifies that either of the edges: - ``[A -> alpha \* B beta][i:j]`` - ``[B -> gamma \*][j:k]`` licenses the edge: - ``[A -> alpha B * beta][i:j]`` if the other edge is already in the chart. :note: This is basically ``FundamentalRule``, with one edge left unspecified. icc s]|jr4xJ|j|||D] }|Vq"Wn%x"|j|||D] }|VqJWdS(N(Rt_apply_incompletet_apply_complete(RRRR]Rf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs   cc skxd|jd|jdtd|jD]8}|j|j}|j|||r+|Vq+q+WdS(NRRR(R[RRCRR5RRl(RRRRRRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs cc skxd|jd|jdtd|jD]8}|j|j}|j|||r+|Vq+q+WdS(NRRR(R[RRBRR5Rl(RRRRRRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs (R#R)R*RRRR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs   t LeafInitRulecB seZdZdZRS(icc sSxLt|jD]8}t|j||}|j|dr|VqqWdS(N((R8RLR>RARe(RRRR2Rf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs(R#R)RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRstTopDownInitRulecB seZdZdZdZRS(u A rule licensing edges corresponding to the grammar productions for the grammar's start symbol. In particular, this rule specifies that ``[S -> \* alpha][0:i]`` is licensed for each grammar production ``S -> alpha``, where ``S`` is the grammar's start symbol. icc sSxL|jd|jD]2}tj|d}|j|dr|VqqWdS(NRi((t productionsRR+R3Re(RRRtprodRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs(R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRstTopDownPredictRulecB seZdZdZdZRS(u| A rule licensing edges corresponding to the grammar productions for the nonterminal following an incomplete edge's dot. In particular, this rule specifies that ``[A -> alpha \* B beta][i:j]`` licenses the edge ``[B -> \* gamma][j:j]`` for each grammar production ``B -> gamma``. :note: This rule corresponds to the Predictor Rule in Earley parsing. icc si|jrdSxR|jd|jD]8}tj||j}|j|dr)|Vq)q)WdS(NR((RRRR+R3RRe(RRRR]RRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR!s  (R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs tCachedTopDownPredictRulecB s eZdZdZdZRS(u1 A cached version of ``TopDownPredictRule``. After the first time this rule is applied to an edge with a given ``end`` and ``next``, it will not generate any more edges for edges with that ``end`` and ``next``. If ``chart`` or ``grammar`` are changed, then the cache is flushed. cC stj|i|_dS(N(RRt_done(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR1s c c s9|jrdS|j|j}}t|s9dS|jj||fd}|d|krx|d|krxdSx|jd|D]}|jr|jd}t |r||j ks||j |krqqqnt j ||} |j| dr| VqqW||f|j||f alpha \*]`` licenses the edge ``[B -> \* A beta]`` for each grammar production ``B -> A beta``. icc si|jrdSxR|jd|jD]8}tj||j}|j|dr)|Vq)q)WdS(NR((RRRR+R3RRe(RRRR]RRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR\s  (R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRTstBottomUpPredictCombineRulecB seZdZdZdZRS(u A rule licensing any edge corresponding to a production whose right-hand side begins with a complete edge's left-hand side. In particular, this rule specifies that ``[A -> alpha \*]`` licenses the edge ``[B -> A \* beta]`` for each grammar production ``B -> A beta``. :note: This is like ``BottomUpPredictRule``, but it also applies the ``FundamentalRule`` to the resulting edge. icc s{|jrdSxd|jd|jD]J}t|j|j|jd}|j||fr)|Vq)q)WdS(NRi(RRRR+RRRe(RRRR]RRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRos  '(R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRcs tEmptyPredictRulecB seZdZdZdZRS(ui A rule that inserts all empty productions as passive edges, in every position in the chart. icc sqxj|jdtD]V}xMtj|jdD]2}tj||}|j|dr3|Vq3q3WqWdS(Ntemptyi((RRBRtxrangeRLR+R3Re(RRRRR2Rf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR|s  (R#R)R*RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRvst!FilteredSingleEdgeFundamentalRulecB seZdZdZRS(cc s|j}||jko*|j|}x|jd|jdtd|jD]\}t|||j|j rX|j |j}|j |||r|VqqXqXWdS(NRRR( RRLRAR[RRCRt_bottomup_filterRRR5Rl(RRRRRt nexttokenRRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs !!cc sx|jd|jdtd|jD]}|j}||jko[|j|}t|||j|jr+|j |j}|j |||r|Vqq+q+WdS(NRRR( R[RRBRRLRARRRR5Rl(RRRRRRRRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs !!(R#R)RR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs t"FilteredBottomUpPredictCombineRulecB seZdZRS(cc s|jrdS|j}||jko:|j|}x|jd|jD]e}t|||jrVt|j |j|jd}|j ||fr|VqqVqVWdS(NRi( RRRLRARRRRR+RRe(RRRR]RRRRf((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs  !'(R#R)R(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRsicC sRt||dkrtS||d}t|r>||kS|j||SdS(Ni(R6RBRt is_leftcorner(RRRRt_next((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs   t ChartParsercB sPeZdZeddeedZdZdZddZ e dZ RS( u A generic chart parser. A "strategy", or list of ``ChartRuleI`` instances, is used to decide what edges to add to the chart. In particular, ``ChartParser`` uses the following algorithm to parse texts: | Until no new edges are added: | For each *rule* in *strategy*: | Apply *rule* to any applicable edges in the chart. | Return any complete parses in the chart ii2cC s||_||_||_||_||_||_g|_g|_x[|D]S}|jdkrw|jj |qO|jdkr|jj |qOt |_qOWdS(u Create a new chart parser, that uses ``grammar`` to parse texts. :type grammar: CFG :param grammar: The grammar used to parse texts. :type strategy: list(ChartRuleI) :param strategy: A list of rules that should be used to decide what edges to add to the chart (top-down strategy by default). :type trace: int :param trace: The level of tracing that should be used when parsing a text. ``0`` will generate no tracing output; and higher numbers will produce more verbose tracing output. :type trace_chart_width: int :param trace_chart_width: The default total width reserved for the chart in trace output. The remainder of each line will be used to display edges. :type use_agenda: bool :param use_agenda: Use an optimized agenda-based algorithm, if possible. :param chart_class: The class that should be used to create the parse charts. iiN( t_grammart _strategyt_tracet_trace_chart_widtht _use_agendat _chart_classt_axiomst_inference_rulesRRaRC(RRtstrategyttracettrace_chart_widtht use_agendat chart_classtrule((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs         cC s|jS(N(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRscC s^|s dS|dk}xA|D]9}|r@td|t}nt|j||qWdS(Niu%s:(tprintRCR(RRRt new_edgesRt edge_widthtprint_rule_headerR]((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt_trace_new_edgess   cC s|dkr|j}n|j}t|}|jj||j|}|j}|j|jd}|rt |j |n|j rcx?|j D]4}t|j ||}||||||qW|j} |j} | jx| r_| j} xR| D]J} t| j ||| }|rN||| |||n| |7} qWqWngt} x^| rt} xK|jD]@} t| j||}t|} ||| |||qWqlW|S(u Return the final parse ``Chart`` from which all possible parse trees can be extracted. :param tokens: The sentence to be parsed :type tokens: list(str) :rtype: Chart iN(R7RRtlistRtcheck_coverageRRRLRRRRRRRNtreversetpopRBRCRRR6(RRHRttrace_new_edgesRRttrace_edge_widthtaxiomRtinference_rulestagendaR]Rt edges_added((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt chart_parses@             cC s1|j|}t|j|jjd|S(NRp(RRORuRR(RRHRpR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytparseEsN( R#R)R*tBU_LC_STRATEGYRBRDRRRR7RRR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs ,  5tTopDownChartParsercB seZdZdZRS(ul A ``ChartParser`` using a top-down parsing strategy. See ``ChartParser`` for more information. cK stj||t|dS(N(RRt TD_STRATEGY(RRt parser_args((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRNs(R#R)R*R(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRIstBottomUpChartParsercB seZdZdZRS(um A ``ChartParser`` using a bottom-up parsing strategy. See ``ChartParser`` for more information. cK s?t|tr%tjddtntj||t|dS(NuTBottomUpChartParser only works for CFG, use BottomUpProbabilisticChartParser insteadtcategory(R"RtwarningstwarntDeprecationWarningRRt BU_STRATEGY(RRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRVs  (R#R)R*R(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRQstBottomUpLeftCornerChartParsercB seZdZdZRS(u A ``ChartParser`` using a bottom-up left-corner parsing strategy. This strategy is often more efficient than standard bottom-up. See ``ChartParser`` for more information. cK stj||t|dS(N(RRR(RRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRcs(R#R)R*R(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyR]stLeftCornerChartParsercB seZdZRS(cK s5|jstdntj||t|dS(NuCLeftCornerParser only works for grammars without empty productions.(t is_nonemptyR_RRt LC_STRATEGY(RRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRgs (R#R)R(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRfstSteppingChartParsercB seZdZgddZdZdZdZdZdZdZ d Z e d Z d Z d Zd Ze dZRS(u A ``ChartParser`` that allows you to step through the parsing process, adding a single edge at a time. It also allows you to change the parser's strategy or grammar midway through parsing a text. The ``initialize`` method is used to start parsing a text. ``step`` adds a single edge to the chart. ``set_strategy`` changes the strategy used by the chart parser. ``parses`` returns the set of parses that has been found by the chart parser. :ivar _restart: Records whether the parser's strategy, grammar, or chart has been changed. If so, then ``step`` must restart the parsing algorithm. icC s5d|_d|_t|_tj||||dS(N(R7t_chartt_current_chartruleRCt_restartRR(RRRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs   cC s"tt||_t|_dS(uBegin parsing the given tokens.N(RDRRRBR(RRH((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRGscc s|jdkrtdnxtrt|_d|jjd}xu|jD]b}|jdkryt |j n|jdkrt |jj ||n|V|jrTPqTqTWdVq!WdS(u Return a generator that adds edges to the chart, one at a time. Each time the generator is resumed, it adds a single edge and yields that edge. If no more edges can be added, then it yields None. If the parser's strategy, grammar, or chart is changed, then the generator will continue adding edges using the new strategy, grammar, or chart. Note that this generator never terminates, since the grammar or strategy might be changed to values that would add new edges. Instead, it yields None when no more edges can be added with the current strategy and grammar. u Parser must be initialized firsti2iiN( RR7R_RBRCRRLt_parseRRRR(RtwR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytsteps   cc s~|j}|j}d}x_|dkryd}xF|jD];}||_x)|j||D]}|d7}|VqYWq7WqWdS(u A generator that implements the actual parsing algorithm. ``step`` iterates through this generator, and restarts it whenever the parser's strategy, grammar, or chart is modified. iiN(RRRRR(RRRRRR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs    cC s|jS(u(Return the strategy used by this parser.(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRscC s|jS(u'Return the grammar used by this parser.(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRscC s|jS(u-Return the chart that is used by this parser.(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRscC s|jS(u<Return the chart rule used to generate the most recent edge.(R(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytcurrent_chartrulescC s|jj|jj|S(u8Return the parse trees currently contained in the chart.(RRuRR(RRp((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRuscC s*||jkrdS||_t|_dS(u  Change the strategy that the parser uses to decide which edges to add to the chart. :type strategy: list(ChartRuleI) :param strategy: A list of rules that should be used to decide what edges to add to the chart. N(RRBR(RR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt set_strategys  cC s)||jkrdS||_t|_dS(u&Change the grammar used by the parser.N(RRBR(RR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt set_grammars cC s)||jkrdS||_t|_dS(u)Load a given chart into the chart parser.N(RRBR(RR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt set_charts cC s`t|}|jj||j|x$|jD]}|dkr6Pq6q6W|jd|S(NRp(RRRRGRR7Ru(RRHRpR((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRs   (R#R)R*RRGRRRRRRRRuRRRR(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyRqs         cC sddlm}|jdS(Ni(tCFGu S -> NP VP PP -> "with" NP NP -> NP PP VP -> VP PP VP -> Verb NP VP -> Verb NP -> Det Noun NP -> "John" NP -> "I" Det -> "the" Det -> "my" Det -> "a" Noun -> "dog" Noun -> "cookie" Verb -> "ate" Verb -> "saw" Prep -> "with" Prep -> "under" (t nltk.grammarRt fromstring(R((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt demo_grammarsiu$I saw John with a dog with my cookieicC sddl}ddl}ddlm} m} m} t} |rZtdt| ntdt||j} t| t|dkrtdtdtdtd td td td d d|j j j }tnt |}|dkr(tddSi}idtfd6dtfd6dtfd6dtfd6}g}||kr|g}n|dkrd}nx|D]}td||dtt| ||dd|}|j}|j| }t|j| j}|j||||dsu%us parser: %6.3fsecRScS s|dS(Ni((ta((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyts(%tsysttimetnltkRRRRRtsplitR7tstdintreadlinetstripR9RRRRRRRRuRR6RNRRRGR8RRRRtmaxtreprRbRU(tchoicet print_timest print_grammart print_treesRtsentt numparsesRRRRRRRHttimest strategiestchoicesRR|ttRRuRtR:tjRtmaxlentformatt times_itemstparser((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pytdemo%s                        !           -    "u__main__(=R*t __future__RRRRyRRRRt nltk.treeRRRRRt nltk.utilRtnltk.internalsR t nltk.compatR R R tnltk.parse.apiR tobjectRR+R>RDRRRRRRRRRRRRRRRRRRRRRRRRRR7RBRCRR#(((sb/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/chart.pyt%s|   l/.50 ,     ~    h