-
Notifications
You must be signed in to change notification settings - Fork 13
/
tests_spellchecker.py
71 lines (61 loc) · 2.8 KB
/
tests_spellchecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections
from libindic.stemmer import Malayalam as stemmer
from testtools import TestCase
from .. import Malayalam as spellchecker
class MalayalamSpellcheckerTest(TestCase):
def setUp(self):
super(MalayalamSpellcheckerTest, self).setUp()
self.spellchecker = spellchecker()
self.stemmer = stemmer()
self.verbosity = False
def test_checking(self):
'''
Test if spelling mistake detection works fine.
'''
true_list = [u'രമയുടെ',
u'ആപത്തിലേക്ക്',
u'ദേവി'
]
for word in true_list:
status = self.spellchecker.check_and_generate(word)['status']
if self.verbosity:
print("%s : %s" % (word, status))
assert status
false_list = [u'ആബത്തിന്റെ',
u'അദ്യാപഗൻ',
u'ദേബി'
]
for word in false_list:
status = self.spellchecker.check_and_generate(word)['status']
if self.verbosity:
print("%s : %s" % (word, status))
assert not status
custom_words = [u'സ്യൂഡോനാഷണലിസ്റ്റ്']
# Words that are not found in dictionary, but unique and thus deemed
# valid
for word in custom_words:
status = self.spellchecker.check_and_generate(word)['status']
if self.verbosity:
print("%s : %s" % (word, status))
assert status
def test_suggestion_generation(self):
'''
Test if correct word is in the list of suggestions generated.
'''
words = collections.OrderedDict({u'ബാരതം': u'ഭാരതം',
u'അദ്യാപകന്': u'അധ്യാപകൻ',
u'ഹലാകലം': u'ഹലാഹലം',
u'ബാരതത്തിന്റെ': u'ഭാരതത്തിന്റെ',
u'അദ്യാപഗനോട്': u'അധ്യാപകനോട്'
})
for incorrect_word, correct_word in words.items():
incorrect_word = self.stemmer.singleencode(incorrect_word)
correct_word = self.stemmer.singleencode(correct_word)
suggestion_list = self.spellchecker.suggest(incorrect_word)
if self.verbosity:
print(incorrect_word + "\n")
for word in suggestion_list:
print("\t" + word)
self.assertIn(correct_word, suggestion_list)