示例#1
0
 def test_context_window_search_sentence_extension_acc(self):
     testfile = open("text.txt", 'w')
     testfile.write("There are only fluffy kittens! Only kittens")
     testfile.close()
     self.testindexer.index_with_lines("text.txt")
     testfile2 = open("text2.txt", 'w')
     testfile2.write("only kittens and puppies.")
     testfile2.close()
     self.testindexer.index_with_lines("text2.txt")
     testsearch = search_engine.SearchEngine('database')
     windowsdict = testsearch.several_tokens_search_with_sentence_context_acc(
         "only", 3, -10)
     expectedwindowresult = {
         "text.txt": [
             search_engine.ContextWindow(
                 "There are only fluffy kittens! Only kittens",
                 [indexer.Position_with_lines(10, 14, 0)],
                 search_engine.WindowPosition(0, 30, 0, "text.txt"))
         ],
         "text2.txt": [
             search_engine.ContextWindow(
                 "only kittens and puppies.",
                 [indexer.Position_with_lines(0, 4, 0)],
                 search_engine.WindowPosition(0, 25, 0, "text2.txt"))
         ]
     }
     self.assertEqual(windowsdict, expectedwindowresult)
     windowsdict = testsearch.several_tokens_search_with_sentence_context_acc(
         "only", 1, 8)
     expectedwindowresult = {}
     self.assertEqual(windowsdict, expectedwindowresult)
示例#2
0
 def test_context_window_search_several_tokens_several_files_3_3(self):
     testfile = open("text.txt", 'w')
     testfile.write("There are only fluffy kittens!")
     testfile.close()
     testfile2 = open("text2.txt", 'w')
     testfile2.write("only kittens and puppies...")
     testfile2.close()
     self.testindexer.index_with_lines("text2.txt")
     self.testindexer.index_with_lines("text.txt")
     testsearch = search_engine.SearchEngine('database')
     # context '3,3'
     windowsdict = testsearch.several_tokens_search_with_customizable_context(
         "only kittens", 3, 3)
     expectedwindowresult = {
         "text.txt": [
             search_engine.ContextWindow(
                 "There are only fluffy kittens", [
                     indexer.Position_with_lines(10, 14, 0),
                     indexer.Position_with_lines(22, 29, 0)
                 ], search_engine.WindowPosition(0, 29, 0, "text.txt"))
         ],
         "text2.txt": [
             search_engine.ContextWindow(
                 "only kittens and puppies", [
                     indexer.Position_with_lines(0, 4, 0),
                     indexer.Position_with_lines(5, 12, 0)
                 ], search_engine.WindowPosition(0, 24, 0, "text2.txt"))
         ]
     }
     self.assertEqual(expectedwindowresult, windowsdict)
示例#3
0
    def test_context_window_search_sentence_extension(self):
        testfile = open("text.txt", 'w')
        testfile.write("There are only fluffy kittens! Only kittens")
        testfile.close()
        self.testindexer.index_with_lines("text.txt")

        testsearch = search_engine.SearchEngine('database')

        windowsdict = testsearch.several_tokens_search_with_sentence_context(
            "only")
        expectedwindowresult = {
            "text.txt": [
                search_engine.ContextWindow(
                    "There are only fluffy kittens! Only kittens",
                    [indexer.Position_with_lines(10, 14, 0)],
                    search_engine.WindowPosition(0, 30, 0, "text.txt"))
            ]
        }
        self.assertEqual(windowsdict, expectedwindowresult)

        windowsdict = testsearch.several_tokens_search_with_sentence_context(
            "only fluffy")
        expectedwindowresult = {
            "text.txt": [
                search_engine.ContextWindow(
                    "There are only fluffy kittens!", [
                        indexer.Position_with_lines(10, 14, 0),
                        indexer.Position_with_lines(15, 21, 0)
                    ], search_engine.WindowPosition(0, 30, 0, "text.txt"))
            ]
        }
        self.assertEqual(windowsdict, expectedwindowresult)

        windowsdict = testsearch.several_tokens_search_with_sentence_context(
            "kittens")
        expectedwindowresult = {
            "text.txt": [
                search_engine.ContextWindow(
                    "There are only fluffy kittens! Only kittens", [
                        indexer.Position_with_lines(22, 29, 0),
                        indexer.Position_with_lines(36, 43, 0)
                    ], search_engine.WindowPosition(0, 43, 0, "text.txt"))
            ]
        }
        self.assertEqual(windowsdict, expectedwindowresult)
示例#4
0
 def test_context_window_search_several_tokens_several_files_0_0(self):
     testfile = open("text.txt", 'w')
     testfile.write("There are only fluffy kittens!")
     testfile.close()
     self.testindexer.index_with_lines("text.txt")
     testsearch = search_engine.SearchEngine('database')
     # context '0,0'
     windowsdict = testsearch.several_tokens_search_with_customizable_context(
         "only kittens", 0, 0)
     expectedwindowresult = {
         'text.txt': [
             search_engine.ContextWindow(
                 "There are only fluffy kittens!",
                 [indexer.Position_with_lines(10, 14, 0)],
                 search_engine.WindowPosition(10, 14, 0, "text.txt")),
             search_engine.ContextWindow(
                 "There are only fluffy kittens!",
                 [indexer.Position_with_lines(22, 29, 0)],
                 search_engine.WindowPosition(22, 29, 0, "text.txt"))
         ]
     }
     self.assertEqual(expectedwindowresult, windowsdict)
示例#5
0
 def test_context_window_context_window_one_position_one_file(self):
     testfile = open("text.txt", 'w')
     testfile.write("There are only kittens!")
     testfile.close()
     testfile2 = open("text2.txt", 'w')
     testfile2.write("only...")
     testfile2.close()
     self.testindexer.index_with_lines("text.txt")
     self.testindexer.index_with_lines("text2.txt")
     testsearch = search_engine.SearchEngine('database')
     window1 = search_engine.ContextWindow.get_context_window_one_position_one_file(
         indexer.Position_with_lines(0, 4, 0), "text2.txt", "only...", 2, 1)
     window2 = search_engine.ContextWindow.get_context_window_one_position_one_file(
         indexer.Position_with_lines(10, 14, 0), "text.txt",
         "There are only kittens!", 2, 1)
     expectedwindow1 = search_engine.ContextWindow(
         "only", [indexer.Position_with_lines(0, 4, 0)],
         search_engine.WindowPosition(0, 4, 0, "text2.txt"))
     expectedwindow2 = search_engine.ContextWindow(
         "There are only kittens", [indexer.Position_with_lines(10, 14, 0)],
         search_engine.WindowPosition(0, 22, 0, "text.txt"))
     self.assertEqual(expectedwindow1, window1)
     self.assertEqual(expectedwindow2, window2)
     windowsdict = testsearch.several_tokens_search_with_customizable_context(
         "only", 2, 1)
     expectedwindowresult = {
         "text.txt": [
             search_engine.ContextWindow(
                 "There are only kittens",
                 [indexer.Position_with_lines(10, 14, 0)],
                 search_engine.WindowPosition(0, 22, 0, "text.txt"))
         ],
         "text2.txt": [
             search_engine.ContextWindow(
                 "only", [indexer.Position_with_lines(0, 4, 0)],
                 search_engine.WindowPosition(0, 4, 0, "text2.txt"))
         ]
     }
     self.assertEqual(expectedwindowresult, windowsdict)