One suggestion is often not enough - a user wants to see the two or three most likely words. Today you rank the whole candidate tier and return the top N, so each Issue offers a short menu of the best guesses.
Return the N highest-ranked candidates for a word, ordered by frequency then alphabetically.
BestByFreq collapsed a candidate set to one winner; a good tool shows a little
more of its reasoning. SuggestN ranks the whole tier - by frequency first,
alphabetically to break ties - and returns the top n. For teh, that is the,
ten, tea, in descending commonness, so a user who did not mean the top guess can
grab the second.
This is the same ranking rule as before, just applied to produce an ordered list
rather than a single element, and it is why the tie-break was worth pinning down: a
stable sort means the menu never reshuffles between runs. The Checker now fills
each Issue’s Suggestions with SuggestN, so every flagged word arrives with its
short list of the most likely corrections instead of a lone guess.
func (d *Dictionary) SuggestN(word string, n int) []string {// take Candidates(word), sort by Count descending,// break ties alphabetically, return the first n}