|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
| 3 | +from pythainlp.corpus import ttc |
3 | 4 | from pythainlp.spell import spell |
4 | | -from pythainlp.spell.pn import spell as pn_tnc_spell |
5 | | -from pythainlp.spell.pn import correct as pn_tnc_correct |
6 | 5 | from pythainlp.spell.pn import NorvigSpellChecker |
7 | | -from pythainlp.corpus import ttc |
| 6 | +from pythainlp.spell.pn import correct as pn_tnc_correct |
| 7 | +from pythainlp.spell.pn import spell as pn_tnc_spell |
8 | 8 |
|
9 | | -# checker from pythainlp.spell module (generic) |
10 | | -spell("สี่เหลียม") # ['สี่เหลี่ยม'] |
11 | | -# spell("สี่เหลียม", engine="hunspell") # available in some Linux systems |
| 9 | +# spell checker from pythainlp.spell module (generic) |
| 10 | +print(spell("สี่เหลียม")) # ['สี่เหลี่ยม'] |
| 11 | +# print(spell("สี่เหลียม", engine="hunspell")) # available in some Linux systems |
12 | 12 |
|
13 | | -# checker from pythainlp.spell.pn module (specified algorithm - Peter Norvig's) |
14 | | -pn_tnc_spell("เหลืยม") |
15 | | -pn_tnc_correct("เหลืยม") |
| 13 | +# spell checker from pythainlp.spell.pn module (specified algorithm - Peter Norvig's) |
| 14 | +print(pn_tnc_spell("เหลืยม")) |
| 15 | +print(pn_tnc_correct("เหลืยม")) |
16 | 16 |
|
17 | | -# checker from pythainlp.spell.pn module (specified algorithm, custom dictionary) |
| 17 | + |
| 18 | +# spell checker from pythainlp.spell.pn module (specified algorithm, custom dictionary) |
18 | 19 | ttc_word_freqs = ttc.get_word_frequency_all() |
19 | | -pn_ttc_spell_checker = NorvigSpellChecker(custom_dict=ttc_word_freqs) |
20 | | -pn_ttc_spell_checker.spell("เหลืยม") |
21 | | -pn_ttc_spell_checker.correct("เหลืยม") |
| 20 | +pn_ttc_checker = NorvigSpellChecker(custom_dict=ttc_word_freqs) |
| 21 | +print(pn_ttc_checker.spell("เหลืยม")) |
| 22 | +print(pn_ttc_checker.correct("เหลืยม")) |
| 23 | + |
| 24 | +# apply different dictionary filter when creating spell checker |
| 25 | +pn_tnc_checker = NorvigSpellChecker() |
| 26 | +print(len(pn_tnc_checker.dictionary())) |
| 27 | +pn_tnc_checker_no_filter = NorvigSpellChecker(dict_filter=None) |
| 28 | +print(len(pn_tnc_checker_no_filter.dictionary())) |
0 commit comments