Project 14 of 15, for Paul
Spell Checker
A spell checker for Paul's end-of-term quiz: the fewest changes between two words, worked out with a table, the nearest real words suggested from a list counted from two old novels, and every answer marked right, near enough or wrong.
Sign up free to open itLog in
Act 4 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- PaulI'm marking the end-of-term quiz on capital cities, and Riya wrote Copenhagan, which I'd give her.
- PaulYahya wrote Kito for Quito and reckons that's near enough too. I need a proper rule before he starts arguing.
- YahyaAnd nobody got the bonus question, which was how many ways there are to make fifty pence.
- NeilBoth of those come apart into smaller questions, and the trick is never working anything out twice.
words.csv is a word list with a count for each word: every word that turns up at least twice in two old novels, Great Expectations and Treasure Island, and how many times. load_counts reads it into a dictionary, and words_in gives back the words of a text in lower case. In spell.py, write:
edit_distance(given, correct): the fewest changes that turn one word into the other, where a change puts in a letter, takes one out, or swaps one letter for another. Fill a table, as Paul does for the Arcade's tokens. Two words of sixty letters should take a blink.suggest(word, counts, limit=3): up tolimitknown words no more thanMOST_CHANGES(2) changes fromword: the fewest changes first; on a tie, the word with the bigger count; on a tie again, alphabetical order. An empty list if nothing is that near.check(text, counts): a list of(word, suggestions)for each word in the text that isn't in the list, in the order they come, each word once.mark(given, correct)gives back"right","near enough"or"wrong", ignoring capitals and spaces at either end. Near enough is Paul's rule: no more than one change for every five letters of the right answer, rounded down.
The main block marks Paul's three disputed answers, then checks each line typed until a blank one.
Knows 7709 words. 'Copenhagan' for 'Copenhagen': near enough 'Kito' for 'Quito': wrong 'Copenahgen' for 'Copenhagen': near enough Check? The captin sailed round the iland at nite. captin: captain, cap'n, cabin iland: island, land, and nite: nine, note, bite Check? Fifteen men on the dead man's chest Every word known. Check?
What you learn
What's in it
- The same small questions
- Coins are not crates
- Each handful once
- Each handful once
- Fill a table, smallest first
- Fewest coins
- A table for two words
- Kito and nite
- How Paul pays at the Arcade
- Make the spell checker
- Ship it