⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hled.c

📁 Hidden Markov Toolkit (HTK) 3.2.1 HTK is a toolkit for use in research into automatic speech recogn
💻 C
📖 第 1 页 / 共 3 页
字号:
   if (sortFirst)       printf("Sort (initial)\n");   if (levSplit)      printf("Split levels into lists\n");   for (i=script, j=1; i != NULL; i = i->next,j++) {      printf("%2d. ",j);      src = *(i->cmd.args);      switch (i->cmd.op) {      case TRIST:         printf("Toggle TriStripping\n");         break;      case SORT:         printf("Sort\n");          break;      case EDOP_DELETE:         printf("Delete  ["); PrintIdList(i->cmd.args); printf(" ]\n");         break;      case REPLACE:         printf("Replace ["); PrintIdList(i->cmd.args+1);         printf(" ] by %s\n",src->name);         break;      case CHANGE:         printf("Change  ["); PrintIdList(i->cmd.args+1);         printf(" ] by %s\n",src->name);         break;      case FIND:         printf("Find  ["); PrintIdList(i->cmd.args);          printf(" ]\n");         break;      case EXPAND:         printf("Expand\n");         break;      case IFILL:         printf("FillGap  ["); PrintIdList(i->cmd.args);          printf(" ]\n");         break;      case ISIL:         printf("InSil  ["); PrintIdList(i->cmd.args);          printf(" ]\n");         break;      case MERGE:         printf("Merge   ["); PrintIdList(i->cmd.args+1);         printf(" ] to %s\n",src->name);         break;      case LCTXT:         printf("Left Context ["); PrintIdList(i->cmd.args);         printf(" ]\n");         break;      case RCTXT:         printf("Right Context ["); PrintIdList(i->cmd.args);         printf(" ]\n");         break;      case TCTXT:         printf("Triphonise ["); PrintIdList(i->cmd.args);         printf(" ]\n");         break;      case SETLEV:         printf("Set Level to %d\n",(int)i->cmd.args[0]->aux);         break;      case DELLEV:         if (i->cmd.nArgs==1)            printf("Delete Level %d\n",(int)i->cmd.args[0]->aux);         else            printf("Delete Current Level\n");         break;      default: break;      }   }}/* ---------------------- Read Script ---------------------- *//* CmdIndex: return index 1..N of given command */int CmdIndex(char *s){   int i;   if (s[1] == ' ') {      for (i=1; i<=n1Cmds; i++)         if (oldmap[i] == s[0]) return i;   } else {      for (i=1; i<=nCmds; i++)         if (strcmp(cmdmap[i],s) == 0) return i;   }   return -1;}/* ReadCmd: returns next command in src or NOCMD if none */EdOp ReadCmd(Source *src){   char s[3],buf[MAXSTRLEN];   int cmdidx;      SkipComment(src);   SkipWhiteSpace(src);   if (!ReadString(src,buf)) return(NOCMD);   s[0]=buf[0]; s[1] = isalnum((int) buf[1])?buf[1]:' '; s[2]='\0';   if (trace&T_EDIN)      printf(" input cmd   '%s'\n",s);   cmdidx = CmdIndex(s);   if (cmdidx<0)      HError(1230,"ReadCmd: Unknown command %s at %s",             s,SrcPosition(*src,buf));   return (EdOp)cmdidx;}/* ReadLabId: Read a label from the current line, return NULL if none */LabId ReadLabId(Source *src){   char buf[MAXSTRLEN];      SkipWhiteSpace(src);   if (src->wasNewline) return NULL;   if (ReadString(src,buf)){      if (trace&T_EDIN)         printf(" input label '%s'\n",buf);      return GetLabId(buf,TRUE);   } else      HError(1230,"ReadLabId: string arg expected at %s",             SrcPosition(*src,buf));   return(NULL);}/* ReadIdList: Read a list of args and store in argList, return num args */int ReadIdList(Source *src,LabId *argList){   int count = 0;   LabId id;      id = ReadLabId(src);   while (id != NULL) {      *argList++ = id; ++count;      id=ReadLabId(src);   }   *argList = NULL;   return count;  }/* ReadScript: read a file of script commands and store them in script */void ReadScript(char *scriptFn){   Source src;    ScriptItem *i, *tail=NULL;   EdOp op;   LabId id,args[MAXARGS];   int n,nArgs;   if(InitSource(scriptFn, &src, NoFilter)<SUCCESS)      HError(1210,"ReadScript: Can't open file %s", scriptFn);   script = NULL;   while (TRUE) {      if ((op = ReadCmd(&src)) == NOCMD) break;      if (op == DEFCON){         id = ReadLabId(&src);         nArgs = ReadIdList(&src,args);         DefineContext(id,args,nArgs);         continue;      }      if (op == WBDEF) {         if (nWB == MAXIW)            HError(1231,"ReadScript: too many W commands");         id = ReadLabId(&src);         wbnd[nWB++] = id;         continue;      }      if (op == VBDEF) {         if (nVB == MAXIV)            HError(1231,"ReadScript: too many V commands");         id = ReadLabId(&src);         vbnd[nVB++] = id;         continue;      }      if (op == SBDEF) {         sentMarker = ReadLabId(&src);         if (trace&T_RDSC)            printf("Sentence marker is '%s'\n",sentMarker->name);         continue;      }      if (op == SPLLEV) {         levSplit=TRUE;         if (trace&T_RDSC)            printf("Splitting levels for output\n");         continue;      }      if (op == SORT && script==NULL) {         sortFirst=TRUE;         if (trace&T_RDSC)            printf("Initial sort enabled\n");         continue;      }      i = (ScriptItem *)New(&permHeap,sizeof(ScriptItem));      i->cmd.op = op;      switch (op) {      case EDOP_DELETE:      case REPLACE:      case MERGE:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         break;      case CHANGE:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs != 4)            HError(1230,"ReadScript: CH must have 4 arguments");         break;         case FIND:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs != 3)            HError(1230,"ReadScript: FI must have 3 args");         MakeFindAccumulator(i->cmd.args);         break;         case LCTXT:      case RCTXT:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs > 1)            HError(1230,"ReadScript: LC/RC command has too many args");         break;      case TCTXT:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs > 2)            HError(1230,"ReadScript: TC command has too many args");         break;      case IFILL:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs != 1)            HError(1230,"ReadScript: FG must have 1 arg");         break;         case ISIL:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs != 2)            HError(1230,"ReadScript: IS must have 2 args");         break;         case SETLEV:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs!=1 ||              (n=(int)i->cmd.args[0]->aux)<1 || n>99 )            HError(1230,"ReadScript: ML must have 1 arg between 1 and 99");                   break;         case DELLEV:         i->cmd.nArgs = ReadIdList(&src,i->cmd.args);         if (i->cmd.nArgs>1)            HError(1230,"ReadScript: DL can have at most 1 arg");         if (i->cmd.nArgs==1 &&              ((n=(int)i->cmd.args[0]->aux)<1 || n>99) )            HError(1230,"ReadScript: DL arg must be between 1 and 99");                    break;         case SORT:      case EXPAND:      case TRIST:         break;      default: break;      }      i->next = NULL;      if (tail==NULL)         script = tail = i;      else {         tail->next = i;         tail = i;      }   }   CloseSource(&src);   if (trace&T_RDSC){      PrintContexts();      PrintWBounds();      PrintVBounds();      PrintScript(scriptFn);   }}/* ----------------------- Misc Operations -------------------- *//* NumParts: return number of parts in a label of form A_B_C  or    the number of phones in the dictionary entry as appropriate */int NumParts(LabId id){   Word word;   char buf[MAXSTRLEN], *s;   int count=1;      if (dictFn!=NULL) {      if ((word = GetWord(&vocab,id,FALSE))==NULL)         HError(1232,"NumParts: Cannot find word %s in dictionary",id->name);      if (word->pron==NULL || word->pron->nphones==0)         HError(1232,"NumParts: Word %s does not have valid pronunciation",id->name);      count = word->pron->nphones;      if (trace&T_DIC)         printf("NumParts: word %s has %d parts\n",id->name,count);   }   else {      strcpy(buf,id->name);      while ((s = strchr(buf,'_')) != NULL) {         ++count; *s = ' ';      }   }   return count;}/* GetPart: return n'th part of a label of form A_B_C   or      the n'th phone in the dictionary entry as appropriate */LabId GetPart(LabId id, int n){   Word word;   char buf[MAXSTRLEN], *s, *t;   int i;   LabId pid;      if (dictFn!=NULL) {      if ((word = GetWord(&vocab,id,FALSE))==NULL)         HError(1290,"GetPart: Cannot find word %s in dictionary",id->name);      if (word->pron==NULL || word->pron->nphones<n)         HError(1290,"GetPart: Word %s does not have valid phone %d",id->name,n);      pid = word->pron->phones[n-1];      if (trace&T_DIC)         printf("GetPart: %d'th part of word %s is %s\n",n,id->name,pid->name);      return(pid);   }   else {      strcpy(buf,id->name);      i = 1; s= buf;      while (i<n && (s = strchr(s,'_')) != NULL) {         ++i; ++s;      }      if (s==NULL)         HError(1290,"GetPart: cant find %d leading _'s in %s",n-1,buf);      if ((t = strchr(s,'_')) != NULL)          *t = '\0';      return GetLabId(s,TRUE);   }}/* ----------------------- Edit Operations -------------------- *//* TrOpEntry: trace entry to named operation */void TrOpEntry(char *name){   printf(" -> %s",name);}/* TrOpExit: trace exit from current operation */void TrOpExit(int count){   if (count >= 0) printf(" %d items",count);   printf("\n");  fflush(stdout);}/* IsSame: return true if given ids are identical */Boolean IsSame(LabId a, LabId b){   char buf[MAXSTRLEN];   if (a==NULL || b==NULL) return(FALSE);   if (triStrip) {      strcpy(buf,a->name); TriStrip(buf); a = GetLabId(buf,TRUE);      strcpy(buf,b->name); TriStrip(buf); b = GetLabId(buf,TRUE);   }   return a==b;}/* IsInIdList: return true if id is in idlist */Boolean IsInIdList(LabId id, LabId *idlist){   if (id!=NULL)      while (*idlist != NULL) {         if (IsSame(id,*idlist)) return TRUE;         ++idlist;      }   return FALSE;}/* SeqMatch: returns true if labels i,i+1,i+2,... match idList */LLink SeqMatch(LLink l,int numIds, LabId *idList){   int j;      for (j=0; j<numIds;j++,l=l->succ)      if (*idList++ != l->labid || l->succ==NULL) {         return(NULL);      }   return l;}/* DeleteOp: scan the current transcription and delete any items   in args,  returns number of deletions performed */int DeleteOp(LabList *ll,LabId *args){   LLink l;   int count=0;      if (trace&T_CMDX) TrOpEntry("DE(lete");   for (l=ll->head->succ; l->succ!=NULL; l=l->succ)      if (IsInIdList(l->labid,args)) {         ++count;         DeleteLabel(l);      }   if (trace&T_CMDX) TrOpExit(count);   return count;}/* ReplaceOp: scan the current transcription and replace any   items in args[1..] with arg[0],  returns the number of   replaces performed */int ReplaceOp(LabList *ll,LabId *args){   LabId item;   LLink l;   int count=0;      if (trace&T_CMDX) TrOpEntry("RE(place");   item = *args++;   for (l=ll->head->succ; l->succ!=NULL; l=l->succ)      if(IsInIdList(l->labid,args)) {         ++count;         l->labid = item;      }   if (trace&T_CMDX) TrOpExit(count);   return count;}/* InContext: Match Context (lc-x+rc) against label l */Boolean InContext(LLink l, LabId *lc, LabId *rc, LabId item){   if (l->succ==NULL || l->pred==NULL)      HError(1291,"InContext: trying to match sentinel");   if (!IsSame(l->labid,item)) return FALSE;   /* Check left context - 1st label is a special case */   if (l->pred->labid == NULL ){      if (lc != NULL && !IsInIdList(sentMarker,lc)) return FALSE;   } else {      if (lc != NULL && !IsInIdList(l->pred->labid,lc)) return FALSE;   }   /* Check right context - last label is a special case */   if (l->succ->labid == NULL) {      if (rc != NULL && !IsInIdList(sentMarker,rc)) return FALSE;   } else {      if (rc != NULL && !IsInIdList(l->succ->labid,rc)) return FALSE;   }   return TRUE;}/* ChangeOp: scan the current transcription and replace any    items which match the context given by args[1..3] with arg[0],   returns number of changes performed.  A sequence of CH cmds is   executed simultaneously by making changes to a copy.  ChangeOp is   called with NULL args to terminate and update any pending changes */int ChangeOp(LabList *ll,LabId *args){   int i,count=0;   LabId *lc,*rc,newId;   static LabList *tl;   LLink l,t;   if (ll==NULL) {      /* end of change sequence */      tl=NULL;  return 0;   } else      if (tl==NULL)        /* first change so clone transcription */         tl = CopyLabelList(&tempHeap, ll);   if (trace&T_CMDX) TrOpEntry("CH(ange");   newId = *args++;   lc = (*args==asterix)?NULL:GetContext(*args);   rc = (*(args+2)==asterix)?NULL:GetContext(*(args+2));   if (trace&T_CHOP){      printf("  Left  context="); if (lc!=NULL) PrintIdList(lc);      printf("\n  Right context="); if (rc!=NULL) PrintIdList(rc);      printf("\n");   }   i=0;   for (l=ll->head->succ,t=tl->head->succ; l->succ!=NULL;        l=l->succ,t=t->succ) {      if (trace&T_CHOP)          printf("  %d. checking %s",++i,t->labid->name);      if(InContext(t,lc,rc,*(args+1))) {         ++count;         l->labid = newId;         if (trace&T_CHOP) printf(" replaced by %s\n",newId->name);      } else         if (trace&T_CHOP) printf("\n");   }   if (trace&T_CMDX) TrOpExit(count);   return count;}/* FindOp: scan the current transcription and count any   items which match the context given by args[0..2] */void FindOp(LabList *ll,LabId *args){   LLink l;   int *acc;   LabId *lc,*rc;   if (trace&T_CMDX) TrOpEntry("FI(nd");   acc = GetFindAccumulator(args);   lc = (*args==asterix)?NULL:GetContext(*args);   rc = (*(args+2)==asterix)?NULL:GetContext(*(args+2));      for (l=ll->head->succ; l->succ!=NULL; l=l->succ)      if(InContext(l,lc,rc,*(args+1)))         ++(*acc);   if (trace&T_CMDX) TrOpExit(-1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -