@extends('template') @section('title') Lab 11, Part 3: Spell checker @stop @section('content') # Lab 11, Part 3: Spell checker In this task, you'll use provided word dictionaries to spell check sentences. Open the file `spellcheck.py` in your `lab11` folder. At the top of your file, there is a block of code that loads in three dictionary variables: + `smallDict` (~200 words) + `mediumDict` (~25,000 words) + `largeDict` (~370,000 words) Think of each of these dictionaries as a word dictionary (as in an actual real-life dictionary). Correctly spelled words are keys in the given dictionaries (the value of each key is 1; it doesn't matter what the value is because we are only interested in the keys). We are using dictionaries here because the access time is fast. When using `largeDict`, we are checking against over 370,000 words, and dictionaries are faster than, say, lists of the same 370,000 words. ## Task 1: Use the given dictionaries to spell-check sentences Write a function called `checkSentence` that takes two parameters: a sentence and a dictionary and returns True if all the words in the sentence are in the dictionary, and False if not. If the function returns False, it will indicate the first word in the sentence that does not appear in the dictionary. Note: You can break a sentence into separate words by using `split`. `split` is a built-in function in Python -- it stashes the words in a **list**. Here is the [python documentation for split](https://docs.python.org/2/library/stdtypes.html#str.split), and here is a [simple split example](http://www.pythonforbeginners.com/dictionary/python-split). ```py >>> "This sentence can be split into separate words".split() ['This', 'sentence', 'can', 'be', 'split', 'into', 'separate', 'words'] ``` Here are a few examples of how your `checkSentence` should work. Pay attention to capitalization. You'll notice that this is not a particularly sophisticated spell-checker, but it is a decent start. ```py >>> checkSentence('duck toy train', smallDict) True >>> checkSentence('Her duck is yellow', smallDict) **** yellow is not in the given dictionary False >>> checkSentence('Her duck eats grapes', smallDict) **** eats is not in the given dictionary False >>> checkSentence('grape', mediumDict) True >>> checkSentence('grapes', mediumDict) **** grapes is not in the given dictionary False >>> checkSentence('Her duck ate the spoon from the zoo', mediumDict) True >>> checkSentence('I am surprised that her duck is chartreuse', mediumDict) **** surprised is not in the given dictionary False >>> checkSentence('How were the points allocated?', mediumDict) **** points is not in the given dictionary False >>> >>> checkSentence('Look at the cirrus clouds!', mediumDict) **** cirrus is not in the given dictionary False >>> checkSentence('Look at the cirrus clouds!', largeDict) **** clouds! is not in the given dictionary >>> checkSentence('How were the points allocated?', largeDict) **** allocated? is not in the given dictionary >>> checkSentence("Truly yogurt and Lemon Thai are in Wellesley", largeDict) **** Wellesley is not in the given dictionary False >>> checkSentence("yeah i don't think so", largeDict) **** don't is not in the given dictionary False >>> ``` ## Task 2: Improve your spell-checker As you may have noted, this is a rather crude spell-checker. Some possible ideas for a better version: + return a list of all the misspelled words in a given sentence (and not just the first misspelled word) + ignore punctuation + handle plurals + handle verb conjugations + other ideas you may have Improve your `checkSentence` so it does something a little better. It's up to you to choose what aspect to make better. @include('/labs/lab11/_toc') @stop