Next: , Previous: , Up: Auxiliary Systems   [Contents][Index]


18.4 Spelling

Hemlock supports spelling checking and correcting commands based on the ITS Ispell dictionary. These commands use the following routines which include adding and deleting entries, reading the Ispell dictionary in a compiled binary format, reading user dictionary files in a text format, and checking and correcting possible spellings.

Function: spell:maybe-read-spell-dictionary

This reads the default binary Ispell dictionary. Users must call this before the following routines will work.

Function: spell:spell-read-dictionary filename

This adds entries to the dictionary from the lines in the file filename. Dictionary files contain line oriented records like the following:

entry1/flag1/flag2
entry2
entry3/flag1

The flags are the Ispell flags indicating which endings are appropriate for the given entry root, but these are unnecessary for user dictionary files. You can consult Ispell documentation if you want to know more about them.

Function: spell:spell-add-entry line &optional word-end

This takes a line from a dictionary file, and adds the entry described by line to the dictionary. Word-end defaults to the position of the first slash character or the length of the line. Line is destructively modified.

Function: spell:spell-remove-entry entry

This removes entry, a simple-string, from the dictionary, so it will be an unknown word. This destructively modifies entry. If it is a root word, then all words derived with entry and its flags will also be deleted. If entry is a word derived from some root word, then the root and any words derived from it remain known words.

Function: spell:correct-spelling word

This checks the spelling of word and outputs the results. If this finds word is correctly spelled due to some appropriate suffix on a root, it generates output indicating this. If this finds word as a root entry, it simply outputs that it found word. If this cannot find word at all, then it outputs possibly correct close spellings. This writes to standard-output, and it calls maybe-read-spell-dictionary before attempting any lookups.

Constant: max-entry-length val 31
Function: spell:spell-try-word word word-len

This returns an index into the dictionary if it finds word or an appropriate root. Word-len must be inclusively in the range 2 through max-entry-length, and it is the length of word. Word must be uppercase. This returns a second value indicating whether it found word due to a suffix flag, nil if word is a root entry.

Function: spell:spell-root-word index

This returns a copy of the root word at dictionary entry index. This index is the same as returned by spell-try-word.

Function: spell:spell-collect-close-words word

This returns a list of words correctly spelled that are close to word. Word must be uppercase, and its length must be inclusively in the range 2 through max-entry-length. Close words are determined by the Ispell rules:

  1. Two adjacent letters can be transposed to form a correct spelling.
  2. One letter can be changed to form a correct spelling.
  3. One letter can be added to form a correct spelling.
  4. One letter can be removed to form a correct spelling.
Function: spell:spell-root-flags index

This returns a list of suffix flags as capital letters that apply to the dictionary root entry at index. This index is the same as returned by spell-try-word.


Next: File Utilities, Previous: Slave Lisps, Up: Auxiliary Systems   [Contents][Index]