
    /h5%                        S r SSKrSSKJr  SSKJrJrJrJr  SSK	J
r
  SSKJr  \R                  " S5      r\R                  " S5      r\R                  " S	5      r\R                  " S
\R"                  5      r\R                  " S\R"                  5      r\R                  " S\R"                  5      r\R                  " S5      r " S S5      r " S S5      rS rS rS rS rS rSS jrSS jr\
" S5      S 5       r\" S5      r g)z
CCG Lexicons
    N)defaultdict)CCGVar	DirectionFunctionalCategoryPrimitiveCategory)
deprecated)
Expressionz([A-Za-z]+)(\[[A-Za-z,]+\])?z"([A-Za-z]+(?:\[[A-Za-z,]+\])?)(.*)z([\\/])([.,]?)([.,]?)(.*)z([\S_]+)\s*(::|[-=]+>)\s*(.+)z([^{}]*[^ {}])\s*(\{[^}]+\})?z\{([^}]+)\}z([^#]*)(?:#.*)?c                   :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)Token-   z
Class representing a token.

token => category {semantics}
e.g. eat => S\var[pl]/var {\x y.eat(x,y)}

* `token` (string)
* `categ` (string)
* `semantics` (Expression)
Nc                 (    Xl         X l        X0l        g N)_token_categ
_semantics)selftokencateg	semanticss       H/var/www/auris/envauris/lib/python3.13/site-packages/nltk/ccg/lexicon.py__init__Token.__init__9   s    #    c                     U R                   $ r   )r   r   s    r   r   Token.categ>   s    {{r   c                     U R                   $ r   )r   r   s    r   r   Token.semanticsA   s    r   c                     SnU R                   b  S[        U R                   5      -   S-   nS[        U R                  5      -   U-   $ )N z {})r   strr   )r   semantics_strs     r   __str__Token.__str__D   sB    ??& 3t#77#=MC$$}44r   c                     [        U[        5      (       d  g[        U R                  U R                  4UR                  5       UR                  5       5      $ )N)
isinstancer   cmpr   r   r   r   )r   others     r   __cmp__Token.__cmp__J   s;    %''DKK15;;=%//BSTTr   )r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r$   r+   __static_attributes__ r   r   r   r   -   s!    	$
5Ur   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	
CCGLexiconP   z
Class representing a lexicon for CCG grammars.

* `primitives`: The list of primitive categories for the lexicon
* `families`: Families of categories
* `entries`: A mapping of words to possible categories
c                 H    [        U5      U l        X l        X0l        X@l        g r   )r   _start_primitives	_families_entries)r   start
primitivesfamiliesentriess        r   r   CCGLexicon.__init__Y   s    '.%!r   c                      U R                   U   $ )z0
Returns all the possible categories for a word
)r;   )r   words     r   
categoriesCCGLexicon.categories_   s     }}T""r   c                     U R                   $ )z+
Return the target category for the parser
)r8   r   s    r   r<   CCGLexicon.starte   s     {{r   c                     SnSn[        U R                  5       HE  nU(       d  US-   nX-   S-   nSnU R                  U    H  nU(       d  US-   nOSnUSU-  -   nM     MG     U$ )z;
String representation of the lexicon. Used for debugging.
r    T
z => z | Fz%s)sortedr;   )r   stringfirstidentcats        r   r$   CCGLexicon.__str__k   sw     DMM*E$^f,FE}}U+#e^F!E$*, , + r   )r;   r:   r9   r8   N)
r-   r.   r/   r0   r1   r   rC   r<   r$   r2   r3   r   r   r5   r5   P   s     #r   r5   c                 N   U SS nSnUS:w  ah  UR                  S5      (       dR  UR                  S5      (       a  [        U5      u  p1X#-   nOX!S   -   nUSS nUS:w  a  UR                  S5      (       d  MR  UR                  S5      (       a
  US-   USS 4$ [        SU -   S-   5      e)	zV
Separate the contents matching the first set of brackets from the rest of
the input.
   N(r    )r   zUnmatched bracket in string '')
startswithmatchBracketsAssertionError)rJ   restinsideparts       r   rU   rU      s    
 !":DF
"*T__S11??3(.LT]F1g%F8D "*T__S11 sd12h''
86ACG
HHr   c                     U R                  S5      (       a  [        U 5      $ [        R                  U 5      R	                  5       $ )zV
Separate the string for the next portion of the category from the rest
of the string
rQ   )rT   rU   NEXTPRIM_REmatchgroups)rJ   s    r   nextCategoryr^      s:    
 V$$V$++--r   c                 &    [        U S   U SS 5      $ )z
Parse an application operator
r   rP   N)r   )apps    r   parseApplicationra      s     SVSW%%r   c                 <    U (       a  U SS R                  S5      $ / $ )z/
Parse the subscripts for a primitive category
rP   r'   ,)split)subscrs    r   parseSubscriptsrf      s#     a|!!#&&Ir   c                     U S   S:X  a  U S   c  Uc
  [        5       nX34$ U S   nXB;   a$  X$   u  pVUc  UnXS4$ UR                  Xc4/5      nXS4$ XA;   a  [        U S   5      n[        XG5      U4$ [	        SU-   S-   5      e)zs
Parse a primitive category

If the primitive is the special category 'var', replace it with the
correct `CCGVar`.
r   varrP   zString 'z-' is neither a family nor primitive category.)r   
substituterf   r   rV   )chunksr=   r>   rh   catstrrM   cvarsubscrss           r   parsePrimitiveCategoryrn      s     ayE!9{h:AYF&;C z ..4+/Cz!&),!&2C88
VMM r   c                 @   [        U 5      u  pEUR                  S5      (       a  [        USS XU5      u  pcO0[        [        R                  U5      R                  5       XU5      u  pcUS:w  a  [        R                  U5      R                  5       n[        USS 5      nUS   n[        U5      u  pEUR                  S5      (       a  [        USS XU5      u  pO0[        [        R                  U5      R                  5       XU5      u  p[        XiU5      nUS:w  a  M  Xc4$ )zo
Parse a string representing a category, and returns a tuple with
(possibly) the CCG variable for the category
rQ   rP   r'   r    r      )
r^   rT   augParseCategoryrn   PRIM_REr\   r]   APP_REra   r   )
liner=   r>   rh   
cat_stringrW   resr`   	directionargs
             r   rq   rq      s   
 &d+ZS!!%j2&6
cR
c ,MM*%,,.
c

 "*ll4 '')$S1X.	1v)$/  %%)*Qr*:JRUVJS#/j)002J#JS !95 "* :r   c                    [         R                  " 5         / n0 n[        [        5      nU R	                  5        GHq  n[
        R                  U5      R                  5       S   R                  5       nUS:X  a  M@  UR                  S5      (       aE  UUSS R                  5       R                  S5       Vs/ s H  ofR                  5       PM     sn-   nM  [        R                  U5      R                  5       u  pxn	[        R                  U	5      R                  5       u  p[        XU5      u  pUS:X  a  X4X7'   GM  SnUSL aK  Uc  [        US	-   5      e[        R                   " ["        R                  U5      R                  5       S   5      nXG   R%                  ['        X|U5      5        GMt     [)        US   X#U5      $ s  snf )
z8
Convert string representation into a lexicon for CCGs.
r   r    z:-   Nrc   z::Tz@ must contain semantics because include_semantics is set to True)r   reset_idr   list
splitlinesCOMMENTS_REr\   r]   striprT   rd   LEX_RERHS_RErq   rV   r	   
fromstringSEMANTICS_REappendr   r5   )lex_strinclude_semanticsr=   r>   r?   rt   primrL   seprhsrk   r#   rM   rh   r   s                  r   r   r      s    OOJH$G""$  &--/288:2:??4   $)-ab)9)?)?)D')D

)D' J
 !'T 2 9 9 ;U&,ll3&7&>&>&@#V)&hGJSd{ $'* 	$,$,, `a 
 %/$9$9(..}=DDFqI%	
 %%eE	&BCK %L jmZ7CC9's   4F?zUse fromstring() instead.c                     [        U 5      $ r   )r   )r   s    r   parseLexiconr   "  s    gr   a  
    # Rather minimal lexicon based on the openccg `tinytiny' grammar.
    # Only incorporates a subset of the morphological subcategories, however.
    :- S,NP,N                    # Primitive categories
    Det :: NP/N                  # Determiners
    Pro :: NP
    IntransVsg :: S\NP[sg]    # Tensed intransitive verbs (singular)
    IntransVpl :: S\NP[pl]    # Plural
    TransVsg :: S\NP[sg]/NP   # Tensed transitive verbs (singular)
    TransVpl :: S\NP[pl]/NP   # Plural

    the => NP[sg]/N[sg]
    the => NP[pl]/N[pl]

    I => Pro
    me => Pro
    we => Pro
    us => Pro

    book => N[sg]
    books => N[pl]

    peach => N[sg]
    peaches => N[pl]

    policeman => N[sg]
    policemen => N[pl]

    boy => N[sg]
    boys => N[pl]

    sleep => IntransVsg
    sleep => IntransVpl

    eat => IntransVpl
    eat => TransVpl
    eats => IntransVsg
    eats => TransVsg

    see => TransVpl
    sees => TransVsg
    r   )F)!r1   recollectionsr   nltk.ccg.apir   r   r   r   nltk.internalsr   nltk.sem.logicr	   compilerr   r[   rs   UNICODEr   r   r   r~   r   r5   rU   r^   ra   rf   rn   rq   r   r   openccg_tinytinyr3   r   r   <module>r      s   
 # Q Q % % **8
9 jjBC 
4	5 
8"**	E 
8"**	E zz,bjj9 jj./ U  UF- -jI(.&<@.Db '( ) )+ r   