Harry Stuart
Harry Stuart

Reputation: 1945

Spelling corrector with supplementary custom dictionary

What is the best system for spell checking in python that enables the use of an external dictionary? I've seen packages that use an external dictionary to replace a default English dictionary for example. But I would like the external dictionary to supplement the existing spell check. For example, if I have weird abstract words (dsdfw, peloe, punj), I want the spell checker to be able to recognise them as English words for the purposes of spelling correction.

This is na exapmle of a setence using pelloe

Should become

This is an example of a sentence using peloe

Upvotes: 3

Views: 3399

Answers (1)

accdias
accdias

Reputation: 5372

As I said in my comment, a nice option is enchant.

Here is an example on how to use it to add words for a session:

import enchant

en_us = enchant.Dict('en_US')

en_us_weird_words = ['your', 'weird', 'words', 'list', 'here']

for word in en_us_weird_words:

    # add word to personal dictionary
    # en_us.add(word)

    # add word just for this session
    en_us.add_to_session(word)

pt_br = enchant.Dict('pt_BR')

pt_br_weird_words = ['outras', 'palavras', 'estranhas', 'aqui']

for word in pt_br_weird_words:

    # add word to personal dictionary
    # pt_br.add(word)

    # add word just for this session
    pt_br.add_to_session(word)

I hope it helps.

Upvotes: 3

Related Questions