
    Of                     P    S r SSKrSSKrSSKJr   " S S\5      r " S S\5      rg)z
CorpusReader for PanLex Lite, a stripped down version of PanLex distributed
as an SQLite database. See the README.txt in the panlex_lite corpus directory
for more information on PanLex Lite.
    N)CorpusReaderc                   8    \ rS rSrSrSrS rS
S jrS rS r	S	r
g)PanLexLiteCorpusReader   a,  
        SELECT dnx2.mn, dnx2.uq, dnx2.ap, dnx2.ui, ex2.tt, ex2.lv
        FROM dnx
        JOIN ex ON (ex.ex = dnx.ex)
        JOIN dnx dnx2 ON (dnx2.mn = dnx.mn)
        JOIN ex ex2 ON (ex2.ex = dnx2.ex)
        WHERE dnx.ex != dnx2.ex AND ex.tt = ? AND ex.lv = ?
        ORDER BY dnx2.uq DESC
    a  
        SELECT s.tt, sum(s.uq) AS trq FROM (
            SELECT ex2.tt, max(dnx.uq) AS uq
            FROM dnx
            JOIN ex ON (ex.ex = dnx.ex)
            JOIN dnx dnx2 ON (dnx2.mn = dnx.mn)
            JOIN ex ex2 ON (ex2.ex = dnx2.ex)
            WHERE dnx.ex != dnx2.ex AND ex.lv = ? AND ex.tt = ? AND ex2.lv = ?
            GROUP BY ex2.tt, dnx.ui
        ) s
        GROUP BY s.tt
        ORDER BY trq DESC, s.tt
    c                 F   [         R                  " [        R                  R	                  US5      5      R                  5       U l        0 U l        0 U l        U R                  R                  S5       H-  nUS   U R                  US   '   US   U R                  US   '   M/     g )Nz	db.sqlitezSELECT uid, lv FROM lv   r   )
sqlite3connectospathjoincursor_c_uid_lv_lv_uidexecute)selfrootrows      @/usr/lib/python3/dist-packages/nltk/corpus/reader/panlex_lite.py__init__PanLexLiteCorpusReader.__init__-   s|    //"'',,t["ABIIK77??#;<C#&q6DLLQ #&q6DLLQ  =    Nc                     Uc)  U R                   R                  S5      R                  5       $ U R                   R                  SU45      R                  5       $ )a  
Return a list of PanLex language varieties.

:param lc: ISO 639 alpha-3 code. If specified, filters returned varieties
    by this code. If unspecified, all varieties are returned.
:return: the specified language varieties as a list of tuples. The first
    element is the language variety's seven-character uniform identifier,
    and the second element is its default name.
:rtype: list(tuple)
z#SELECT uid, tt FROM lv ORDER BY uidz0SELECT uid, tt FROM lv WHERE lc = ? ORDER BY uid)r   r   fetchall)r   lcs     r   language_varieties)PanLexLiteCorpusReader.language_varieties7   sI     :77??#HIRRTT77??BREhjr   c                    U R                   U   n0 nU R                  R                  U R                  X#45       Hd  nUS   nU R                  US      nXd;  a  US   US   US   X/0S.XF'   XtU   S   ;  a
  / XF   S   U'   XF   S   U   R                  US   5        Mf     U Vs/ s H  n[        XdU   5      PM     sn$ s  snf )	z
Return a list of meanings for an expression.

:param expr_uid: the expression's language variety, as a seven-character
    uniform identifier.
:param expr_tt: the expression's text.
:return: a list of Meaning objects.
:rtype: list(Meaning)
r      r         )uqapuiexr&      )r   r   r   	MEANING_Qr   appendMeaning)r   expr_uidexpr_ttexpr_lvmn_infoimnuids           r   meaningsPanLexLiteCorpusReader.meaningsJ   s     ,,x('1CDA1B,,qt$C=A$A$A$#Y/	 "+d++)+D!#&Kc"))!A$/ E" 4;;7RBK(7;;;s   %C c                     U R                   U   nU R                   U   nU R                  R                  U R                  XBU45      R	                  5       $ )a  
Return a list of translations for an expression into a single language
variety.

:param from_uid: the source expression's language variety, as a
    seven-character uniform identifier.
:param from_tt: the source expression's text.
:param to_uid: the target language variety, as a seven-character
    uniform identifier.
:return: a list of translation tuples. The first element is the expression
    text and the second element is the translation quality.
:rtype: list(tuple)
)r   r   r   TRANSLATION_Qr   )r   from_uidfrom_ttto_uidfrom_lvto_lvs         r   translations#PanLexLiteCorpusReader.translationsl   sI     ,,x(V$wwt11Ge3LMVVXXr   )r   r   r   )N)__name__
__module____qualname____firstlineno__r(   r5   r   r   r2   r;   __static_attributes__ r   r   r   r      s&    IM*& <DYr   r   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
r*      zb
Represents a single PanLex meaning. A meaning is a translation set derived
from a single source.
c                 .   > [         TU ]  " S0 UD6  XS'   g )Nr0   rB   )superr   )r   r0   attr	__class__s      r   r   Meaning.__init__   s     4 T
r   c                     U S   $ )z(
:return: the meaning's id.
:rtype: int
r0   rB   r   s    r   id
Meaning.id       
 Dzr   c                     U S   $ )zH
:return: the meaning's source's quality (0=worst, 9=best).
:rtype: int
r#   rB   rK   s    r   qualityMeaning.quality   rN   r   c                     U S   $ )z/
:return: the meaning's source id.
:rtype: int
r$   rB   rK   s    r   sourceMeaning.source   rN   r   c                     U S   $ )z5
:return: the meaning's source group id.
:rtype: int
r%   rB   rK   s    r   source_groupMeaning.source_group   rN   r   c                     U S   $ )z
:return: the meaning's expressions as a dictionary whose keys are language
    variety uniform identifiers and whose values are lists of expression
    texts.
:rtype: dict
r&   rB   rK   s    r   expressionsMeaning.expressions   s     Dzr   rB   )r=   r>   r?   r@   __doc__r   rL   rP   rS   rV   rY   rA   __classcell__)rH   s   @r   r*   r*      s+    
 r   r*   )r[   r   r	   nltk.corpus.reader.apir   r   dictr*   rB   r   r   <module>r_      s2    
  /jY\ jYZ-d -r   