#NEWLINE# def test_labeled_nodes( self ) : #NEWLINE# #INDENT# '\n        Test labeled nodes.\n\n        Test case from Emily M. Bender.\n        ' #NEWLINE# search = '\n            # macros\n            @ SBJ /SBJ/;\n            @ VP /VP/;\n            @ VB /VB/;\n            @ VPoB /V[PB]/;\n            @ OBJ /OBJ/;\n\n            # 1 svo\n            S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v' #NEWLINE# sent1 = ParentedTree . fromstring ( '(S (NP-SBJ I) (VP (VB eat) (NP-OBJ (NNS apples))))' ) #NEWLINE# sent2 = ParentedTree . fromstring ( '(S (VP (VB eat) (NP-OBJ (NNS apples))) (NP-SBJ I))' ) #NEWLINE# search_firsthalf = ( search . split ( '\n\n' ) [ 0 ] + 'S < @SBJ < (@VP < (@VB $.. @OBJ))' ) #NEWLINE# search_rewrite = 'S < (/.*SBJ/ $.. (/VP/ < (/VB/ $.. /.*OBJ/)))' #NEWLINE# self . assertTrue ( list ( tgrep . tgrep_positions ( search_firsthalf , [ sent1 ] ) ) [ 0 ] ) #NEWLINE# self . assertTrue ( list ( tgrep . tgrep_positions ( search , [ sent1 ] ) ) [ 0 ] ) #NEWLINE# self . assertTrue ( list ( tgrep . tgrep_positions ( search_rewrite , [ sent1 ] ) ) [ 0 ] ) #NEWLINE# self . assertEqual ( list ( tgrep . tgrep_positions ( search , [ sent1 ] ) ) , list ( tgrep . tgrep_positions ( search_rewrite , [ sent1 ] ) ) ) #NEWLINE# self . assertTrue ( list ( tgrep . tgrep_positions ( search_firsthalf , [ sent2 ] ) ) [ 0 ] ) #NEWLINE# self . assertFalse ( list ( tgrep . tgrep_positions ( search , [ sent2 ] ) ) [ 0 ] ) #NEWLINE# self . assertFalse ( list ( tgrep . tgrep_positions ( search_rewrite , [ sent2 ] ) ) [ 0 ] ) #NEWLINE# self . assertEqual ( list ( tgrep . tgrep_positions ( search , [ sent2 ] ) ) , list ( tgrep . tgrep_positions ( search_rewrite , [ sent2 ] ) ) )