+
    ÖÇÜhB  ã                   ót   € R t ^ RIt^ RIHt  ^ RItRsRR ltR	R ltR
R lt	R t
R tR#   ] d    Rt L$i ; i)aP  
A set of functions used to interface with the external megam_ maxent
optimization package. Before megam can be used, you should tell NLTK where it
can find the megam binary, using the ``config_megam()`` function. Typical
usage:

    >>> from nltk.classify import megam
    >>> megam.config_megam() # pass path to megam if not found in PATH # doctest: +SKIP
    [Found megam: ...]

Use with MaxentClassifier. Example below, see MaxentClassifier documentation
for details.

    nltk.classify.MaxentClassifier.train(corpus, 'megam')

.. _megam: https://www.umiacs.umd.edu/~hal/megam/index.html
N)Úfind_binaryc                ó,   € \        RV R.. RORR7      sR# )a%  
Configure NLTK's interface to the ``megam`` maxent optimization
package.

:param bin: The full path to the ``megam`` binary.  If not specified,
    then nltk will search the system for a ``megam`` binary; and if
    one is not found, it will raise a ``LookupError`` exception.
:type bin: str
ÚmegamÚMEGAMz0https://www.umiacs.umd.edu/~hal/megam/index.html)Úenv_varsÚbinary_namesÚurlN)z	megam.optr   Ú	megam_686zmegam_i686.opt)r   Ú
_megam_bin)Úbins   &Ú5/usr/lib/python3/dist-packages/nltk/classify/megam.pyÚconfig_megamr   )   s   € ô ØØØ�ÚJØ>ô‚Jó    c                ó   aaa
€ SP                  4       p\        V4       UUu/ uF  w  rgWvbK	  	  pppV  FÐ  w  o
o\        SR4      '       d.   VP                  RP	                  VV
V3R lV 4       4      4       MVP                  RVS,          ,          4       V'       g   \        SP                  S
S4      W#4       M6V F0  p	VP                  R4       \        SP                  S
V	4      W#4       K2  	  VP                  R4       KÒ  	  R# u uppi )a–  
Generate an input file for ``megam`` based on the given corpus of
classified tokens.

:type train_toks: list(tuple(dict, str))
:param train_toks: Training data, represented as a list of
    pairs, the first member of which is a feature dictionary,
    and the second of which is a classification label.

:type encoding: MaxentFeatureEncodingI
:param encoding: A feature encoding, used to convert featuresets
    into feature vectors. May optionally implement a cost() method
    in order to assign different costs to different class predictions.

:type stream: stream
:param stream: The stream to which the megam input file should be
    written.

:param bernoulli: If true, then use the 'bernoulli' format.  I.e.,
    all joint features have binary values, and are listed iff they
    are true.  Otherwise, list feature values explicitly.  If
    ``bernoulli=False``, then you must call ``megam`` with the
    ``-fvals`` option.

:param explicit: If true, then use the 'explicit' format.  I.e.,
    list the features that would fire for any of the possible
    labels, for each token.  If ``explicit=True``, then you must
    call ``megam`` with the ``-explicit`` option.
ÚcostÚ:c              3   ó\   <"  € T F!  p\        SP                  SSV4      4      x € K#  	  R # 5i©N)Ústrr   )Ú.0ÚlÚencodingÚ
featuresetÚlabels   & €€€r   Ú	<genexpr>Ú#write_megam_file.<locals>.<genexpr>i   s&   øé € ÐRÉ6Àaœ˜XŸ]™]¨:°u¸aÓ@×AÐAË6ùs   ƒ),z%dz #Ú
N)ÚlabelsÚ	enumerateÚhasattrÚwriteÚjoinÚ_write_megam_featuresÚencode)Ú
train_toksr   ÚstreamÚ	bernoulliÚexplicitr   Úir   Úlabelnumr   r   s   &f&&&  `  @r   Úwrite_megam_filer*   B   sÝ   ú€ ð> �_‰_Ó€FÜ+4°VÔ+<Ô=Ñ+<™Z˜a�’Ñ+<€HÑ=ó (Ñˆ
�Eä�8˜V×$Ò$Ø�L‰LØ—‘ÖRÉ6ÓRÓRõð �L‰L˜ ¨¥Õ/Ô0÷ Ü! (§/¡/°*¸eÓ"DÀfÕXó
 �Ø—‘˜TÔ"Ü% h§o¡o°jÀ!Ó&DÀfÖXñ ð
 	�‰�TÖó- (ùó >s   ¢D
c                óJ  € \         f   \        R4      hV'       g   Q R4       hV P                  4       P                  R4      p\         P                  ! VR4      pV FD  pVP                  4       '       g   K  VP                  4       w  rg\        V4      V\        V4      &   KF  	  V# )zÄ
Given the stdout output generated by ``megam`` when training a
model, return a ``numpy`` array containing the corresponding weight
vector.  This function does not currently handle bias features.
z.This function requires that numpy be installedznon-explicit not supported yetr   Úd)ÚnumpyÚ
ValueErrorÚstripÚsplitÚzerosÚfloatÚint)ÚsÚfeatures_countr'   ÚlinesÚweightsÚlineÚfidÚweights   &&&     r   Úparse_megam_weightsr;   ~   s‚   € ô ‚}ÜÐIÓJÐJßÐ5Ð5Ó5ˆ8Ø�G‰G‹I�O‰O˜DÓ!€EÜ�kŠk˜.¨#Ó.€GÛˆØ�:‰:�<Œ<ØŸ*™*›,‰KˆCÜ % f£ˆG”C˜“HÓñ ð €Nr   c                 óê   € V '       g   \        R 4      hV  FY  w  r4V'       d6   V^8X  d   VP                  RV,          4       K.  V^ 8w  d   \        R4      hKB  VP                  RV RV 24       K[  	  R# )z:MEGAM classifier requires the use of an always-on feature.z %sz3If bernoulli=True, then allfeatures must be binary.Ú N)r.   r    )Úvectorr%   r&   r9   Úfvals   &&&  r   r"   r"   �   st   € ßÜØKó
ð 	
ó ‰	ˆßØ�qŒyØ—‘˜U S�[Ö)Ø˜”Ü ØLóð ñ ð
 �L‰L˜1˜S˜E  4 &Ð)Ö*ó r   c                ó¨  € \        V \        4      '       d   \        R4      h\        f   \	        4        \        .V ,           p\
        P                  ! V\
        P                  R7      pVP                  4       w  r4VP                  ^ 8w  d!   \        4        \        V4       \        R4      h\        V\        4      '       d   V# VP                  R4      # )z5
Call the ``megam`` binary with the given arguments.
z args should be a list of strings)Ústdoutzmegam command failed!zutf-8)Ú
isinstancer   Ú	TypeErrorr
   r   Ú
subprocessÚPopenÚPIPEÚcommunicateÚ
returncodeÚprintÚOSErrorÚdecode)ÚargsÚcmdÚprA   Ústderrs   &    r   Ú
call_megamrP   ¡   s¡   € ô �$œ×ÒÜÐ:Ó;Ð;ÜÒÜŒô ˆ,˜Õ
€CÜ×Ò˜¤Z§_¡_Ô5€AØ—}‘}“Ñ€Vð 	‡|�|�qÔÜŒÜˆfŒÜÐ-Ó.Ð.ä�&œ#×ÒØˆà�}‰}˜WÓ%Ð%r   r   )TT)T)Ú__doc__rD   Únltk.internalsr   r-   ÚImportErrorr
   r   r*   r;   r"   rP   © r   r   Ú<module>rU      sR   ðñó" å &ðÛð €
ôô29ôxò$+ô"&øðE ô Ø‚Eðús   Ž+ «	7¶7