コード例 #1
0
ファイル: HLStats.c プロジェクト: botonchou/AlgoFinal
int main(int argc, char *argv[])
{
   char * labFn, *listfn, *s;
   int i,fidx;
   MLFEntry *me = NULL;
   Transcription *t;
   void InitStats(char *listfn);
   void GatherStats(Transcription *t);
   void OutputStats(void);

   if(InitShell(argc,argv,hlstats_version,hlstats_vc_id)<SUCCESS)
      HError(1300,"HLStats: InitShell failed");

   InitMem();   InitMath();
   InitWave();  InitLabel();
   InitLM();

   if (!InfoPrinted() && NumArgs() == 0)
      ReportUsage();
   if (NumArgs() == 0) Exit(0);
   SetConfParms();
   
   enterId=GetLabId("!ENTER",TRUE); /* All sentences should or are coerced */
   exitId=GetLabId("!EXIT",TRUE);   /*  to start enterId and end exitId */
   nullId=GetLabId("!NULL",TRUE);  /* Name for words not in list */

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(1319,"HLStats: Bad switch %s; must be single letter",s);
      switch(s[0]){
      case 'b':
         doBigram = TRUE;
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: Ngram output file name expected");
         bigFile = GetStrArg();
         break;
      case 'c':
         doLCount = TRUE;
         lCountLimit = GetChkedInt(0,100000,s);
         break;
      case 'd':
         doDurs = TRUE; break;
      case 'f':
         bigFloor = GetChkedFlt(0.0,1000.0,s);
         break;
      case 'h':
         hSize =  GetChkedInt(1,2,s);
         break;
      case 'l':
         doList = TRUE; 
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: Output label list file name expected");
         listFile = GetStrArg();
         break;
      case 'o':
         doBOff = TRUE;
         break;
      case 'p':
         doPCount = TRUE;
         pCountLimit = GetChkedInt(0,100000,s);
         break;
      case 's':
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: ENTER label name expected");
         enterId=GetLabId(GetStrArg(),TRUE);
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: EXIT label name expected");
         exitId=GetLabId(GetStrArg(),TRUE);
         break;
      case 't':
         bigThresh = GetChkedInt(0,100,s);
         break;
      case 'u':
         uniFloor = GetChkedFlt(0.0,1000.0,s);
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: Input label File format expected");
         if((ff = Str2Format(GetStrArg())) == ALIEN)
            HError(-1389,"HLStats: Warning ALIEN Label file format set");
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(1319,"HLStats: Input MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'T':
         if (NextArg() != INTARG)
            HError(1319,"HLStats: Trace value expected");
         trace = GetChkedInt(0,017,s); break;
      default:
         HError(1319,"HLStats: Unknown switch %s",s);
      }
   }

   if (NextArg()!=STRINGARG)
      HError(1319,"HLStats: Label list file name expected");
   listfn = GetStrArg();
   if (!(doDurs || doBigram || doList || doLCount || doPCount))
      HError(1330,"HLStats: Nothing to do!");
   InitStats(listfn);

   i=0;
   while (NumArgs()>0) {
      if (NextArg()!=STRINGARG)
         HError(1319,"HLStats: Input label file name expected");
      labFn = GetStrArg();
      if (IsMLFFile(labFn)) {
         fidx = NumMLFFiles();
         if ((me=GetMLFTable()) != NULL) {
            while(me->next != NULL) me=me->next;
            LoadMasterFile(labFn);
            me=me->next;
         }
         else {
            LoadMasterFile(labFn);
            me=GetMLFTable();
         }
         while (me != NULL) {
            if (me->type == MLF_IMMEDIATE && me->def.immed.fidx == fidx) {
               if (trace&T_FIL) {
                  printf("  Processing file %s\n",me->pattern); fflush(stdout);
               }
               t = LOpen(&tmpHeap,me->pattern,ff);
               if (t->numLists<1)
                  HError(-1330,"HLStats: Empty file %s",me->pattern);
               else
                  GatherStats(t),i++;

               Dispose(&tmpHeap,t);
            }
            me = me->next;
            if ((trace&T_BAS) && !(trace&T_FIL) &&
                NumMLFEntries()>5000 && i%1000==0) 
               printf(". "),fflush(stdout);
         }
         if ((trace&T_BAS) && !(trace&T_FIL) && NumMLFEntries()>5000)
            printf("\n");
      } else {
         if (trace&T_FIL) {
            printf("  Processing file %s\n",labFn); fflush(stdout);
         }
         t = LOpen(&tmpHeap,labFn,ff);
         if (t->numLists<1)
            HError(-1330,"HLStats: Empty file %s",me->pattern);
         else
            GatherStats(t),i++;
         Dispose(&tmpHeap,t);
      }
   }
   if (trace&T_MEM)
      PrintAllHeapStats();
   OutputStats();

   if (trace&T_MEM)
      PrintAllHeapStats();
   Exit(0);
   return (0);          /* never reached -- make compiler happy */
}
コード例 #2
0
ファイル: LPlex.c プロジェクト: DorisGao/personal-uni
/* ProcessFiles: process label files */
static void ProcessFiles()
{
   int nSize;
   char *labFn;
   MLFEntry *me;
   char *inpfn[MAX_FILES];
   int i,t,numFiles,fidx;

   numFiles = 0;
   while (NumArgs()>0){
      if (NextArg()!=STRINGARG)
	HError(16619,"ProcessFiles: label file (MLF) name expected");
      inpfn[numFiles++] = CopyString(&gstack, GetStrArg());

      if (numFiles == MAX_FILES) {
	 HError(-16619,"Processing only the first %d files",MAX_FILES);
      }
   }

   for (t=0; t<numTests; t++) {
      ZeroStats(&totl);
      nSize = testInfo[t];
      printf("LPlex test #%d: %d-gram\n", t, nSize);
      if (numFiles==0) {
	 ProcessTextStream(NULL, nSize);
	 continue;
      }

      for (i=0; i<numFiles; i++) {
	 labFn = inpfn[i];
	 if (streamMode) {
	    ProcessTextStream(labFn,nSize);
	 } else {
	    if (IsMLFFile(labFn)) {
	       if (trace>0) {
		  printf("Processing MLF: %s\n", labFn);
		  fflush(stdout);
	       }
	       fidx = NumMLFFiles();
	       if ((me=GetMLFTable()) != NULL) {
		  while(me->next != NULL) me=me->next;
		  LoadMasterFile(labFn);
		  me=me->next;
	       }
	       else{
		  LoadMasterFile(labFn);
		  me=GetMLFTable();
	       }
	       while (me != NULL) {
		  if (me->type == MLF_IMMEDIATE && me->def.immed.fidx == fidx) {
		     ProcessLabelFile(me->pattern,nSize);
		  }
		  me = me->next;
	       }
	    } else {
	       ProcessLabelFile(labFn,nSize);
	    }
	 }
      }
      PrintInfo(&totl, printOOV);
   }
}