[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Spell Features from function level



Here's a function you can use to see if a word is in any of a set of
dictionaries.  The first argument is a string, and the second is a list
of dictionary instances.  If the word is not found, it returns nil.  If
the word is found, it returns the first dictionary that contains the
word.  If the word cannot be represented in a dictionary, it returns t.

(defun lookup-word-in-dictionaries (word dictionaries)
  (condition-case ()
       (spell:encode-string
	 word
	 (length word)
	 #'(lambda (ignore list n-bytes hash)
	     (or (< n-bytes 2)
		 (dolist (dictionary dictionaries)
		   (when (spell:lookup-word dictionary list n-bytes hash)
		     (return dictionary)))))
	 nil)
     (spell:cannot-encode t)))

Here's a function for reading a dictionary file into a dictionary instance:

(defun read-dictionary-file (pathname)
  (with-open-file (stream pathname :element-type :default)
    (funcall (if (send stream :characters)
		 #'spell:read-character-dictionary
		 #'spell:read-binary-dictionary)
	     stream pathname)))

Here's a function to get the corrected versions of a word:

(defun get-corrections (word dictionaries)
  (delete-duplicates
    (loop for dictionary in dictionaries
	  nconc (spell:get-list-of-corrections dictionary word))
    :test #'string-equal))