Ejemplo n.º 1
0
    def test_delete_dictionary_entry(self):
        sym_spell = SymSpell()
        sym_spell.create_dictionary_entry("stea", 1)
        sym_spell.create_dictionary_entry("steama", 2)
        sym_spell.create_dictionary_entry("steem", 3)

        result = sym_spell.lookup("steama", Verbosity.TOP, 2)
        self.assertEqual(1, len(result))
        self.assertEqual("steama", result[0].term)
        self.assertEqual(len("steama"), sym_spell.max_length())
        self.assertEqual(3, sym_spell.word_count())

        self.assertTrue(sym_spell.delete_dictionary_entry("steama"))
        self.assertEqual(len("steem"), sym_spell.max_length())
        self.assertEqual(2, sym_spell.word_count())
        result = sym_spell.lookup("steama", Verbosity.TOP, 2)
        self.assertEqual(1, len(result))
        self.assertEqual("steem", result[0].term)

        self.assertTrue(sym_spell.delete_dictionary_entry("stea"))
        self.assertEqual(len("steem"), sym_spell.max_length())
        self.assertEqual(1, sym_spell.word_count())
        result = sym_spell.lookup("steama", Verbosity.TOP, 2)
        self.assertEqual(1, len(result))
        self.assertEqual("steem", result[0].term)
Ejemplo n.º 2
0
    def test_add_additional_counts_should_not_add_word_again(self):
        sym_spell = SymSpell()
        word = "hello"
        sym_spell.create_dictionary_entry(word, 11)
        self.assertEqual(1, sym_spell.word_count())

        sym_spell.create_dictionary_entry(word, 3)
        self.assertEqual(1, sym_spell.word_count())
Ejemplo n.º 3
0
 def test_load_dictionary_bad_dictionary(self):
     dictionary_path = os.path.join(self.fortests_path, "bad_dict.txt")
     edit_distance_max = 2
     prefix_length = 7
     sym_spell = SymSpell(edit_distance_max, prefix_length)
     self.assertEqual(True,
                      sym_spell.load_dictionary(dictionary_path, 0, 1))
     self.assertEqual(7, sym_spell.word_count())