Search code examples
pythonnlp

Adding known word to Python pyspellchecker with word_frequency.load_words


I am trying to add a new word to be recognized by pyspellchecker. The following code:

from spellchecker import SpellChecker
spell = SpellChecker(language='es')
spell.word_frequency.load_words('coronavirus')
spell.unknown(['El','coronavirus','marca','nuestros','días'])

Produces this output:

{'coronavirus'}

And the output I expected was:

set()

...an empty set, as I added the word 'coronavirus' so it should be included in the set of known words.


Solution

  • Already solved, I missed the brackets. This is the corrected code:

    from spellchecker import SpellChecker
    spell = SpellChecker(language='es')
    spell.word_frequency.load_words(['coronavirus'])
    spell.unknown(['El','coronavirus','marca','nuestros','días'])
    

    Which has this output:

    set()