Dictionary Module for Python

- author: Saswat Raj

Contents


Dictionary Module Functions

Use the dictionary module to spell check your documents in python with its easy implimentation and functions.It has a dictionary class that handles all operations with the dictionary and a session class that handles temporary session words to the dictionary.Besides all these you have an option to add words permanently to the dictionary.This method is diretcly available in the dictionary module. To add to dictionary permanently use addToDictionary function.An ex- ample of this is:

dictionary.addToDictionary(’myname’)

Now when you check for myname it will give True as a result.

Dictionary Class

The dictionary class provides all interactions with the dictionary file.Some examples of using the dictionary class are given below.Remember all opera- tions are to be done using a dictionary object.Each object can have its own session object hence its search space will be different.See examples below:

dict=dictionary.Dictionary()
dict.isInDictionary(’hello’)

This is the basic dictionary without any session object.It will return true if word is in dictionary and false if not.You can also initialize with a session object and change it later.

dict=dictionary.Dictionary(sessionObject)

To get a list of probable words that could be caused by one mistake use function getSimilarWords.This will return a list of probable words if present and an empty list if no words are found. To change session object associated with a dictionary use changeSessions- Dictionary with a session object as a parameter.

dict.getSimilarWords(’hullo’)
dict.changeSessionsDictionary(newsessDict)

Sessions Class

Example of creating a session object which will have temporary words to be added to dictionary when initialized with it.Creating a session object is like:

s=dictionary.Session()
s.addToSession(’myname’)
s.addListToSession(’["dominoes","mytitle"]’)
s.removeFromSession(’dominoes’)

These are procedures to add and remove words from session and to check whether a word is in session just use isInSessionsDictionary method of the dictionary object.

Exceptions

We have two types of exceptions defined: DictFileMissingException It is when python cannot access the dict file because of installation or deletion problems or due to IOError. NotCorrectArgument It is for the user to check for the correct argu- ments to be specified then the user can throw this exception