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

  1. /*
  2.  * ReaderDomain.m: 
  3.  * This file is used to generate programmatically a .domain file     
  4.  * to be used with the FrenchReader miniexample.
  5.  * The FrenchText file must be fed into the attribute parser. It is supposed
  6.  * to be the most representative sample of the French language. For the purpose
  7.  * of this example, a random French text has been chosen. 
  8.  *
  9.  * Written by Mai Nguyen, NeXT Developer Support
  10.  * June 1993
  11.  */
  12.  
  13. #import <indexing/indexing.h>
  14. #import <streams/streams.h>
  15. #import <libc.h>
  16. #import "IXFrenchReader.h"
  17.  
  18. void main() {
  19.     IXFrenchReader*    theReader;
  20.     IXAttributeParser*    theParser;
  21.     IXWeightingDomain*    theDomain;
  22.     List *        aList;
  23.     int fd;             /* file descriptor */
  24.     NXStream *stream = NULL;
  25.     BOOL saveOK;
  26.  
  27.         /* Set up a French Reader and a Parser */
  28.     theReader = [[IXFrenchReader alloc] init];
  29.     theParser = [[IXAttributeParser alloc] init];
  30.     aList = [[List alloc] init];
  31.     [aList addObject:theReader];
  32.     [theParser setAttributeReaders:aList];
  33.         /* Parse a representative French text file to generate the
  34.          * histogram. Note that the FrenchText file in this example
  35.          * is NOT at all representative of the French language, but
  36.          * is only used for testing purposes.
  37.          */
  38.     [theParser parseFile:"FrenchText" ofType:"ASCII"];
  39.     
  40.  
  41.      if (saveOK = 
  42.         (((fd = open ("French.domain", O_WRONLY|O_CREAT|O_TRUNC, 0644)) != -1) &&
  43.         (stream = NXOpenFile (fd, NX_WRITEONLY))))
  44.         theDomain = [[[IXWeightingDomain alloc]
  45.                 initFromAttributeParser:theParser] writeDomain:stream];
  46.         if (stream) NXClose (stream);
  47.      if (fd != -1) close (fd);
  48.  
  49.      if (saveOK)
  50.          printf("Domain file successfully created\n");
  51.     else
  52.         printf("Domain file can't be created\n");
  53.  
  54.     
  55.     exit(0);
  56.    }
  57.