예제 #1
0
 def test_limit_scw(self):
     """test if the program is working correctly
     when searching for context windows extended to
     the sentence boundaries
     """
     result = self.s.limit_search_extended_context('test required', 2, 1, 0)
     output = {'test.txt': [Context_Window([Position_with_lines(10, 14, 0), Position_with_lines(15, 23, 0),
                                            Position_with_lines(54, 58, 0)], 0, 58, 'this is a test required for helping students create a test'),
                            Context_Window([Position_with_lines(11, 19, 1), Position_with_lines(31, 35, 1)], 0, 41, ' professor required to write a test first')]}
     self.assertEqual(result, output)
예제 #2
0
 def test_mcw_two(self):
     """test if the program is working correctly
     when searching for contexts of two words with window = 2
     
     """
     query = self.s.search_multiple('test required')
     result = self.s.search_multiple_contexts(query, 2)
     output = {'test.txt': [Context_Window([Position_with_lines(10, 14, 0), Position_with_lines(15, 23, 0)], 5, 35, 'this is a test required for helping students create a test'),
                            Context_Window([Position_with_lines(54, 58, 0)], 45, 58, 'this is a test required for helping students create a test'),
                            Context_Window([Position_with_lines(11, 19, 1), Position_with_lines(31, 35, 1)], 0, 41, ' professor required to write a test first')],
               'tst.txt': [Context_Window([Position_with_lines(0, 4, 0), Position_with_lines(8, 16, 0)], 0, 24, 'test is required. On the other hand...')]}
     self.assertEqual(result, output)
예제 #3
0
 def test_mcw_singleword_one(self):
     """test if the program is working correctly
     when searching for contexts of a word with window = 1
     
     """
     query = self.s.search_multiple('test')
     result = self.s.search_multiple_contexts(query, 1)
     output = {'test.txt': [Context_Window([Position_with_lines(10, 14, 0)], 8, 23, 'this is a test required for helping students create a test'),
                            Context_Window([Position_with_lines(54, 58, 0)], 52, 58, 'this is a test required for helping students create a test'),
                            Context_Window([Position_with_lines(31, 35, 1)], 29, 41, ' professor required to write a test first')],
               'tst.txt': [Context_Window([Position_with_lines(0, 4, 0)], 0, 7, 'test is required. On the other hand...')]}
     self.assertEqual(result, output)
예제 #4
0
 def test_cw_no_right_one_token(self):
     """test if the program is working correctly
     when searching for context of a word with no right context
     
     """
     result = self.s.search_one_context('test.txt', Position_with_lines(54, 58, 0), 3)
     self.window = Context_Window([Position_with_lines(54, 58, 0)], 36, 58, 'this is a test required for helping students create a test')
     self.assertEqual(result.start, self.window.start)
     self.assertEqual(result.end, self.window.end)
     self.assertEqual(result.position, self.window.position)
     self.assertEqual(result.string, self.window.string)
예제 #5
0
 def test_cw_one_out_of_range(self):
     """test if the program is working correctly
     when searching for context of a word with window > text length
     
     """
     result = self.s.search_one_context('test.txt', Position_with_lines(10, 14, 0), 10)
     self.window = Context_Window([Position_with_lines(10, 14, 0)], 0, 58, 'this is a test required for helping students create a test')
     self.assertEqual(result.start, self.window.start)
     self.assertEqual(result.end, self.window.end)
     self.assertEqual(result.position, self.window.position)
     self.assertEqual(result.string, self.window.string)
예제 #6
0
 def test_scw_single(self):
     """test if the program is working correctly
     when searching for context windows extended to
     the sentence boundaries for a single word
     """
     k = open('newtest.txt', 'w')
     k.write('What is your name? My name is test.')
     k.close()
     ind = indexer.Indexer('newdb')
     ind.indexing_with_lines('newtest.txt')
     del ind
     self.k = SearchEngine('newdb')
     result = self.k.search_extended_context('test', 1)
     output = {'newtest.txt': [Context_Window([Position_with_lines(30, 34, 0)], 19, 35, 'What is your name? My name is test.')]}
     self.assertEqual(result, output)
     del self.k
     for filename in os.listdir(os.getcwd()):            
         if filename == 'newdb' or filename.startswith('newdb.'):
             os.remove(filename)        
     os.remove('newtest.txt')