Main Page   Compound List   File List   Compound Members   File Members  

get_ngram.c

Go to the documentation of this file.
00001 /*=====================================================================
00002                 =======   COPYRIGHT NOTICE   =======
00003 Copyright (C) 1996, Carnegie Mellon University, Cambridge University,
00004 Ronald Rosenfeld and Philip Clarkson.
00005 
00006 All rights reserved.
00007 
00008 This software is made available for research purposes only.  It may be
00009 redistributed freely for this purpose, in full or in part, provided
00010 that this entire copyright notice is included on any copies of this
00011 software and applications and derivations thereof.
00012 
00013 This software is provided on an "as is" basis, without warranty of any
00014 kind, either expressed or implied, as to any matter including, but not
00015 limited to warranty of fitness of purpose, or merchantability, or
00016 results obtained from use of this software.
00017 ======================================================================*/
00018 /* Function to read in a n-gram from the file specified */
00019 
00020 /* Returns zero if we have reached eof */
00021 
00022 #include <stdio.h>
00023 #include <stdarg.h>
00024 #include "rr_libs/general.h"
00025 #include "ngram.h"
00026 
00031 int get_ngram(FILE *id_ngram_fp, ngram *ng, flag ascii) {  
00032 
00033   int i;
00034 
00035   if (ascii) {
00036 
00037     for (i=0;i<=ng->n-1;i++) {
00038       if (fscanf(id_ngram_fp,"%hu",&ng->id_array[i]) != 1) {
00039         if (rr_feof(id_ngram_fp)) {
00040           return 0;
00041         }
00042         quit(-1,"Error reading from id_ngram file.\n");
00043       }
00044     }
00045     if (fscanf(id_ngram_fp,"%d",&ng->count) != 1) {
00046       if (rr_feof(id_ngram_fp)) {
00047         return 0;
00048       }
00049       quit(-1,"Error reading from id_ngram file.2\n");
00050     }
00051   }
00052   else {
00053 
00054     /* Read in array of ids */
00055 
00056     /* Read in one at a time - slower, but spares us having to think 
00057        about byte-orders. */
00058     
00059     for (i=0;i<=ng->n-1;i++) {
00060       if (rr_feof(id_ngram_fp)) {
00061         return 0;
00062       }
00063       rr_fread(&ng->id_array[i],sizeof(id__t),1,id_ngram_fp,
00064                "from id_ngram file",0);
00065     }
00066 
00067     /* Read in count */
00068     if (rr_feof(id_ngram_fp)) {
00069       return 0;
00070     }
00071     rr_fread(&ng->count,sizeof(count_t),1,id_ngram_fp,
00072              "count from id_ngram file",0);
00073 
00074   }
00075 
00076   return 1;
00077   
00078 }
00079 
00080 
00081 

Generated on Tue Dec 21 13:54:45 2004 by doxygen1.2.18