def test_tokenize_encoding(self): ''' Test that tokenization handles bytes and strs the same way. ''' self.assertEqual( tgrep.tgrep_tokenize(b('A .. (B !< C . D) | ![<< (E , F) $ G]')), tgrep.tgrep_tokenize('A .. (B !< C . D) | ![<< (E , F) $ G]'))
def test_tokenize_encoding(self): """ Test that tokenization handles bytes and strs the same way. """ self.assertEqual( tgrep.tgrep_tokenize(b"A .. (B !< C . D) | ![<< (E , F) $ G]"), tgrep.tgrep_tokenize("A .. (B !< C . D) | ![<< (E , F) $ G]"), )
def test_tokenize_node_labels(self): '''Test tokenization of labeled nodes.''' self.assertEqual(tgrep.tgrep_tokenize( 'S < @SBJ < (@VP < (@VB $.. @OBJ))'), ['S', '<', '@SBJ', '<', '(', '@VP', '<', '(', '@VB', '$..', '@OBJ', ')', ')']) self.assertEqual(tgrep.tgrep_tokenize( 'S < @SBJ=s < (@VP=v < (@VB $.. @OBJ))'), ['S', '<', '@SBJ', '=', 's', '<', '(', '@VP', '=', 'v', '<', '(', '@VB', '$..', '@OBJ', ')', ')'])
def test_tokenize_macros(self): ''' Test tokenization of macro definitions. ''' self.assertEqual( tgrep.tgrep_tokenize( '@ NP /^NP/;\n@ NN /^NN/;\n@NP [!< NP | < @NN] !$.. @NN' ), [ '@', 'NP', '/^NP/', ';', '@', 'NN', '/^NN/', ';', '@NP', '[', '!', '<', 'NP', '|', '<', '@NN', ']', '!', '$..', '@NN', ], )
def test_tokenize_simple(self): ''' Simple test of tokenization. ''' tokens = tgrep.tgrep_tokenize('A .. (B !< C . D) | ![<< (E , F) $ G]') self.assertEqual( tokens, [ 'A', '..', '(', 'B', '!', '<', 'C', '.', 'D', ')', '|', '!', '[', '<<', '(', 'E', ',', 'F', ')', '$', 'G', ']', ], )
def test_tokenize_segmented_patterns(self): """Test tokenization of segmented patterns.""" self.assertEqual( tgrep.tgrep_tokenize( "S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v"), [ "S", "<", "@SBJ", "=", "s", "<", "(", "@VP", "=", "v", "<", "(", "@VB", "$..", "@OBJ", ")", ")", ":", "=s", "..", "=v", ], )
def test_tokenize_quoting(self): ''' Test tokenization of quoting. ''' self.assertEqual( tgrep.tgrep_tokenize('"A<<:B"<<:"A $.. B"<"A>3B"<C'), ['"A<<:B"', '<<:', '"A $.. B"', '<', '"A>3B"', '<', 'C'])
def test_tokenize_simple(self): """ Simple test of tokenization. """ tokens = tgrep.tgrep_tokenize("A .. (B !< C . D) | ![<< (E , F) $ G]") self.assertEqual( tokens, [ "A", "..", "(", "B", "!", "<", "C", ".", "D", ")", "|", "!", "[", "<<", "(", "E", ",", "F", ")", "$", "G", "]", ], )
def test_tokenize_macros(self): """ Test tokenization of macro definitions. """ self.assertEqual( tgrep.tgrep_tokenize( "@ NP /^NP/;\n@ NN /^NN/;\n@NP [!< NP | < @NN] !$.. @NN"), [ "@", "NP", "/^NP/", ";", "@", "NN", "/^NN/", ";", "@NP", "[", "!", "<", "NP", "|", "<", "@NN", "]", "!", "$..", "@NN", ], )
def test_tokenize_segmented_patterns(self): '''Test tokenization of segmented patterns.''' self.assertEqual(tgrep.tgrep_tokenize( 'S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v'), ['S', '<', '@SBJ', '=', 's', '<', '(', '@VP', '=', 'v', '<', '(', '@VB', '$..', '@OBJ', ')', ')', ':', '=s', '..', '=v'])
def test_tokenize_segmented_patterns(self): '''Test tokenization of segmented patterns.''' self.assertEqual( tgrep.tgrep_tokenize('S < @SBJ=s < (@VP=v < (@VB $.. @OBJ)) : =s .. =v'), [ 'S', '<', '@SBJ', '=', 's', '<', '(', '@VP', '=', 'v', '<', '(', '@VB', '$..', '@OBJ', ')', ')', ':', '=s', '..', '=v', ], )
def test_tokenize_quoting(self): ''' Test tokenization of quoting. ''' self.assertEqual(tgrep.tgrep_tokenize('"A<<:B"<<:"A $.. B"<"A>3B"<C'), ['"A<<:B"', '<<:', '"A $.. B"', '<', '"A>3B"', '<', 'C'])
def test_tokenize_quoting(self): """ Test tokenization of quoting. """ self.assertEqual( tgrep.tgrep_tokenize('"A<<:B"<<:"A $.. B"<"A>3B"<C'), ['"A<<:B"', "<<:", '"A $.. B"', "<", '"A>3B"', "<", "C"], )
def test_tokenize_node_labels(self): """Test tokenization of labeled nodes.""" self.assertEqual( tgrep.tgrep_tokenize("S < @SBJ < (@VP < (@VB $.. @OBJ))"), [ "S", "<", "@SBJ", "<", "(", "@VP", "<", "(", "@VB", "$..", "@OBJ", ")", ")", ], ) self.assertEqual( tgrep.tgrep_tokenize("S < @SBJ=s < (@VP=v < (@VB $.. @OBJ))"), [ "S", "<", "@SBJ", "=", "s", "<", "(", "@VP", "=", "v", "<", "(", "@VB", "$..", "@OBJ", ")", ")", ], )
def test_tokenize_nodenames(self): ''' Test tokenization of node names. ''' self.assertEqual(tgrep.tgrep_tokenize('Robert'), ['Robert']) self.assertEqual(tgrep.tgrep_tokenize('/^[Bb]ob/'), ['/^[Bb]ob/']) self.assertEqual(tgrep.tgrep_tokenize('*'), ['*']) self.assertEqual(tgrep.tgrep_tokenize('__'), ['__']) # test tokenization of NLTK tree position syntax self.assertEqual(tgrep.tgrep_tokenize('N()'), ['N(', ')']) self.assertEqual(tgrep.tgrep_tokenize('N(0,)'), ['N(', '0', ',', ')']) self.assertEqual(tgrep.tgrep_tokenize('N(0,0)'), ['N(', '0', ',', '0', ')']) self.assertEqual( tgrep.tgrep_tokenize('N(0,0,)'), ['N(', '0', ',', '0', ',', ')'] )
def test_tokenize_nodenames(self): """ Test tokenization of node names. """ self.assertEqual(tgrep.tgrep_tokenize("Robert"), ["Robert"]) self.assertEqual(tgrep.tgrep_tokenize("/^[Bb]ob/"), ["/^[Bb]ob/"]) self.assertEqual(tgrep.tgrep_tokenize("*"), ["*"]) self.assertEqual(tgrep.tgrep_tokenize("__"), ["__"]) # test tokenization of NLTK tree position syntax self.assertEqual(tgrep.tgrep_tokenize("N()"), ["N(", ")"]) self.assertEqual(tgrep.tgrep_tokenize("N(0,)"), ["N(", "0", ",", ")"]) self.assertEqual(tgrep.tgrep_tokenize("N(0,0)"), ["N(", "0", ",", "0", ")"]) self.assertEqual(tgrep.tgrep_tokenize("N(0,0,)"), ["N(", "0", ",", "0", ",", ")"])
def test_tokenize_nodenames(self): ''' Test tokenization of node names. ''' self.assertEqual(tgrep.tgrep_tokenize('Robert'), ['Robert']) self.assertEqual(tgrep.tgrep_tokenize('/^[Bb]ob/'), ['/^[Bb]ob/']) self.assertEqual(tgrep.tgrep_tokenize('*'), ['*']) self.assertEqual(tgrep.tgrep_tokenize('__'), ['__']) # test tokenization of NLTK tree position syntax self.assertEqual(tgrep.tgrep_tokenize('N()'), ['N(', ')']) self.assertEqual(tgrep.tgrep_tokenize('N(0,)'), ['N(', '0', ',', ')']) self.assertEqual(tgrep.tgrep_tokenize('N(0,0)'), ['N(', '0', ',', '0', ')']) self.assertEqual(tgrep.tgrep_tokenize('N(0,0,)'), ['N(', '0', ',', '0', ',', ')'])
def test_tokenize_examples(self): ''' Test tokenization of the TGrep2 manual example patterns. ''' self.assertEqual(tgrep.tgrep_tokenize('NP < PP'), ['NP', '<', 'PP']) self.assertEqual(tgrep.tgrep_tokenize('/^NP/'), ['/^NP/']) self.assertEqual(tgrep.tgrep_tokenize('NP << PP . VP'), ['NP', '<<', 'PP', '.', 'VP']) self.assertEqual(tgrep.tgrep_tokenize('NP << PP | . VP'), ['NP', '<<', 'PP', '|', '.', 'VP']) self.assertEqual(tgrep.tgrep_tokenize('NP !<< PP [> NP | >> VP]'), ['NP', '!', '<<', 'PP', '[', '>', 'NP', '|', '>>', 'VP', ']']) self.assertEqual(tgrep.tgrep_tokenize('NP << (PP . VP)'), ['NP', '<<', '(', 'PP', '.', 'VP', ')']) self.assertEqual(tgrep.tgrep_tokenize('NP <\' (PP <, (IN < on))'), ['NP', '<\'', '(', 'PP', '<,', '(', 'IN', '<', 'on', ')', ')']) self.assertEqual(tgrep.tgrep_tokenize('S < (A < B) < C'), ['S', '<', '(', 'A', '<', 'B', ')', '<', 'C']) self.assertEqual(tgrep.tgrep_tokenize('S < ((A < B) < C)'), ['S', '<', '(', '(', 'A', '<', 'B', ')', '<', 'C', ')']) self.assertEqual(tgrep.tgrep_tokenize('S < (A < B < C)'), ['S', '<', '(', 'A', '<', 'B', '<', 'C', ')']) self.assertEqual(tgrep.tgrep_tokenize('A<B&.C'), ['A', '<', 'B', '&', '.', 'C'])
def test_tokenize_examples(self): ''' Test tokenization of the TGrep2 manual example patterns. ''' self.assertEqual(tgrep.tgrep_tokenize('NP < PP'), ['NP', '<', 'PP']) self.assertEqual(tgrep.tgrep_tokenize('/^NP/'), ['/^NP/']) self.assertEqual(tgrep.tgrep_tokenize('NP << PP . VP'), ['NP', '<<', 'PP', '.', 'VP']) self.assertEqual(tgrep.tgrep_tokenize('NP << PP | . VP'), ['NP', '<<', 'PP', '|', '.', 'VP']) self.assertEqual( tgrep.tgrep_tokenize('NP !<< PP [> NP | >> VP]'), ['NP', '!', '<<', 'PP', '[', '>', 'NP', '|', '>>', 'VP', ']']) self.assertEqual(tgrep.tgrep_tokenize('NP << (PP . VP)'), ['NP', '<<', '(', 'PP', '.', 'VP', ')']) self.assertEqual( tgrep.tgrep_tokenize('NP <\' (PP <, (IN < on))'), ['NP', '<\'', '(', 'PP', '<,', '(', 'IN', '<', 'on', ')', ')']) self.assertEqual(tgrep.tgrep_tokenize('S < (A < B) < C'), ['S', '<', '(', 'A', '<', 'B', ')', '<', 'C']) self.assertEqual( tgrep.tgrep_tokenize('S < ((A < B) < C)'), ['S', '<', '(', '(', 'A', '<', 'B', ')', '<', 'C', ')']) self.assertEqual(tgrep.tgrep_tokenize('S < (A < B < C)'), ['S', '<', '(', 'A', '<', 'B', '<', 'C', ')']) self.assertEqual(tgrep.tgrep_tokenize('A<B&.C'), ['A', '<', 'B', '&', '.', 'C'])
def test_tokenize_link_types(self): """ Test tokenization of basic link types. """ self.assertEqual(tgrep.tgrep_tokenize("A<B"), ["A", "<", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>B"), ["A", ">", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<3B"), ["A", "<3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>3B"), ["A", ">3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<,B"), ["A", "<,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>,B"), ["A", ">,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<-3B"), ["A", "<-3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>-3B"), ["A", ">-3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<-B"), ["A", "<-", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>-B"), ["A", ">-", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<'B"), ["A", "<'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>'B"), ["A", ">'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<:B"), ["A", "<:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>:B"), ["A", ">:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<<B"), ["A", "<<", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>>B"), ["A", ">>", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<<,B"), ["A", "<<,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>>,B"), ["A", ">>,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<<'B"), ["A", "<<'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>>'B"), ["A", ">>'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A<<:B"), ["A", "<<:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A>>:B"), ["A", ">>:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A.B"), ["A", ".", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A,B"), ["A", ",", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A..B"), ["A", "..", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A,,B"), ["A", ",,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A$B"), ["A", "$", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A$.B"), ["A", "$.", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A$,B"), ["A", "$,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A$..B"), ["A", "$..", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A$,,B"), ["A", "$,,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<B"), ["A", "!", "<", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>B"), ["A", "!", ">", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<3B"), ["A", "!", "<3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>3B"), ["A", "!", ">3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<,B"), ["A", "!", "<,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>,B"), ["A", "!", ">,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<-3B"), ["A", "!", "<-3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>-3B"), ["A", "!", ">-3", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<-B"), ["A", "!", "<-", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>-B"), ["A", "!", ">-", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<'B"), ["A", "!", "<'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>'B"), ["A", "!", ">'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<:B"), ["A", "!", "<:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>:B"), ["A", "!", ">:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<<B"), ["A", "!", "<<", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>>B"), ["A", "!", ">>", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<<,B"), ["A", "!", "<<,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>>,B"), ["A", "!", ">>,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<<'B"), ["A", "!", "<<'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>>'B"), ["A", "!", ">>'", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!<<:B"), ["A", "!", "<<:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!>>:B"), ["A", "!", ">>:", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!.B"), ["A", "!", ".", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!,B"), ["A", "!", ",", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!..B"), ["A", "!", "..", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!,,B"), ["A", "!", ",,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!$B"), ["A", "!", "$", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!$.B"), ["A", "!", "$.", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!$,B"), ["A", "!", "$,", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!$..B"), ["A", "!", "$..", "B"]) self.assertEqual(tgrep.tgrep_tokenize("A!$,,B"), ["A", "!", "$,,", "B"])
def test_tokenize_link_types(self): ''' Test tokenization of basic link types. ''' self.assertEqual(tgrep.tgrep_tokenize('A<B'), ['A', '<', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>B'), ['A', '>', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<3B'), ['A', '<3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>3B'), ['A', '>3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<,B'), ['A', '<,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>,B'), ['A', '>,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<-3B'), ['A', '<-3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>-3B'), ['A', '>-3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<-B'), ['A', '<-', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>-B'), ['A', '>-', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<\'B'), ['A', '<\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>\'B'), ['A', '>\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<:B'), ['A', '<:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>:B'), ['A', '>:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<<B'), ['A', '<<', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>>B'), ['A', '>>', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<<,B'), ['A', '<<,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>>,B'), ['A', '>>,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<<\'B'), ['A', '<<\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>>\'B'), ['A', '>>\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A<<:B'), ['A', '<<:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A>>:B'), ['A', '>>:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A.B'), ['A', '.', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A,B'), ['A', ',', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A..B'), ['A', '..', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A,,B'), ['A', ',,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A$B'), ['A', '$', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A$.B'), ['A', '$.', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A$,B'), ['A', '$,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A$..B'), ['A', '$..', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A$,,B'), ['A', '$,,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<B'), ['A', '!', '<', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>B'), ['A', '!', '>', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<3B'), ['A', '!', '<3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>3B'), ['A', '!', '>3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<,B'), ['A', '!', '<,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>,B'), ['A', '!', '>,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<-3B'), ['A', '!', '<-3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>-3B'), ['A', '!', '>-3', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<-B'), ['A', '!', '<-', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>-B'), ['A', '!', '>-', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<\'B'), ['A', '!', '<\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>\'B'), ['A', '!', '>\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<:B'), ['A', '!', '<:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>:B'), ['A', '!', '>:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<<B'), ['A', '!', '<<', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>>B'), ['A', '!', '>>', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<<,B'), ['A', '!', '<<,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>>,B'), ['A', '!', '>>,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<<\'B'), ['A', '!', '<<\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>>\'B'), ['A', '!', '>>\'', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!<<:B'), ['A', '!', '<<:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!>>:B'), ['A', '!', '>>:', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!.B'), ['A', '!', '.', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!,B'), ['A', '!', ',', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!..B'), ['A', '!', '..', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!,,B'), ['A', '!', ',,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!$B'), ['A', '!', '$', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!$.B'), ['A', '!', '$.', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!$,B'), ['A', '!', '$,', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!$..B'), ['A', '!', '$..', 'B']) self.assertEqual(tgrep.tgrep_tokenize('A!$,,B'), ['A', '!', '$,,', 'B'])
def test_tokenize_examples(self): """ Test tokenization of the TGrep2 manual example patterns. """ self.assertEqual(tgrep.tgrep_tokenize("NP < PP"), ["NP", "<", "PP"]) self.assertEqual(tgrep.tgrep_tokenize("/^NP/"), ["/^NP/"]) self.assertEqual(tgrep.tgrep_tokenize("NP << PP . VP"), ["NP", "<<", "PP", ".", "VP"]) self.assertEqual(tgrep.tgrep_tokenize("NP << PP | . VP"), ["NP", "<<", "PP", "|", ".", "VP"]) self.assertEqual( tgrep.tgrep_tokenize("NP !<< PP [> NP | >> VP]"), ["NP", "!", "<<", "PP", "[", ">", "NP", "|", ">>", "VP", "]"], ) self.assertEqual( tgrep.tgrep_tokenize("NP << (PP . VP)"), ["NP", "<<", "(", "PP", ".", "VP", ")"], ) self.assertEqual( tgrep.tgrep_tokenize("NP <' (PP <, (IN < on))"), ["NP", "<'", "(", "PP", "<,", "(", "IN", "<", "on", ")", ")"], ) self.assertEqual( tgrep.tgrep_tokenize("S < (A < B) < C"), ["S", "<", "(", "A", "<", "B", ")", "<", "C"], ) self.assertEqual( tgrep.tgrep_tokenize("S < ((A < B) < C)"), ["S", "<", "(", "(", "A", "<", "B", ")", "<", "C", ")"], ) self.assertEqual( tgrep.tgrep_tokenize("S < (A < B < C)"), ["S", "<", "(", "A", "<", "B", "<", "C", ")"], ) self.assertEqual(tgrep.tgrep_tokenize("A<B&.C"), ["A", "<", "B", "&", ".", "C"])