12

So PyEnchant allows you to define a personal word list of correctly spelled words in addition to a language dictionary:

d2 = enchant.DictWithPWL("en_US","mywords.txt")

However, the resulting d2 checker is of class Dict, which can only be used to check a single word, e.g.:

>>> d.check("Hello")
True

The SpellChecker class allows spellchecking of a block of text. However, I can't seem to find out how to specify a personal word list as with Dict. Is this not a supported feature? I'd like to spellcheck a block of text against en_US plus my personal word list. Any ideas?

mart1n
  • 5,969
  • 5
  • 46
  • 83
  • What exactly do you mean by *specify a personal word list*? – A.J. Uppal Apr 10 '14 at 04:17
  • @aj8uppal: meaning the file `mywords.txt` holds a list of words that I want spellchecked. More info here: http://pythonhosted.org/pyenchant/tutorial.html#personal-word-lists – mart1n Apr 10 '14 at 06:10

1 Answers1

20

The first argument of the SpellChecker initializer can be both the name of a language or an enchant dictionary:

from enchant import DictWithPWL
from enchant.checker import SpellChecker

my_dict = DictWithPWL("en_US", "mywords.txt")
my_checker = SpellChecker(my_dict)

my_checker.set_text("This is sme sample txt with erors.")
for error in my_checker:
    print "ERROR:", error.word

The documentation isn't clear about this, but the code is available :)

zeebonk
  • 4,864
  • 4
  • 21
  • 31