Beispiel #1
0
    def test_spellchecker(self):
        checker = NorvigSpellingChecker()
        self.assertIsNotNone(checker)

        self.assertEqual("THIS", checker.correct("THIS"))
        self.assertEqual("THIS", checker.correct("This"))
        self.assertEqual("THIS", checker.correct("this"))

        self.assertEqual("LOCATION", checker.correct("LOCETION"))
        self.assertEqual("LOCATION", checker.correct("Locetion"))
        self.assertEqual("LOCATION", checker.correct("locetion"))
Beispiel #2
0
    def test_load_spelling(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertTrue(store.load_spelling(spelling_checker))

        self.assertEqual("THESE ARE SOME WORDS", spelling_checker.correct("Thise ara sime wards"))
Beispiel #3
0
    def assert_upload_from_file(self, store):
        store.empty()

        store.upload_from_file(
            os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" +
            os.sep + "corpus.txt")

        spelling_checker = NorvigSpellingChecker()
        store.load_spelling(spelling_checker)

        self.assertEqual("THESE ARE SOME WORDS",
                         spelling_checker.correct("Thise ara sime wards"))
Beispiel #4
0
    def assert_upload_from_file_no_corpus(self, store, verbose):
        store.empty()

        spelling_checker = NorvigSpellingChecker()
        store.load_spelling(spelling_checker)

        spelling_checker = NorvigSpellingChecker()

        self.assertEquals(0, len(spelling_checker.words))
        self.assertEquals(0, spelling_checker.sum_of_words)

        store.load_spelling(spelling_checker)

        self.assertEquals(0, len(spelling_checker.words))
        self.assertEquals(0, spelling_checker.sum_of_words)
Beispiel #5
0
    def assert_upload_from_file_exception(self, store, verbose):
        store.empty()

        spelling_checker = NorvigSpellingChecker()
        store.load_spelling(spelling_checker)

        store.upload_from_file(os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", verbose=verbose)

        spelling_checker = NorvigSpellingChecker()

        self.assertEquals(0, len(spelling_checker.words))
        self.assertEquals(0, spelling_checker.sum_of_words)

        store.load_spelling(spelling_checker)

        self.assertEquals(0, len(spelling_checker.words))
        self.assertEquals(0, spelling_checker.sum_of_words)
Beispiel #6
0
    def test_load_spelling_with_exception(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertFalse(store.load_spelling(spelling_checker))
    def setUp(self):
        self._client = TestClient()

        config = BotConfiguration()

        self.client_context = self._client.create_client_context("testuser")

        self.client_context._bot = Bot(config=config, client=self._client)
        self.client_context._bot._spell_checker = NorvigSpellingChecker()
Beispiel #8
0
    def setUp(self):
        self._client = TestClient()

        config = BotConfiguration()

        self.client_context = self._client.create_client_context("testuser")

        self.client_context._bot = Bot(config=config, client=self._client)
        self.client_context._bot._spell_checker = NorvigSpellingChecker()
        self.client_context._bot._spell_checker.add_corpus("THIS IS HAVE WORDS SPELLED CORRECTLY")
Beispiel #9
0
    def test_spellchecker(self):
        client = TestClient()

        client.add_license_keys_store()
        client.add_spelling_store()

        checker = NorvigSpellingChecker()
        self.assertIsNotNone(checker)
        checker.initialise(client.storage_factory)

        self.assertEqual("THIS", checker.correct("THIS"))
        self.assertEqual("THIS", checker.correct("This"))
        self.assertEqual("THIS", checker.correct("this"))

        self.assertEqual("LOCATION", checker.correct("LOCETION"))
        self.assertEqual("LOCATION", checker.correct("Locetion"))
        self.assertEqual("LOCATION", checker.correct("locetion"))
Beispiel #10
0
    def test_spellchecker(self):
        checker = NorvigSpellingChecker()
        self.assertIsNotNone(checker)

        self.assertEqual("THIS", checker.correct("THIS"))
        self.assertEqual("THIS", checker.correct("This"))
        self.assertEqual("THIS", checker.correct("this"))

        self.assertEqual("LOCATION", checker.correct("LOCETION"))
        self.assertEqual("LOCATION", checker.correct("Locetion"))
        self.assertEqual("LOCATION", checker.correct("locetion"))
Beispiel #11
0
    def test_edits(self):
        checker = NorvigSpellingChecker()
        checker.add_corpus("THIS IS A WORD AND SO IS THIS")

        edits1 = checker._edits1('AND')
        list1 = list(edits1)
        list1.sort()
        self.assertEquals(list1[0], 'AAD')

        edits2 = checker._edits2('AND')
        list2 = [x for x in edits2]
        list2.sort()
        self.assertEquals('A', list2[0])
Beispiel #12
0
    def test_probability(self):
        checker = NorvigSpellingChecker()
        self.assertEquals(0.0, checker._probability("WORD"))

        checker.add_corpus("WORD")
        self.assertEquals(1.0, checker._probability("WORD"))