spellingCorrectorobject | spelling.t[9] |
Superclass Tree | Property Summary | Method Summary | Property Details | Method Details |
spellingCorrector : object
checkSpacing
correct
correctPairSpacing
findUnknownWord
getCandidates
isWordDefined
dict | spelling.t[289] |
checkSpacing (toks, idx, err) | spelling.t[155] |
Note that all spacing changes have edit distance 1. All of our corrections are single character insertions or deletions, or pair transpositions (which we count as one edit).
correct (toks, idx, err) | spelling.t[62] |
'toks' is a token list to be corrected, and 'idx' is the index of the first unknown word. 'err' is ParseError that triggered the spelling check. We use the error to filter the list of candidates for corrected spellings: for a general verb syntax error, for example, we'll look for words that are used in verb phrases, and for noun resolution we'll look for words associated with in-scope objects.
If we fail to find a correction, the return value is nil.
If we find a correction, the return value is a list of token lists. It's a list rather than a single correction because we might be unable to break a tie; rather than picking one arbitrarily, we return all of the candidates. This allows the caller to try the different possibilities. The caller will generally have more information than we have here about the overall context, so it's in a better position to make a final judgment about how to break a tie.
Note that we only correct a single error per call. If the token list has additional unknown words, the caller can continue parsing and call here again to get candidate corrections for the next word, and so on until all unknown words are resolved. We use this iterative approach because the first correction might change the parser's guess about where the error lies; by waiting, we get the benefit of the revised context information for correcting each additional word.
correctPairSpacing (toks, idx) | spelling.t[218] |
findUnknownWord (toks) | spelling.t[14] |
getCandidates (w) | spelling.t[301] |
isWordDefined (w) | spelling.t[295] |