Example #1
0
 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]'))
Example #2
0
 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]'))
Example #3
0
 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]"),
     )
Example #4
0
 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', ')',
                       ')'])
Example #5
0
 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', ')',
                       ')'])
Example #6
0
 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',
         ],
     )
Example #7
0
 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',
             ']',
         ],
     )
Example #8
0
 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",
         ],
     )
Example #9
0
 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'])
Example #10
0
 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",
             "]",
         ],
     )
Example #11
0
 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",
         ],
     )
Example #12
0
 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',
         ],
     )
Example #13
0
 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',
             ']',
         ],
     )
Example #14
0
 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'])
Example #15
0
 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',
         ],
     )
Example #16
0
 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'])
Example #17
0
 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"],
     )
Example #18
0
 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",
             ")",
             ")",
         ],
     )
Example #19
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', ',', ')']
     )
Example #20
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", ",", ")"])
Example #21
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', ',', ')'])
Example #22
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'])
Example #23
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'])
Example #24
0
 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"])
Example #25
0
 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'])
Example #26
0
 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'])
Example #27
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"])