Measure what a spell checker catches and what it cannot see
word processing
spell checking
workforce research
Learn how hunspell flags unknown workforce words and how to test constructed spelling errors.
A vocabulary list is almost ready for review. The team wants to know whether a spell checker can clean obvious typing errors before a person reads the list.
That sounds simple until the team runs into proper names and real-word typos. A dictionary can say which strings it does not know. It cannot know what the writer meant.
Spell checking here means asking hunspell for words that are absent from its dictionary. The result is a list of unknown words, not a list of all errors.
Note
The Riverton Workforce Lab, its job board, and its training flyer are fictional and were created for teaching. The deliberately misspelled words below are constructed examples made from Riverton words.
TipWhat you will learn
By the end of this lesson, you will be able to:
run hunspell() on the Riverton vocabulary;
count word types the dictionary flags;
build a small constructed spelling test;
see why a test built from known non-words cannot fail; and
explain why real-word errors escape a dictionary.
Check the real vocabulary
For the vocabulary check, readr brings in the sentences, dplyr and tibble shape the word list, purrr repeats the dictionary call, tidytext creates tokens, and hunspell supplies dictionary flags. It builds the same lowercased 96-word Riverton vocabulary as the stemming lesson, using the same tokenization rule.
Hunspell flags 2 of the 96 real word types: october and riverton. In this small vocabulary, the dictionary flags a month word under the lowercased form and a fictional place name. Those are unknown to this dictionary setting, not proved spelling mistakes.
Build a constructed error test
The next table uses eight deliberate misspellings of real Riverton word types. This is a constructed test, not a claim about how often people make these errors.
knitr::kable( spell_summary,col.names =c("Errors caught","Constructed errors","Correct words wrongly flagged","Correct words checked","Caught fraction","False flag fraction" ),caption ="Counts from the constructed spelling test",row.names =FALSE)
Counts from the constructed spelling test
Errors caught
Constructed errors
Correct words wrongly flagged
Correct words checked
Caught fraction
False flag fraction
8
8
0
8
8/8
0/8
Hunspell flags 8 of 8. That number was settled before the test ran: all eight constructed misspellings are strings that are not English words, and flagging non-words is the dictionary’s job. It falsely flags 0 of the 8 source words, which was also settled in advance because those words came from a vocabulary already shown to hold only two dictionary unknowns. This is a wiring check, not a measurement of spelling quality. The next section shows the case the eight left out.
Show the real-word limit
A dictionary will not flag a typo if the typo is also a real word. form and from are both dictionary words.
real_word_error <-tibble(intended_word ="from",typed_word ="form",intended_flagged =!known_to_hunspell(intended_word),typed_flagged =!known_to_hunspell(typed_word))knitr::kable( real_word_error,col.names =c("Intended word", "Typed word", "Intended word flagged", "Typed word flagged"),caption ="A real-word typo that dictionary lookup cannot catch",row.names =FALSE)
A real-word typo that dictionary lookup cannot catch
Intended word
Typed word
Intended word flagged
Typed word flagged
from
form
FALSE
FALSE
If a writer meant from and typed form, this dictionary reports no problem. Both strings are familiar to it, so context has to do the work.
What to remember
hunspell() returns dictionary unknowns.
Unknown does not always mean misspelled.
Checking each of the 96 word types on its own flags october and riverton.
The constructed 8/8 check is a demonstration because it contains only non-word errors.
Real-word errors need context as well as a dictionary.
Use hunspell to make a review queue, then read the queue. A dictionary can sort strings into familiar and unfamiliar; people still decide whether the sentence is right.