
    /hx                     R    S r SSKrSSKJr  SSKJr   " S S\R                  5      rg)z
Unit tests for nltk.tgrep.
    N)tgrep)ParentedTreec                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"g!)"TestSequenceFunctions   z-
Class containing unit tests for nltk.tgrep.
c                 X    [         R                  " S5      nU R                  U/ SQ5        g)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tokenss     Q/var/www/auris/envauris/lib/python3.13/site-packages/nltk/test/unit/test_tgrep.pytest_tokenize_simple*TestSequenceFunctions.test_tokenize_simple   s+     %%&MN	
    c                 x    U R                  [        R                  " S5      [        R                  " S5      5        g)z=
Test that tokenization handles bytes and strs the same way.
s%   A .. (B !< C . D) | ![<< (E , F) $ G]r	   Nr   r   r   r   s    r!   test_tokenize_encoding,TestSequenceFunctions.test_tokenize_encoding;   s0     	  !IJ  !HI	
r$   c                 d   U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S	5      / S
Q5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / S Q5        U R                  [        R                  " S!5      / S"Q5        U R                  [        R                  " S#5      / S$Q5        U R                  [        R                  " S%5      / S&Q5        U R                  [        R                  " S'5      / S(Q5        U R                  [        R                  " S)5      / S*Q5        U R                  [        R                  " S+5      / S,Q5        U R                  [        R                  " S-5      / S.Q5        U R                  [        R                  " S/5      / S0Q5        U R                  [        R                  " S15      / S2Q5        U R                  [        R                  " S35      / S4Q5        U R                  [        R                  " S55      / S6Q5        U R                  [        R                  " S75      / S8Q5        U R                  [        R                  " S95      / S:Q5        U R                  [        R                  " S;5      / S<Q5        U R                  [        R                  " S=5      / S>Q5        U R                  [        R                  " S?5      / S@Q5        U R                  [        R                  " SA5      / SBQ5        U R                  [        R                  " SC5      / SDQ5        U R                  [        R                  " SE5      / SFQ5        U R                  [        R                  " SG5      / SHQ5        U R                  [        R                  " SI5      / SJQ5        U R                  [        R                  " SK5      / SLQ5        U R                  [        R                  " SM5      / SNQ5        U R                  [        R                  " SO5      / SPQ5        U R                  [        R                  " SQ5      / SRQ5        U R                  [        R                  " SS5      / STQ5        U R                  [        R                  " SU5      / SVQ5        U R                  [        R                  " SW5      / SXQ5        U R                  [        R                  " SY5      / SZQ5        U R                  [        R                  " S[5      / S\Q5        U R                  [        R                  " S]5      / S^Q5        U R                  [        R                  " S_5      / S`Q5        U R                  [        R                  " Sa5      / SbQ5        U R                  [        R                  " Sc5      / SdQ5        U R                  [        R                  " Se5      / SfQ5        U R                  [        R                  " Sg5      / ShQ5        U R                  [        R                  " Si5      / SjQ5        U R                  [        R                  " Sk5      / SlQ5        U R                  [        R                  " Sm5      / SnQ5        U R                  [        R                  " So5      / SpQ5        U R                  [        R                  " Sq5      / SrQ5        U R                  [        R                  " Ss5      / StQ5        U R                  [        R                  " Su5      / SvQ5        U R                  [        R                  " Sw5      / SxQ5        U R                  [        R                  " Sy5      / SzQ5        U R                  [        R                  " S{5      / S|Q5        g})~z(
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   r0   r   zA!>-3B)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   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   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   r   r   zA!$.B)r
   r   r@   r   zA!$,B)r
   r   rA   r   zA!$..B)r
   r   rB   r   zA!$,,B)r
   r   rC   r   Nr&   r'   s    r!   test_tokenize_link_types.TestSequenceFunctions.test_tokenize_link_typesD   s    	--e4oF--e4oF--f57GH--f57GH--f57GH--f57GH--g68IJ--g68IJ--f57GH--f57GH--f57GH--f57GH--f57GH--f57GH--f57GH--f57GH--g68IJ--g68IJ--g68IJ--g68IJ--g68IJ--g68IJ--e4oF--e4oF--f57GH--f57GH--e4oF--f57GH--f57GH--g68IJ--g68IJ--f57KL--f57KL--g68MN--g68MN--g68MN--g68MN--h79OP--h79OP--g68MN--g68MN--g68MN--g68MN--g68MN--g68MN--g68MN--g68MN--h79OP--h79OP--h79OP--h79OP--h79OP--h79OP--f57KL--f57KL--g68MN--g68MN--f57KL--g68MN--g68MN--h79OP--h79OPr$   c                 r   U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      S/5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / S	Q5        U R                  [        R                  " S
5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        g)z:
Test tokenization of the TGrep2 manual example patterns.
NP < PP)NPr   PP/^NP/NP << PP . VP)rH   r   rI   r   VPNP << PP | . VP)rH   r   rI   r   r   rL   NP !<< PP [> NP | >> VP])rH   r   r   rI   r   r+   rH   r   r8   rL   r   NP << (PP . VP))rH   r   r   rI   r   rL   r   NP <' (PP <, (IN < on)))rH   r4   r   rI   r.   r   INr   onr   r   S < (A < B) < C)	Sr   r   r
   r   r   r   r   r   S < ((A < B) < C))rT   r   r   r   r
   r   r   r   r   r   r   S < (A < B < C))	rT   r   r   r
   r   r   r   r   r   zA<B&.C)r
   r   r   &r   r   Nr&   r'   s    r!   test_tokenize_examples,TestSequenceFunctions.test_tokenize_examples   sh    	--i8:KL--g6	B  13P	
 	  !235W	
 	  !;<I	
 	  !233	
 	  !:;I	
 	  !239	
 	  !45C	
 	  !239	
 	--h79WXr$   c                 T    U R                  [        R                  " S5      / SQ5        g)z
Test tokenization of quoting.
z"A<<:B"<<:"A $.. B"<"A>3B"<C)z"A<<:B"r=   z	"A $.. B"r   z"A>3B"r   r   Nr&   r'   s    r!   test_tokenize_quoting+TestSequenceFunctions.test_tokenize_quoting   s$     	  !?@D	
r$   c                 |   U R                  [        R                  " S5      S/5        U R                  [        R                  " S5      S/5        U R                  [        R                  " S5      S/5        U R                  [        R                  " S5      S/5        U R                  [        R                  " S5      SS/5        U R                  [        R                  " S5      / S	Q5        U R                  [        R                  " S
5      / SQ5        U R                  [        R                  " S5      / SQ5        g)z"
Test tokenization of node names.
Robertz	/^[Bb]ob/*__zN()N(r   zN(0,))ra   0r   r   zN(0,0))ra   rb   r   rb   r   zN(0,0,))ra   rb   r   rb   r   r   Nr&   r'   s    r!   test_tokenize_nodenames-TestSequenceFunctions.test_tokenize_nodenames   s     	--h7(D--k:[MJ--c2SE:--d3dV<--e4tSkB--g68MN--h79ST  +-L	
r$   c                 T    U R                  [        R                  " S5      / SQ5        g)z)
Test tokenization of macro definitions.
z4@ NP /^NP/;
@ NN /^NN/;
@NP [!< NP | < @NN] !$.. @NN)@rH   rJ   ;rf   NNz/^NN/rg   z@NPr   r   r   rH   r   r   @NNr   r   rB   ri   Nr&   r'   s    r!   test_tokenize_macros*TestSequenceFunctions.test_tokenize_macros   s(     	  H		
r$   c                 t   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R                  " SU/5      5      US   US   //5        U R                  [        [        R
                  " SU/5      5      / SQ/5        g)zH
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)))rh   r      ro      NN|JJ)r   rq   rn   rp   Nr   
fromstringr   listr   tgrep_positionstgrep_nodesr   trees     r!   test_node_simple&TestSequenceFunctions.test_node_simple   s    
 &&R
 	e33D4&ABffEUDVW""4$01T$Zd4L3M	
 	&&w78;S:T	
r$   c           	      p   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      [        [        R
                  " SU/5      5      5        U R                  [        [        R
                  " SU/5      5      [        [        R
                  " SU/5      5      5        g)z9Test that the tgrep print operator ' is properly ignored.(S (n x) (N x))Nz'Nz/[Nn]/z'/[Nn]/Nr   ru   r   rv   r   rw   ry   s     r!   test_node_printing(TestSequenceFunctions.test_node_printing   s    &&'89&&sTF34&&tdV45	
 	&&x$89&&y4&9:	
r$   c           	         [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      [        [        R
                  " SU/5      5      5        U R                  [        [        R                  " SU/5      5      [        [        R                  " SU/5      5      5        U R                  [        [        R
                  " SU/5      5      [        [        R
                  " SU/5      5      5        g)zE
Test that tgrep search strings handles bytes and strs the same
way.
rm   s   NNrh   s   NN|JJrr   Nrt   ry   s     r!   test_node_encoding(TestSequenceFunctions.test_node_encoding  s    
 &&R
 	&&utf56&&utf56	
 	""54&12""4$01	
 	&&x$89&&w78	
r$   c                     [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      SS//5        g)z9
Test selecting nodes using case insensitive node names.
r~   "N"rq   zi@"N"r   Nr   ry   s     r!   test_node_nocase&TestSequenceFunctions.test_node_nocase  sg     &&'89e33ED6BCtfXNe33GdVDEt~Vr$   c                    [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S	//5        g
)z/
Test selecting nodes using quoted node names.
z(N ("N" x) (N" x) ("\" x))r    z"\"N\""r   z"N\""r   z"\"\\\""ro   Nr   ry   s     r!   test_node_quoted&TestSequenceFunctions.test_node_quoted  s     &&'DEe33ED6BCrdVLe33K$HITF8Te33HtfEF$Qe33NTFKLPTvhWr$   c                     [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        g)
Test regex matching on nodes.
$(S (NP-SBJ x) (NP x) (NNP x) (VP x))rJ   r   r   Nr   ry   s     r!   test_node_regex%TestSequenceFunctions.test_node_regex)  sA     &&'MN 	e33GdVDEt~Vr$   c                     [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        g)r   z(S (SBJ x) (SBJ1 x) (NP-SBJ x))z/^SBJ/r   r   z/SBJ/)r   r   r   Nr   ry   s     r!   test_node_regex_2'TestSequenceFunctions.test_node_regex_22  sm     &&'HIe33HtfEF$PTW 	&&w78;M:N	
r$   c                    [         R                  " S5      n[        [        UR	                  5       5      5       Vs1 s H  o!R                  U5      iM     nnUR                  5        Vs/ s H  o"U;  d  M
  UPM     nnU H^  nSU 3n[        [        R                  " Xa/5      5      nU R                  [        US   5      S5        U R                  US   S   U5        M`     gs  snf s  snf )z5
Test matching on nodes based on NLTK tree position.
r   r   r   rq   N)r   ru   rangelenleavesleaf_treepositiontreepositionsrv   r   rw   r   )r   rz   xleaf_positionstree_positionspositionnode_idrw   s           r!   test_node_tree_position-TestSequenceFunctions.test_node_tree_position>  s     &&'MN=B3t{{}CU=VW=V003=VW%)%7%7%9U%9n=T!%9U&H(nG"5#8#8&#IJOS!34a8_Q/2H=	 ' XUs   C#)	C(6C(c           	          [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/S5      5      / /5        g)zC
Test node name matching with the search_leaves flag set to False.
(S (A (T x)) (B (N x)))r   r   r   r   rq   r   r   FNr   ry   s     r!   test_node_noleaves(TestSequenceFunctions.test_node_noleavesL  sn     &&'@A&&sTF34	97M6N	
 	e33C$GH2$Or$   c                 	   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " S	U/5      5      S
//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      SS
//5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S 5      nU R                  [        [        R
                  " S!U/5      5      S//5        U R                  [        [        R
                  " S"U/5      5      / S#Q/5        [         R                  " S$5      nU R                  [        [        R
                  " S%U/5      5      / S&Q/5        U R                  [        [        R
                  " S'U/5      5      / S(Q/5        g))*z3
Test matching nodes based on dominance relations.
r   z* < Tr   z	* < T > Sz* !< T)r   r   r   r   r   rq   r   r   z
* !< T > Sr   z* > Ar   z* > Br   z* !> B)r   r   r   r   r   r   z* !> B >> S)r   r   r   z* >> S)r   r   r   r   z* >>, Sz* >>' Sz* << Tr   z* <<' Tz* <<1 Nz* !<< T)r   r   r   r   r   z(S (A (T x)) (B (T x) (N x )))z* <: Tz* !<: T)r   r   r   r   r   r   )rq   rq   )rq   rq   r   z* !<: T > Sz(S (T (A x) (B x)) (T (C x)))z* >: Tz* !>: T)r   r   r   r   rs   r   rq   r   r   r   z=(S (A (B (C (D (E (T x)))))) (A (B (C (D (E (T x))) (N x)))))z* <<: T)r   r   r   r   r   r   r   r   r   r   r   r   rq   r   r   r   )rq   r   r   r   r   z* >>: A)r   r   r   r   )r   r   r   r   r   r   r   r   Nr   ry   s     r!   tests_rel_dominance)TestSequenceFunctions.tests_rel_dominanceV  s+    &&'@Ae33GdVDExPe33K$HITF8T&&x$89=>	
 	e33L4&IJdVHUe33GdVDEzRe33GdVDEzR&&x$89;<	
 	&&}tf=>AU@V	
 	&&x$89)*	
 	&&y4&9:dF^<L	
 	&&y4&9:dF^<L	
 	e33HtfEF"dUe33IvFG4&Re33IvFG4&R&&y4&9:9:	
 &&'GHe33HtfEF$Qe33GdVDEt~V&&y4&9:PQ	
 	e33MD6JKtfXV&&'FGe33HtfEF&
S&&y4&9:NO	
 &&N
 	&&y4&9:
	
 	&&y4&9:
	
r$   c                     [         R                  " S5      nU R                  [        R                  [
        [        R                  " SU/5      5        g)z3
Test error handling of undefined tgrep operators.
r   z* >>> SN)r   ru   assertRaisesr   TgrepExceptionrv   rw   ry   s     r!   test_bad_operator'TestSequenceFunctions.test_bad_operator  s?     &&'@A  $(=(=i$(P	
r$   c                    [         R                  " S5      nSnU R                  [        [        R
                  " X!/5      5      SS//5        SnU R                  [        [        R
                  " X1/5      5      SS//5        g)zH
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
        r   r   zg
        # macros
        @ NP /^NP/;
        @ NN /^NN/;

        # search string
        @NN
        Nr   )r   rz   search1search2s       r!   test_comments#TestSequenceFunctions.test_comments  sw    
 &&'AB
 	e33GVDEt~V 	e33GVDEt~Vr$   c                 0   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      SS//5        g	)
z'
Test matching sister nodes in a tree.
(S (A x) (B x) (C x))z* $. Br   z* $.. Bz* $, Br   z* $,, Bz* $ BNr   ry   s     r!   test_rel_sister_nodes+TestSequenceFunctions.test_rel_sister_nodes  s     &&'>?e33HtfEF$Qe33IvFG4&Re33HtfEF$Qe33IvFG4&Re33GdVDEt~Vr$   c                    [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " S	U/5      5      S//5        U R                  [        [        R
                  " S
U/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        g)z@
Test matching nodes based on their index in their parent node.
r   z* >, Sr   z* >1 Sz* >2 Sr   z* >3 Sr   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 ANr   ry   s     r!   tests_rel_indexed_children0TestSequenceFunctions.tests_rel_indexed_children  s    &&'>?e33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33IvFG4&Re33IvFG4&Re33IvFG4&R&&V
 	e33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33HtfEF$Qe33IvFG4&Re33IvFG4&Re33IvFG4&Rr$   c                 p   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " S	U/5      5      / S
Q/5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      / SQ/5        U R                  [        [        R
                  " SU/5      5      / SQ/5        g)z4
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)r   rs   r   z* . Yr   r   z* .. X)r   r   r   rs   r   z* .. Y)r   r   r   rs   r   r   r   z* , Xrq   r   rq   rq   r   rq   r   z* , Y)r   ro   r   ro   r   r   ro   r   r   r   z* ,, X)r   r   r   r   r   r   z* ,, YNr   ry   s     r!   test_rel_precedence)TestSequenceFunctions.test_rel_precedence  s    &&&

 	&&w78;T:U	
 	&&w78I|;T:U	
 	&&x$899:	
 	&&x$89RS	
 	&&w78I|;T:U	
 	&&w7845	
 	&&x$89MN	
 	&&x$8945	
r$   c                    [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        [         R                  " S	5      nU R                  [        [        R
                  " S
U/5      5      SS//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      S//5        g)z1
Test the Basic Examples from the TGrep2 manual.
z(S (NP (AP x)) (NP (PP x)))rG   r   z$(S (NP x) (VP x) (NP (PP x)) (VP x))rK   r   z6(S (NP (AP x)) (NP (PP x)) (NP (DET x) (NN x)) (VP x))rM   zX(S (NP (NP (PP x)) (NP (AP x))) (VP (AP (NP (PP x)) (NP (AP x)))) (NP (RC (NP (AP x)))))rN   rs   r   z:(S (NP (AP (PP x) (VP x))) (NP (AP (PP x) (NP x))) (NP x))rO   r   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))rP   z;(S (S (C x) (A (B x))) (S (C x) (A x)) (S (D x) (A (B x))))rS   z/(S (S (A (B x) (C x))) (S (S (C x) (A (B x)))))rU   rV   Nr   ry   s     r!   test_examples#TestSequenceFunctions.test_examples  sC    &&'DEe33IvFG4&R&&'MN 	e33OdVLMQUPVxX&&G

 	&&'84&ABdD\N	
 &&&
 	&&'AD6JKi !	

 &&K
 	&&'84&ABdVH	
 &&
 	&&'@4&IJdVH	
 &&L

 	&&'84&ABdVH	
 &&=

 	&&':TFCDvh	

 	&&'84&ABdVH	
r$   c                    [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        R                  [        [        R
                  " SU/5      5        g)z(
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 !$.. @NNr   )ro   ro   z,@ NP /^NP/;
@ NN /^NN/;
@CNP !< @NP !$.. @NNN)r   ru   r   rv   r   rw   r   r   ry   s     r!   test_use_macros%TestSequenceFunctions.test_use_macrosf  s     &&6

 	%%CdV
 F^	
 	  !!@4&	
r$   c                     U R                  [        R                  " S5      / SQ5        U R                  [        R                  " S5      / SQ5        g)z#Test tokenization of labeled nodes.!S < @SBJ < (@VP < (@VB $.. @OBJ)))rT   r   @SBJr   r   @VPr   r   @VBrB   @OBJr   r   z%S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)))rT   r   r   =sr   r   r   r   vr   r   r   rB   r   r   r   Nr&   r'   s    r!   test_tokenize_node_labels/TestSequenceFunctions.test_tokenize_node_labels  sH      !DE	
$ 	  !HI	
r$   c                 T    U R                  [        R                  " S5      / SQ5        g)z(Test tokenization of segmented patterns.z0S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v)rT   r   r   r   r   r   r   r   r   r   r   r   r   rB   r   r   r   :z=sr   z=vNr&   r'   s    r!    test_tokenize_segmented_patterns6TestSequenceFunctions.test_tokenize_segmented_patterns  s$      !ST	
r$   c           	      "   Sn[         R                  " S5      n[         R                  " S5      nUR                  S5      S   S-   nSnU R                  [	        [
        R                  " XB/5      5      S   5        U R                  [	        [
        R                  " X/5      5      S   5        U R                  [	        [
        R                  " XR/5      5      S   5        U R                  [	        [
        R                  " X/5      5      [	        [
        R                  " XR/5      5      5        U R                  [	        [
        R                  " XC/5      5      S   5        U R                  [	        [
        R                  " X/5      5      S   5        U R                  [	        [
        R                  " XS/5      5      S   5        U R                  [	        [
        R                  " X/5      5      [	        [
        R                  " XS/5      5      5        g)	z6
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   ru   split
assertTruerv   r   rw   r   assertFalse)r   searchsent1sent2search_firsthalfsearch_rewrites         r!   test_labeled_nodes(TestSequenceFunctions.test_labeled_nodes  s   	@ ''@
 ''@
 "<</25XXHU223CWMNqQRU2267CDQGHU22>7KLQOP&&vw78&&~w?@	
 	U223CWMNqQRe33FGDEaHIe33NGLMaPQ&&vw78&&~w?@	
r$   c                     [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      S//5        U R                  [        [        R
                  " SU/5      5      SS//5        g)zU
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)r   z(A < B < C)r   Nr   )r   sents     r!   test_multiple_conjs)TestSequenceFunctions.test_multiple_conjs  sr    
 &&'PQ 	&&'84&ABdVH	
 	&&}tf=>$	
r$   c                 h   [         R                  " S5      nU R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      SS//5        U R                  [        [        R
                  " SU/5      5      SS//5        g)zX
Test that semicolons at the end of a tgrep2 search string won't
cause a parse failure.
rm   rh   rn   rp   zNN;zNN;;Nr   ry   s     r!   test_trailing_semicolon-TestSequenceFunctions.test_trailing_semicolon  s    
 &&R
 	e33D4&ABffEUDVWe33ED6BCvvFVEWX&&vv6766:J9K	
r$   r   N)#__name__
__module____qualname____firstlineno____doc__r"   r(   rD   rX   r[   rc   rj   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r$   r!   r   r      s    
B
AQF$YL

 
@
 


*WXW

>PU
n
W,	WS2%
NM
^
4)
V
:&
P

r$   r   )r   unittestnltkr   	nltk.treer   TestCaser   r   r$   r!   <module>r      s)   
   "v
H-- v
r$   