home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / MiniExamples / IndexingKit / LanguageReader / ReaderDomain / IXFrenchReader.m < prev    next >
Encoding:
Text File  |  1993-06-10  |  1.6 KB  |  57 lines

  1. /*
  2.  * IXFrenchReader.m
  3.  *
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  6.  * fitness for any particular use.
  7.  *
  8.  * Written by: Mai Nguyen, NeXT Developer Support
  9.  *
  10.  * Note that the example only shows what steps are needed in order
  11.  * to build a reader. It doesn't take into account the French language
  12.  * semantics in order to build a useful reader for the French language. 
  13.  * This exercise is left to the native French readers (no pun!).
  14.  */
  15.  
  16.  
  17. #import    <ansi/ansi.h>
  18. #import    "IXFrenchReader.h"
  19.  
  20. #define    CLASSVERSION     1
  21.  
  22. @implementation IXFrenchReader
  23.  
  24. + initialize
  25. {
  26.     if (self != [IXFrenchReader class]) return self;
  27.     return [[super initialize] setVersion:CLASSVERSION];
  28. }
  29.  
  30. /* This method simplifies plural words. For example, words like 'maisons',
  31.  * 'midis',  'papas', 'mademoiselles' etc. can be reduced to their singular
  32.  * form: 'maison', 'midi', 'papa', 'mademoiselle'. 
  33.  * This method can be made much more sophisticated to handle other forms of
  34.  * French plurals such as 'animaux' --> 'animal', etc.
  35.  */
  36. - (unsigned)foldPlural:(char *)string inLength:(unsigned)length
  37. {
  38.     unsigned theLength;
  39.  
  40.     if ((theLength = strlen(string)) < 3 || string[theLength - 1] != 's')
  41.     return theLength;
  42.  
  43.     switch(string[theLength - 2])
  44.     {
  45.     case 's': case '\'': break;
  46.     case 'e': case 'i': case 'u': case 'a': case 'o': case 'n': case 'l':
  47.         string[theLength = theLength - 1] = '\0';
  48.         break;
  49.     default: string[theLength = theLength - 1] = '\0';
  50.     }
  51.  
  52.     return theLength;
  53. }
  54.  
  55. @end
  56.  
  57.