+
    ÖÇÜhï   ã                   óŠ   € R t ^ RIHt ^ RIHtHtHt ^ RIHtH	t	 ^ RI
HtHt ^ RIHt RR ltR tR	 t ! R
 R4      tRR ltR# )z 
Utility functions for parsers.
)Úload)ÚCFGÚPCFGÚFeatureGrammar)ÚChartÚChartParser)ÚFeatureChartÚFeatureChartParser)ÚInsideChartParserNc                óT  € \        V 3/ VB p\        V\        4      '       g   \        R4      h\        V\        4      '       d   Vf   \
        pV! WaVR7      # \        V\        4      '       d   Vf   \        pVf   \        pV! WaVR7      # Vf   \        pVf   \        pV! WaVR7      # )a6  
Load a grammar from a file, and build a parser based on that grammar.
The parser depends on the grammar format, and might also depend
on properties of the grammar itself.

The following grammar formats are currently supported:
  - ``'cfg'``  (CFGs: ``CFG``)
  - ``'pcfg'`` (probabilistic CFGs: ``PCFG``)
  - ``'fcfg'`` (feature-based CFGs: ``FeatureGrammar``)

:type grammar_url: str
:param grammar_url: A URL specifying where the grammar is located.
    The default protocol is ``"nltk:"``, which searches for the file
    in the the NLTK data package.
: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.
:param parser: The class used for parsing; should be ``ChartParser``
    or a subclass.
    If None, the class depends on the grammar format.
:param chart_class: The class used for storing the chart;
    should be ``Chart`` or a subclass.
    Only used for CFGs and feature CFGs.
    If None, the chart class depends on the grammar format.
:type beam_size: int
:param beam_size: The maximum length for the parser's edge queue.
    Only used for probabilistic CFGs.
:param load_args: Keyword parameters used when loading the grammar.
    See ``data.load`` for more information.
z1The grammar must be a CFG, or a subclass thereof.)ÚtraceÚ	beam_size)r   Úchart_class)r   Ú
isinstancer   Ú
ValueErrorr   r
   r   r	   r   r   r   )Úgrammar_urlr   Úparserr   r   Ú	load_argsÚgrammars   &&&&&, Ú1/usr/lib/python3/dist-packages/nltk/parse/util.pyÚload_parserr      s¤   € ôD �;Ñ, )Ñ,€GÜ�gœs×#Ò#ÜÐOÓPÐPÜ�'œ4× Ò ØŠ>Ü&ˆFÙ�g°iÔ@Ð@ä	�Gœ^×	,Ò	,ØŠ>Ü'ˆFØÒÜ&ˆKÙ�g¸ÔDÐDð Š>Ü ˆFØÒÜˆKÙ�g¸ÔDÐDó    c              #  ó    "  € \        V ^R7       F8  w  pw  r#\        V4      VRW3RRRRR.
pRP                  V4      R,           pVx € K:  	  R# 5i)a®  
A module to convert a single POS tagged sentence into CONLL format.

>>> from nltk import word_tokenize, pos_tag
>>> text = "This is a foobar sentence."
>>> for line in taggedsent_to_conll(pos_tag(word_tokenize(text))): # doctest: +NORMALIZE_WHITESPACE
...         print(line, end="")
    1       This    _       DT      DT      _       0       a       _       _
    2       is      _       VBZ     VBZ     _       0       a       _       _
    3       a       _       DT      DT      _       0       a       _       _
    4       foobar  _       JJ      JJ      _       0       a       _       _
    5       sentence        _       NN      NN      _       0       a       _       _
    6       .               _       .       .       _       0       a       _       _

:param sentence: A single input sentence to parse
:type sentence: list(tuple(str, str))
:rtype: iter(str)
:return: a generator yielding a single sentence in CONLL format.
)ÚstartÚ_Ú0ÚaÚ	Ú
N)Ú	enumerateÚstrÚjoin)ÚsentenceÚiÚwordÚtagÚ	input_strs   &    r   Útaggedsent_to_conllr'   O   sR   é € ô( $ H°A×6‰ˆ‰;ˆDÜ˜“V˜T 3¨°#°s¸CÀÀcÐJˆ	Ø—I‘I˜iÓ(¨4Õ/ˆ	ØŒó 7ùs   ‚AAc              #  óR   "  € V  F  p\        V4       Rj  x€L
  Rx € K  	  R#  L5i)a¹  
A module to convert the a POS tagged document stream
(i.e. list of list of tuples, a list of sentences) and yield lines
in CONLL format. This module yields one line per word and two newlines
for end of sentence.

>>> from nltk import word_tokenize, sent_tokenize, pos_tag
>>> text = "This is a foobar sentence. Is that right?"
>>> sentences = [pos_tag(word_tokenize(sent)) for sent in sent_tokenize(text)]
>>> for line in taggedsents_to_conll(sentences): # doctest: +NORMALIZE_WHITESPACE
...     if line:
...         print(line, end="")
1   This    _       DT      DT      _       0       a       _       _
2   is      _       VBZ     VBZ     _       0       a       _       _
3   a       _       DT      DT      _       0       a       _       _
4   foobar  _       JJ      JJ      _       0       a       _       _
5   sentence        _       NN      NN      _       0       a       _       _
6   .               _       .       .       _       0       a       _       _
<BLANKLINE>
<BLANKLINE>
1   Is      _       VBZ     VBZ     _       0       a       _       _
2   that    _       IN      IN      _       0       a       _       _
3   right   _       NN      NN      _       0       a       _       _
4   ?       _       .       .       _       0       a       _       _
<BLANKLINE>
<BLANKLINE>

:param sentences: Input sentences to parse
:type sentence: list(list(tuple(str, str)))
:rtype: iter(str)
:return: a generator yielding sentences in CONLL format.
Nz

)r'   )Ú	sentencesr"   s   & r   Útaggedsents_to_conllr*   i   s(   é € óB ˆÜ& xÓ0×0Ð0ØŒó Ù0ùs   ‚'–%—'c                   ó8   a € ] tR t^”t o RtRR ltRR ltRtV tR# )ÚTestGrammarz
Unit tests for  CFG.
Nc                óZ   € Wn         \        V^ R7      V n        W n        W0n        W@n        R# )é    )r   N)Útest_grammarr   ÚcpÚsuiteÚ_acceptÚ_reject)Úselfr   r1   ÚacceptÚrejects   &&&&&r   Ú__init__ÚTestGrammar.__init__™   s%   € Ø#Ôä˜g¨QÔ/ˆŒØŒ
ØŒØŽr   c                ó.  € V P                    EF  p\        VR,          R,           RR7       R F¿  pW#,           F°  pVP                  4       p\        V P                  P                  V4      4      pV'       d2   V'       d*   \        4        \        V4       V F  p\        V4       K  	  VR8X  d   V. 8X  d   \        RV,          4      hRpK”  V'       d   \        RV,          4      hRp	K²  	  KÁ  	  X'       g   Kî  X	'       g   Kø  \        R	4       EK  	  R
# )aE  
Sentences in the test suite are divided into two classes:

- grammatical (``accept``) and
- ungrammatical (``reject``).

If a sentence should parse according to the grammar, the value of
``trees`` will be a non-empty list. If a sentence should be rejected
according to the grammar, then the value of ``trees`` will be None.
ÚdocÚ:Ú )Úendr5   zSentence '%s' failed to parse'TzSentence '%s' received a parse'zAll tests passed!N)r5   r6   )r1   ÚprintÚsplitÚlistr0   Úparser   )
r4   Ú
show_treesÚtestÚkeyÚsentÚtokensÚtreesÚtreeÚacceptedÚrejecteds
   &&        r   ÚrunÚTestGrammar.run¡   sÔ   € ð —J•JˆDÜ�$�u•+ Õ#¨Õ-Û+�Ø ŸI˜I�DØ!ŸZ™Z›\�FÜ  §¡§¡¨vÓ!6Ó7�Eß!§eÜœÜ˜dœÛ$)˜DÜ! $žKñ %*à˜h”Ø  Bœ;Ü",Ð-MÐPTÕ-TÓ"UÐUà'+šHç Ü",Ð-NÐQUÕ-UÓ"VÐVà'+šHó# &ñ ,÷& ‰xŸH™HÜÐ)×*ó- r   )r2   r3   r0   r1   r/   )NN)F)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r7   rK   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r,   r,   ”   s   ø‡ € ñô÷!+ò !+r   r,   c                ó   € Ve   V P                  V4      p . pV P                  R4       F¡  pVR8X  g   V^ ,          V9   d   K  VP                  R^4      pRp\        V4      ^8X  d@   V^ ,          R9   d   V^ ,          R9   pV^,          pM\        V^ ,          4      pV^,          pVP                  4       pV. 8X  d   K–  W7V3.,          pK£  	  V# )a\  
Parses a string with one test sentence per line.
Lines can optionally begin with:

- a bool, saying if the sentence is grammatical or not, or
- an int, giving the number of parse trees is should have,

The result information is followed by a colon, and then the sentence.
Empty lines and lines beginning with a comment char are ignored.

:return: a list of tuple of sentences and expected results,
    where a sentence is a list of str,
    and a result is None, or bool, or int

:param comment_chars: ``str`` of possible comment characters.
:param encoding: the encoding of the string, if it is binary
Nr   Ú r;   )ÚTrueÚtrueÚFalseÚfalse)rW   rX   )Údecoder?   ÚlenÚint)ÚstringÚcomment_charsÚencodingr)   r"   Ú
split_infoÚresultrF   s   &&&     r   Úextract_test_sentencesrc   Å   sÐ   € ð$ ÒØ—‘˜xÓ(ˆØ€IØ—L‘L Ö&ˆØ�rŒ>˜X a�[¨MÔ9ÙØ—^‘^ C¨Ó+ˆ
ØˆÜˆz‹?˜aÔØ˜!�}Ð BÔBØ# A�Ð*:Ñ:�Ø% a�=‘ä˜Z¨�]Ó+�Ø% a�=�Ø—‘Ó!ˆØ�RŒ<ÙØ˜vÐ&Ð'Õ'Š	ñ 'ð  Ðr   )r.   NNr.   )z#%;N)rQ   Ú	nltk.datar   Únltk.grammarr   r   r   Únltk.parse.chartr   r   Únltk.parse.featurechartr   r	   Únltk.parse.pchartr
   r   r'   r*   r,   rc   © r   r   Ú<module>rj      s@   ðñõ ß 2Ñ 2ß /ß DÝ /ô6Eòrò4#÷V.+ñ .+öb%r   