home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / utils / sondxspl.sh < prev    next >
Encoding:
Text File  |  1989-03-21  |  1.9 KB  |  61 lines

  1. From riacs!eos!agate!bionet!bloom-beacon!tut.cis.ohio-state.edu!mailrus!rutgers!rochester!udel!princeton!siemens!demon!fwb Wed Jan 18 08:20:47 PST 1989
  2.  
  3. The Soundex routine <19090@agate.BERKELEY.EDU> posted by Dean Pentcheff
  4. (dean@violet.berkeley.edu) can be made into a simple spelling corrector.  I
  5. did this to play around with his routine, and thought others might find it
  6. amusing.  There is probably a better method for making a spelling
  7. corrector, but this was fun.
  8.  
  9. Copyright?  Nah.
  10.  
  11. Step 1.  Modify Dean's program to print the soundex code along with the
  12.      input string.  Replace the printf statement with:
  13.  
  14.         printf("%s %s", soundex(instring), instring);
  15.  
  16.      Remember to remove the \n in the original format string!
  17.  
  18. Step 2.     Compile soundex.c
  19.  
  20.         cc -O -DTESTPROG soundex.c -o soundex
  21.  
  22. Step 3.  [Optional] Compute and store soundex values for all words in
  23.      /usr/dict/words
  24.  
  25.         soundex < /usr/dict/words | sort > words.soundex
  26.  
  27. Step 4.  Cut out the following shell script.  Make it executable, and have
  28.      fun.
  29.  
  30. #------------- cut here for mispel -----------------
  31. #! /bin/sh
  32. # A simple spelling corrector.
  33. # Usage:
  34. #   mispel word
  35. #
  36. # All words from the system dictionary with the same soundex code as word
  37. # are printed to the standard output.
  38.  
  39. DICT=/WHERE/THIS/LIVES/words.soundex
  40. SOUNDEX=/WHERE/THAT/LIVES/soundex
  41.  
  42. # calculate the soundex value for the input word and put it in $1
  43. set `echo $1 | $SOUNDEX`
  44.  
  45. # did you cache the soundex dictionary?
  46. if [ -f $DICT ]; then
  47.     # look up the word in the cached dictionary
  48.     look -d $1 $DICT | awk '{ print $2 }'
  49. else
  50.     # calculate the soundex value for the system dictionary and print 
  51.     # all words which match the input word
  52.     $SOUNDEX < /usr/dict/words | fgrep $1 | awk '{ print $2 }'
  53. fi
  54. #------------- end of mispel -----------------
  55.  
  56. --
  57. Frederic W. Brehm    Siemens Corporate Research    Princeton, NJ  
  58. fwb@demon.siemens.com    -or-    ...!princeton!siemens!demon!fwb
  59.  
  60.  
  61.