ó
    ´OÂfµ)  ã                   óž   • S SK Jr  S SKJr   S/r S SKJr  S SKJr  S r	S	 rS
 r " S S\5      rS rg! \
 a  r\4S jr	 SrCN&SrCff = f)é    )ÚParserI)ÚTreeÚBllipParser)ÚRerankingParser©Úget_unified_model_parametersc                  ó   • g ©N© r   ó    Ú2/usr/lib/python3/dist-packages/nltk/parse/bllip.pyÚ_ensure_bllip_import_or_errorr   Z   s   € Ør   c                 ó   • [        SU -  5      e)Nz&Couldn't import bllipparser module: %s)ÚImportError)Úies    r   r   r   _   s   € ÜÐBÀRÑGÓHÐHr   Nc                 óœ   •  [        U 5       H  u  pUR                  S5        M     g ! [         a  n[        SW SW< S35      UeS nAff = f)NÚasciizToken z (zH) is non-ASCII. BLLIP Parser currently doesn't support non-ASCII inputs.)Ú	enumerateÚencodeÚUnicodeEncodeErrorÚ
ValueError)ÚwordsÚiÚwordÚes       r   Ú_ensure_asciir   c   s]   € ðÜ  Ö'‰GˆAØ�K‰K˜Ö ò (øäó ÜØ�Q�C�r˜$™ð ":ð :ó
ð ð	ûðús   ‚%( ¨
A²AÁAc                 óT   • [         R                  " [        U R                  5      5      $ r
   )r   Ú
fromstringÚstrÚ	ptb_parse)Úscored_parses    r   Ú_scored_parse_to_nltk_treer"   n   s   € Ü�?Š?œ3˜|×5Ñ5Ó6Ó7Ð7r   c                   óN   • \ rS rSrSr     S	S jrS rS r\ S
S j5       r	Sr
g)r   ér   zÁ
Interface for parsing with BLLIP Parser. BllipParser objects can be
constructed with the ``BllipParser.from_unified_model_dir`` class
method or manually using the ``BllipParser`` constructor.
Nc                 óú   • [        5         U=(       d    0 nU=(       d    0 n[        5       U l        U R                  R                  " U40 UD6  U(       a(  U(       a   U R                  R                  " SUUS.UD6  ggg)a0  
Load a BLLIP Parser model from scratch. You'll typically want to
use the ``from_unified_model_dir()`` class method to construct
this object.

:param parser_model: Path to parser model directory
:type parser_model: str

:param reranker_features: Path the reranker model's features file
:type reranker_features: str

:param reranker_weights: Path the reranker model's weights file
:type reranker_weights: str

:param parser_options: optional dictionary of parser options, see
    ``bllipparser.RerankingParser.RerankingParser.load_parser_options()``
    for more information.
:type parser_options: dict(str)

:param reranker_options: optional
    dictionary of reranker options, see
    ``bllipparser.RerankingParser.RerankingParser.load_reranker_model()``
    for more information.
:type reranker_options: dict(str)
)Úfeatures_filenameÚweights_filenameNr   )r   r   ÚrrpÚload_parser_modelÚload_reranker_model)ÚselfÚparser_modelÚreranker_featuresÚreranker_weightsÚparser_optionsÚreranker_optionss         r   Ú__init__ÚBllipParser.__init__y   sv   € ôB 	&Ô'à'×-¨2ˆØ+×1¨rÐä"Ó$ˆŒØ�‰×"Ò" <ÑB°>ÒBÞÖ!1Ø�H‰H×(Ò(ð Ø"3Ø!1ñð #óð "2Ðr   c              #   ó„   #   • [        U5        U R                  R                  U5      nU H  n[        U5      v •  M     g7f)aW  
Use BLLIP Parser to parse a sentence. Takes a sentence as a list
of words; it will be automatically tagged with this BLLIP Parser
instance's tagger.

:return: An iterator that generates parse trees for the sentence
    from most likely to least likely.

:param sentence: The sentence to be parsed
:type sentence: list(str)
:rtype: iter(Tree)
N)r   r(   Úparser"   )r+   ÚsentenceÚ
nbest_listr!   s       r   r4   ÚBllipParser.parse¨   s6   é € ô 	�hÔØ—X‘X—^‘^ HÓ-ˆ
Û&ˆLÜ,¨\Ó:Ô:ò 'ùs   ‚>A c              #   óî   #   • / n0 n[        U5       H"  u  nu  pVUR                  U5        Uc  M  XcU'   M$     [        U5        U R                  R	                  X#5      nU H  n[        U5      v •  M     g7f)a@  
Use BLLIP to parse a sentence. Takes a sentence as a list of
(word, tag) tuples; the sentence must have already been tokenized
and tagged. BLLIP will attempt to use the tags provided but may
use others if it can't come up with a complete parse subject
to those constraints. You may also specify a tag as ``None``
to leave a token's tag unconstrained.

:return: An iterator that generates parse trees for the sentence
    from most likely to least likely.

:param sentence: Input sentence to parse as (word, tag) pairs
:type sentence: list(tuple(str, str))
:rtype: iter(Tree)
N)r   Úappendr   r(   Úparse_taggedr"   )	r+   Úword_and_tag_pairsr   Útag_mapr   r   Útagr6   r!   s	            r   Útagged_parseÚBllipParser.tagged_parseº   sr   é € ð  ˆØˆÜ'Ð(:Ö;‰NˆA‰{�Ø�L‰L˜ÔØ‹Ø ˜“
ñ <ô
 	�eÔØ—X‘X×*Ñ*¨5Ó:ˆ
Û&ˆLÜ,¨\Ó:Ô:ò 'ùs   ‚*A5°AA5c                 ó8   • [        U5      u  nnnU " UUUUU5      $ )a�  
Create a ``BllipParser`` object from a unified parsing model
directory. Unified parsing model directories are a standardized
way of storing BLLIP parser and reranker models together on disk.
See ``bllipparser.RerankingParser.get_unified_model_parameters()``
for more information about unified model directories.

:return: A ``BllipParser`` object using the parser and reranker
    models in the model directory.

:param model_dir: Path to the unified model directory.
:type model_dir: str
:param parser_options: optional dictionary of parser options, see
    ``bllipparser.RerankingParser.RerankingParser.load_parser_options()``
    for more information.
:type parser_options: dict(str)
:param reranker_options: optional dictionary of reranker options, see
    ``bllipparser.RerankingParser.RerankingParser.load_reranker_model()``
    for more information.
:type reranker_options: dict(str)
:rtype: BllipParser
r   )ÚclsÚ	model_dirr/   r0   Úparser_model_dirÚreranker_features_filenameÚreranker_weights_filenames          r   Úfrom_unified_model_dirÚ"BllipParser.from_unified_model_dirÖ   s6   € ô< )¨Ó3ñ		
ØØ&Ø%áØØ&Ø%ØØó
ð 	
r   )r(   )NNNNN)NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r1   r4   r>   ÚclassmethodrF   Ú__static_attributes__r   r   r   r   r   r   s?   † ñð ØØØØô-ò^;ò$;ð8 à>Bó$
ó ó$
r   c            	      ó  • SSK Jn   U " S5      R                  n[        S5        [        R                  U5      n[        S5        SR                  5       nSR                  5       nSR                  5       nX4U4 HF  n[        S	S
R                  U5      -  5         [        UR                  U5      5      n[        U5        MH     [        UR                  U5      5       H  u  p‰[        SX‰4-  5        M     [        S[        UR                  SS/5      5      5        [        S[        UR                  SS/5      5      5        [        S[        UR                  SS/5      5      5        g! [         a    [        S5         GM  f = f)z8This assumes the Python module bllipparser is installed.r   )Úfindzmodels/bllip_wsj_no_auxzLoading BLLIP Parsing models...zDone.z#British left waffles on Falklands .z"I saw the man with the telescope .z	# ! ? : -zSentence: %rÚ z(parse failed)zparse %d:
%szforcing 'tree' to be 'NN':)ÚAN)ÚtreeÚNNz.forcing 'A' to be 'DT' and 'tree' to be 'NNP':)rR   ÚDT)rS   ÚNNPzforcing 'A' to be 'NNP':)rR   rV   )rS   NN)Ú	nltk.datarP   ÚpathÚprintr   rF   ÚsplitÚjoinÚnextr4   ÚStopIterationr   r>   )
rP   rB   ÚbllipÚ	sentence1Ú	sentence2Úfail1r5   rS   r   r4   s
             r   Údemorb   þ   s]  € õ áÐ.Ó/×4Ñ4€Iä	Ð
+Ô,ä×.Ñ.¨yÓ9€EÜ	ˆ'„Nà5×;Ñ;Ó=€IØ4×:Ñ:Ó<€Ià×ÑÓ€EØ¨5Ó1ˆÜˆn˜sŸx™x¨Ó1Ñ1Ô2ð	$Ü˜Ÿ™ HÓ-Ó.ˆDÜ�$ŽKñ	 2ô ˜eŸk™k¨)Ó4Ö5‰ˆÜˆo  
Ñ*Ö+ñ 6ô 
Ø$ÜˆU×Ñ ¨nÐ =Ó>Ó?ôô 
Ø8ÜˆU×Ñ ¨oÐ >Ó?Ó@ôô 
Ø"ÜˆU×Ñ ¨~Ð >Ó?Ó@õøô% ó 	$ÜÐ"×#Ð#ð	$ús   Â%E'Å'FÆ F)Únltk.parse.apir   Ú	nltk.treer   Ú__all__Úbllipparserr   Úbllipparser.RerankingParserr   r   r   r   r   r"   r   rb   r   r   r   Ú<module>rh      sp   ðõ #Ý ðDðL ˆ/€ð
IÝ+ÝHòòò8ôI
�'ô I
óX-øðC ó Ià)+÷ Iñ IûðIús   ’6 ¶A¼AÁA