
    /h)                         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       H/var/www/auris/envauris/lib/python3.13/site-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    BR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]     'GAKK  ( QCr$ ": :
 	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+1r"$""<B>B!1HH(( "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XX^^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       '(:;NA{LL 
 <
 	eXX**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X4-  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4I	
+,..y9E	'N5;;=I4::<IE51nsxx112	$H-.D$K	 2 ekk)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