a
     ˜ëjÏx  ã                   @   s:   d Z ddlZddlmZ ddlmZ G dd„ dejƒZdS )z
Unit tests for nltk.tgrep.
é    N)Útgrep)ÚParentedTreec                   @   sø   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<S )=ÚTestSequenceFunctionsz5
    Class containing unit tests for nltk.tgrep.
    c                 C   s   t  d¡}|  |g d¢¡ dS )z.
        Simple test of tokenization.
        ú%A .. (B !< C . D) | ![<< (E , F) $ G])ÚAú..ú(ÚBú!ú<ÚCÚ.ÚDú)ú|r
   ú[ú<<r   ÚEú,ÚFr   ú$ÚGú]N)r   Útgrep_tokenizeÚassertEqual)ÚselfÚtokens© r   úX/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/test/unit/test_tgrep.pyÚtest_tokenize_simple   s
    
þz*TestSequenceFunctions.test_tokenize_simplec                 C   s   |   t d¡t d¡¡ dS )zM
        Test that tokenization handles bytes and strs the same way.
        s%   A .. (B !< C . D) | ![<< (E , F) $ G]r   N©r   r   r   ©r   r   r   r   Útest_tokenize_encoding;   s    þz,TestSequenceFunctions.test_tokenize_encodingc                 C   sX  |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d	¡g d
¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d ¢¡ |   t d!¡g d"¢¡ |   t d#¡g d$¢¡ |   t d%¡g d&¢¡ |   t d'¡g d(¢¡ |   t d)¡g d*¢¡ |   t d+¡g d,¢¡ |   t d-¡g d.¢¡ |   t d/¡g d0¢¡ |   t d1¡g d2¢¡ |   t d3¡g d4¢¡ |   t d5¡g d6¢¡ |   t d7¡g d8¢¡ |   t d9¡g d:¢¡ |   t d;¡g d<¢¡ |   t d=¡g d>¢¡ |   t d?¡g d@¢¡ |   t dA¡g dB¢¡ |   t dC¡g dD¢¡ |   t dE¡g dF¢¡ |   t dG¡g dH¢¡ |   t dI¡g dJ¢¡ |   t dK¡g dL¢¡ |   t dM¡g dN¢¡ |   t dO¡g dP¢¡ |   t dQ¡g dR¢¡ |   t dS¡g dT¢¡ |   t dU¡g dV¢¡ |   t dW¡g dX¢¡ |   t dY¡g dZ¢¡ |   t d[¡g d\¢¡ |   t d]¡g d^¢¡ |   t d_¡g d`¢¡ |   t da¡g db¢¡ |   t dc¡g dd¢¡ |   t de¡g df¢¡ |   t dg¡g dh¢¡ |   t di¡g dj¢¡ |   t dk¡g dl¢¡ |   t dm¡g dn¢¡ |   t do¡g dp¢¡ |   t dq¡g dr¢¡ |   t ds¡g dt¢¡ |   t du¡g dv¢¡ |   t dw¡g dx¢¡ |   t dy¡g dz¢¡ |   t d{¡g d|¢¡ d}S )~z8
        Test tokenization of basic link types.
        zA<B)r   r   r	   zA>B)r   ú>r	   zA<3B)r   ú<3r	   zA>3B)r   ú>3r	   zA<,B)r   ú<,r	   zA>,B)r   ú>,r	   zA<-3B)r   ú<-3r	   zA>-3B)r   ú>-3r	   zA<-B)r   ú<-r	   zA>-B)r   ú>-r	   zA<'B)r   ú<'r	   zA>'B)r   ú>'r	   zA<:B)r   ú<:r	   zA>:B)r   ú>:r	   zA<<B)r   r   r	   zA>>B)r   ú>>r	   zA<<,B)r   ú<<,r	   zA>>,B)r   ú>>,r	   zA<<'B)r   ú<<'r	   zA>>'B)r   ú>>'r	   zA<<:B)r   ú<<:r	   zA>>:B)r   ú>>:r	   zA.B)r   r   r	   zA,B)r   r   r	   zA..B)r   r   r	   zA,,B)r   ú,,r	   zA$B)r   r   r	   zA$.B)r   ú$.r	   zA$,B)r   ú$,r	   zA$..B)r   ú$..r	   zA$,,B)r   ú$,,r	   zA!<B)r   r
   r   r	   zA!>B)r   r
   r#   r	   zA!<3B)r   r
   r$   r	   zA!>3B)r   r
   r%   r	   zA!<,B)r   r
   r&   r	   zA!>,B)r   r
   r'   r	   zA!<-3B)r   r
   r(   r	   zA!>-3B)r   r
   r)   r	   zA!<-B)r   r
   r*   r	   zA!>-B)r   r
   r+   r	   zA!<'B)r   r
   r,   r	   zA!>'B)r   r
   r-   r	   zA!<:B)r   r
   r.   r	   zA!>:B)r   r
   r/   r	   zA!<<B)r   r
   r   r	   zA!>>B)r   r
   r0   r	   zA!<<,B)r   r
   r1   r	   zA!>>,B)r   r
   r2   r	   zA!<<'B)r   r
   r3   r	   zA!>>'B)r   r
   r4   r	   zA!<<:B)r   r
   r5   r	   zA!>>:B)r   r
   r6   r	   zA!.B)r   r
   r   r	   zA!,B)r   r
   r   r	   zA!..B)r   r
   r   r	   zA!,,B)r   r
   r7   r	   zA!$B)r   r
   r   r	   zA!$.B)r   r
   r8   r	   zA!$,B)r   r
   r9   r	   zA!$..B)r   r
   r:   r	   zA!$,,B)r   r
   r;   r	   Nr    r!   r   r   r   Útest_tokenize_link_typesD   s|    z.TestSequenceFunctions.test_tokenize_link_typesc                 C   sô   |   t d¡g d¢¡ |   t d¡dg¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d	¢¡ |   t d
¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ |   t d¡g d¢¡ dS )zJ
        Test tokenization of the TGrep2 manual example patterns.
        úNP < PP)ÚNPr   ÚPPú/^NP/úNP << PP . VP)r>   r   r?   r   ÚVPúNP << PP | . VP)r>   r   r?   r   r   rB   úNP !<< PP [> NP | >> VP])r>   r
   r   r?   r   r#   r>   r   r0   rB   r   úNP << (PP . VP))r>   r   r   r?   r   rB   r   úNP <' (PP <, (IN < on)))r>   r,   r   r?   r&   r   ÚINr   Úonr   r   úS < (A < B) < C)	ÚSr   r   r   r   r	   r   r   r   úS < ((A < B) < C))rJ   r   r   r   r   r   r	   r   r   r   r   úS < (A < B < C))	rJ   r   r   r   r   r	   r   r   r   zA<B&.C)r   r   r	   ú&r   r   Nr    r!   r   r   r   Útest_tokenize_examples‡   sB    ÿÿþþþþþþz,TestSequenceFunctions.test_tokenize_examplesc                 C   s   |   t d¡g d¢¡ dS )z/
        Test tokenization of quoting.
        z"A<<:B"<<:"A $.. B"<"A>3B"<C)z"A<<:B"r5   z	"A $.. B"r   z"A>3B"r   r   Nr    r!   r   r   r   Útest_tokenize_quoting­   s    þz+TestSequenceFunctions.test_tokenize_quotingc                 C   s¬   |   t d¡dg¡ |   t d¡dg¡ |   t d¡dg¡ |   t d¡dg¡ |   t d¡ddg¡ |   t d¡g d	¢¡ |   t d
¡g d¢¡ |   t d¡g d¢¡ dS )z2
        Test tokenization of node names.
        ZRobertz	/^[Bb]ob/Ú*Ú__zN()úN(r   zN(0,))rR   Ú0r   r   zN(0,0))rR   rS   r   rS   r   zN(0,0,))rR   rS   r   rS   r   r   Nr    r!   r   r   r   Útest_tokenize_nodenames¶   s    ÿz-TestSequenceFunctions.test_tokenize_nodenamesc                 C   s   |   t d¡g d¢¡ dS )z9
        Test tokenization of macro definitions.
        z4@ NP /^NP/;
@ NN /^NN/;
@NP [!< NP | < @NN] !$.. @NN)ú@r>   r@   ú;rU   ÚNNz/^NN/rV   z@NPr   r
   r   r>   r   r   ú@NNr   r
   r:   rX   Nr    r!   r   r   r   Útest_tokenize_macrosÆ   s    ÿüz*TestSequenceFunctions.test_tokenize_macrosc                 C   sv   t  d¡}|  tt d|g¡ƒddgg¡ |  tt d|g¡ƒ|d |d gg¡ |  tt d|g¡ƒg d¢g¡ dS )z`
        Test a simple use of tgrep for finding nodes matching a given
        pattern.
        úA(S (NP (DT the) (JJ big) (NN dog)) (VP bit) (NP (DT a) (NN cat)))rW   ©r   é   ©r\   é   úNN|JJ)©r   r^   r[   r]   N©r   Ú
fromstringr   Úlistr   Útgrep_positionsZtgrep_nodes©r   Útreer   r   r   Útest_node_simpleæ   s    ÿ  ÿÿz&TestSequenceFunctions.test_node_simplec                 C   s^   t  d¡}|  tt d|g¡ƒtt d|g¡ƒ¡ |  tt d|g¡ƒtt d|g¡ƒ¡ dS )z9Test that the tgrep print operator ' is properly ignored.ú(S (n x) (N x))ÚNz'Nz/[Nn]/z'/[Nn]/N©r   rb   r   rc   r   rd   re   r   r   r   Útest_node_printingö   s    
þþz(TestSequenceFunctions.test_node_printingc                 C   s†   t  d¡}|  tt d|g¡ƒtt d|g¡ƒ¡ |  tt d|g¡ƒtt d|g¡ƒ¡ |  tt d|g¡ƒtt d|g¡ƒ¡ dS )z]
        Test that tgrep search strings handles bytes and strs the same
        way.
        rZ   s   NNrW   s   NN|JJr_   Nra   re   r   r   r   Útest_node_encoding  s    ÿþþþz(TestSequenceFunctions.test_node_encodingc                 C   sL   t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒddgg¡ dS )zI
        Test selecting nodes using case insensitive node names.
        rh   ú"N"©r^   zi@"N"©r   Nrj   re   r   r   r   Útest_node_nocase  s    
z&TestSequenceFunctions.test_node_nocasec                 C   s†   t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒd	gg¡ d
S )z?
        Test selecting nodes using quoted node names.
        z(N ("N" x) (N" x) ("\" x))rm   r   z"\"N\""ro   z"N\""rn   z"\"\\\""©r\   Nrj   re   r   r   r   Útest_node_quoted  s
    
z&TestSequenceFunctions.test_node_quotedc                 C   s.   t  d¡}|  tt d|g¡ƒddgg¡ dS )ú/
        Test regex matching on nodes.
        ú$(S (NP-SBJ x) (NP x) (NNP x) (VP x))r@   ro   rn   Nrj   re   r   r   r   Útest_node_regex)  s    
z%TestSequenceFunctions.test_node_regexc                 C   sN   t  d¡}|  tt d|g¡ƒddgg¡ |  tt d|g¡ƒg d¢g¡ dS )rs   z(S (SBJ x) (SBJ1 x) (NP-SBJ x))z/^SBJ/ro   rn   z/SBJ/)ro   rn   rq   Nrj   re   r   r   r   Útest_node_regex_22  s
    
 ÿz'TestSequenceFunctions.test_node_regex_2c                    s�   t  d¡‰‡fdd„ttˆ ¡ ƒƒD ƒ‰ ‡ fdd„ˆ ¡ D ƒ}|D ]H}d|› �}tt |ˆg¡ƒ}|  	t|d ƒd¡ |  	|d d |¡ qBd	S )
zE
        Test matching on nodes based on NLTK tree position.
        rt   c                    s   h | ]}ˆ   |¡’qS r   )Zleaf_treeposition©Ú.0Úx)rf   r   r   Ú	<setcomp>D  ó    z@TestSequenceFunctions.test_node_tree_position.<locals>.<setcomp>c                    s   g | ]}|ˆ vr|‘qS r   r   rw   )Úleaf_positionsr   r   Ú
<listcomp>E  r{   zATestSequenceFunctions.test_node_tree_position.<locals>.<listcomp>ri   r   r^   N)
r   rb   ÚrangeÚlenZleavesZtreepositionsrc   r   rd   r   )r   Ztree_positionsÚpositionZnode_idrd   r   )r|   rf   r   Útest_node_tree_position>  s    

z-TestSequenceFunctions.test_node_tree_positionc                 C   sL   t  d¡}|  tt d|g¡ƒddgg¡ |  tt d|gd¡ƒg g¡ dS )zS
        Test node name matching with the search_leaves flag set to False.
        ú(S (A (T x)) (B (N x)))ry   ©r   r   r   ©r^   r   r   FNrj   re   r   r   r   Útest_node_noleavesL  s
    
ÿz(TestSequenceFunctions.test_node_noleavesc                 C   sø  t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒdgg¡ |  tt d	|g¡ƒd
gg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒdd
gg¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒg d¢g¡ t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒdgg¡ t  d ¡}|  tt d!|g¡ƒdgg¡ |  tt d"|g¡ƒg d#¢g¡ t  d$¡}|  tt d%|g¡ƒg d&¢g¡ |  tt d'|g¡ƒg d(¢g¡ d)S )*zC
        Test matching nodes based on dominance relations.
        r‚   z* < Tro   z	* < T > Sz* !< T)r   ©r   r   rƒ   rn   ©r^   r   r„   z
* !< T > Srn   z* > Ar†   z* > Br‡   z* !> B)r   ro   r†   rƒ   rn   r„   z* !> B >> S)ro   r†   rn   z* >> S)ro   r†   rn   r‡   z* >>, Sz* >>' Sz* << Tr   z* <<' Tz* <<1 Nz* !<< T)r†   rƒ   rn   r‡   r„   z(S (A (T x)) (B (T x) (N x )))z* <: Tz* !<: T)r   r†   rƒ   rn   r‡   r„   )r^   r^   )r^   r^   r   z* !<: T > Sz(S (T (A x) (B x)) (T (C x)))z* >: Tz* !>: T)r   ro   r†   rƒ   r`   ©r   r^   r   rn   r„   z=(S (A (B (C (D (E (T x)))))) (A (B (C (D (E (T x))) (N x)))))z* <<: T)ro   r†   rƒ   ©r   r   r   r   ©r   r   r   r   r   ©r^   r   r   r   )r^   r   r   r   r   z* >>: A)r†   rƒ   r‰   rŠ   )r   r   r   r   r   r   r‡   r„   Nrj   re   r   r   r   Útests_rel_dominanceV  sz    
þþÿþÿÿ þ
 þ
þÿÿþÿþz)TestSequenceFunctions.tests_rel_dominancec                 C   s(   t  d¡}|  tjtt d|g¡¡ dS )zC
        Test error handling of undefined tgrep operators.
        r‚   z* >>> SN)r   rb   ÚassertRaisesr   ÚTgrepExceptionrc   rd   re   r   r   r   Útest_bad_operator­  s    
ÿz'TestSequenceFunctions.test_bad_operatorc                 C   sV   t  d¡}d}|  tt ||g¡ƒddgg¡ d}|  tt ||g¡ƒddgg¡ dS )z`
        Test that comments are correctly filtered out of tgrep search
        strings.
        z(S (NN x) (NP x) (NN x))z=
        @ NP /^NP/;
        @ NN /^NN/;
        @NN
        ro   rq   zg
        # macros
        @ NP /^NP/;
        @ NN /^NN/;

        # search string
        @NN
        Nrj   )r   rf   Zsearch1Zsearch2r   r   r   Útest_comments¶  s
    
 z#TestSequenceFunctions.test_commentsc                 C   s¦   t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒddgg¡ d	S )
z7
        Test matching sister nodes in a tree.
        ú(S (A x) (B x) (C x))z* $. Bro   z* $.. Bz* $, Brq   z* $,, Bz* $ BNrj   re   r   r   r   Útest_rel_sister_nodesÌ  s    
z+TestSequenceFunctions.test_rel_sister_nodesc                 C   sø  t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d	|g¡ƒdgg¡ |  tt d
|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ dS )zP
        Test matching nodes based on their index in their parent node.
        r‘   z* >, Sro   z* >1 Sz* >2 Srn   z* >3 Srq   z* >' Sz* >-1 Sz* >-2 Sz* >-3 SzE(S (D (A x) (B x) (C x)) (E (B x) (C x) (A x)) (F (C x) (A x) (B x)))z* <, Az* <1 Az* <2 Az* <3 Az* <' Az* <-1 Az* <-2 Az* <-3 ANrj   re   r   r   r   Útests_rel_indexed_children×  s(    
ÿz0TestSequenceFunctions.tests_rel_indexed_childrenc                 C   s  t  d¡}|  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒg d¢g¡ |  tt d	|g¡ƒg d
¢g¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒg d¢g¡ |  tt d|g¡ƒg d¢g¡ dS )zD
        Test matching nodes based on precedence relations.
        zV(S (NP (NP (PP x)) (NP (AP x))) (VP (AP (X (PP x)) (Y (AP x)))) (NP (RC (NP (AP x)))))z* . X)ro   r`   rˆ   z* . Yr„   r‹   z* .. X)ro   r†   rƒ   r`   rˆ   z* .. Y)ro   r†   rƒ   r`   rˆ   r„   r‹   z* , X©r^   r   r^   ©r^   r   r^   r   z* , Y)rq   ©r\   r   ©r\   r   r   ©r\   r   r   r   z* ,, X)r”   r•   rq   r–   r—   r˜   z* ,, YNrj   re   r   r   r   Útest_rel_precedenceð  s@    ÿÿÿþþÿþþþz)TestSequenceFunctions.test_rel_precedencec                 C   sf  t  d¡}|  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒddgg¡ t  d	¡}|  tt d
|g¡ƒddgg¡ t  d¡}|  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒdgg¡ t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒdgg¡ dS )zA
        Test the Basic Examples from the TGrep2 manual.
        z(S (NP (AP x)) (NP (PP x)))r=   rn   z$(S (NP x) (VP x) (NP (PP x)) (VP x))rA   rq   z6(S (NP (AP x)) (NP (PP x)) (NP (DET x) (NN x)) (VP x))rC   zX(S (NP (NP (PP x)) (NP (AP x))) (VP (AP (NP (PP x)) (NP (AP x)))) (NP (RC (NP (AP x)))))rD   r`   r”   z:(S (NP (AP (PP x) (VP x))) (NP (AP (PP x) (NP x))) (NP x))rE   ro   ze(S (NP (DET a) (NN cat) (PP (IN on) (NP x))) (NP (DET a) (NN cat) (PP (IN on) (NP x)) (PP x)) (NP x))rF   z;(S (S (C x) (A (B x))) (S (C x) (A x)) (S (D x) (A (B x))))rI   z/(S (S (A (B x) (C x))) (S (S (C x) (A (B x)))))rK   rL   Nrj   re   r   r   r   Útest_examples  sX    

ÿÿÿþÿÿÿÿÿÿÿÿÿz#TestSequenceFunctions.test_examplesc                 C   sH   t  d¡}|  tt d|g¡ƒddgg¡ |  tjtt d|g¡¡ dS )z8
        Test defining and using tgrep2 macros.
        zi(VP (VB sold) (NP (DET the) (NN heiress)) (NP (NN deed) (PREP to) (NP (DET the) (NN school) (NN house))))z+@ NP /^NP/;
@ NN /^NN/;
@NP !< @NP !$.. @NNrn   )r\   r\   z,@ NP /^NP/;
@ NN /^NN/;
@CNP !< @NP !$.. @NNN)r   rb   r   rc   r   rd   r�   rŽ   re   r   r   r   Útest_use_macrosf  s$    ÿÿÿú	ÿýz%TestSequenceFunctions.test_use_macrosc                 C   s0   |   t d¡g d¢¡ |   t d¡g d¢¡ dS )z#Test tokenization of labeled nodes.ú!S < @SBJ < (@VP < (@VB $.. @OBJ)))rJ   r   ú@SBJr   r   ú@VPr   r   ú@VBr:   ú@OBJr   r   z%S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)))rJ   r   r�   ú=Úsr   r   rž   r¡   Úvr   r   rŸ   r:   r    r   r   Nr    r!   r   r   r   Útest_tokenize_node_labels€  s    þþz/TestSequenceFunctions.test_tokenize_node_labelsc                 C   s   |   t d¡g d¢¡ dS )z(Test tokenization of segmented patterns.z0S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v)rJ   r   r�   r¡   r¢   r   r   rž   r¡   r£   r   r   rŸ   r:   r    r   r   ú:z=sr   z=vNr    r!   r   r   r   Ú test_tokenize_segmented_patterns«  s    þz6TestSequenceFunctions.test_tokenize_segmented_patternsc                 C   s*  d}t  d¡}t  d¡}| d¡d d }d}|  tt ||g¡ƒd ¡ |  tt ||g¡ƒd ¡ |  tt ||g¡ƒd ¡ |  tt ||g¡ƒtt ||g¡ƒ¡ |  tt ||g¡ƒd ¡ |  tt ||g¡ƒd ¡ |  tt ||g¡ƒd ¡ |  tt ||g¡ƒtt ||g¡ƒ¡ dS )	zN
        Test labeled nodes.

        Test case from Emily M. Bender.
        zã
            # macros
            @ SBJ /SBJ/;
            @ VP /VP/;
            @ VB /VB/;
            @ VPoB /V[PB]/;
            @ OBJ /OBJ/;

            # 1 svo
            S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =vz2(S (NP-SBJ I) (VP (VB eat) (NP-OBJ (NNS apples))))z2(S (VP (VB eat) (NP-OBJ (NNS apples))) (NP-SBJ I))z

r   rœ   z-S < (/.*SBJ/ $.. (/VP/ < (/VB/ $.. /.*OBJ/)))N)	r   rb   ÚsplitÚ
assertTruerc   r   rd   r   ZassertFalse)r   ÚsearchZsent1Zsent2Zsearch_firsthalfZsearch_rewriter   r   r   Útest_labeled_nodesÈ  s.    
ÿÿþþz(TestSequenceFunctions.test_labeled_nodesc                 C   sL   t  d¡}|  tt d|g¡ƒdgg¡ |  tt d|g¡ƒddgg¡ dS )zm
        Test that multiple (3 or more) conjunctions of node relations are
        handled properly.
        z'((A (B b) (C c)) (A (B b) (C c) (D d)))z(A < B < C < D)rn   z(A < B < C)ro   Nrj   )r   Úsentr   r   r   Útest_multiple_conjsð  s    
ÿÿz)TestSequenceFunctions.test_multiple_conjsc                 C   sn   t  d¡}|  tt d|g¡ƒddgg¡ |  tt d|g¡ƒddgg¡ |  tt d|g¡ƒddgg¡ dS )zp
        Test that semicolons at the end of a tgrep2 search string won't
        cause a parse failure.
        rZ   rW   r[   r]   zNN;zNN;;Nrj   re   r   r   r   Útest_trailing_semicolonÿ  s    ÿ  ÿz-TestSequenceFunctions.test_trailing_semicolonN)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r<   rN   rO   rT   rY   rg   rk   rl   rp   rr   ru   rv   r�   r…   rŒ   r�   r�   r’   r“   r™   rš   r›   r¤   r¦   rª   r¬   r­   r   r   r   r   r      s<   !	C&	 
	
W	'O+(r   )r±   ZunittestZnltkr   Z	nltk.treer   ZTestCaser   r   r   r   r   Ú<module>
   s   