/* SetLabSeg: Set st and en for label (sequence) */ void SetLabSeg(Transcription *tr) { LabList *ll = tr->head; /* use first lab list */ LLink p,q; if (tr->numLists > 1) HError(-1031,"SetLabSeg: label lists 2 to %d will be ignored", tr->numLists); if (labName != NULL) { /* extract labName */ if (auxLab==0) { p = GetCase(ll,labName,labRep); st = p->start; en = p->end; } else { p = GetAuxCase(ll,labName,labRep,auxLab); st = p->start; en = AuxLabEndTime(p,auxLab); } } else { /* extract labstidx to labenidx */ if (auxLab==0){ FixLabIdxs(CountLabs(ll)); p = GetLabN(ll,curstidx); q = GetLabN(ll,curenidx); st = p->start; en = q->end; }else{ FixLabIdxs(CountAuxLabs(ll,auxLab)); p = GetAuxLabN(ll,curstidx,auxLab); q = GetAuxLabN(ll,curenidx,auxLab); st = p->start; en = AuxLabEndTime(q,auxLab); } } if(trace & T_SEGMENT) printf("Extracting %8.0f to %8.0f\n",st,en); }
/* GatherStats: update stats using given label file */ void GatherStats(Transcription *t) { LLink l; LabList *ll; WordInfo *lt; int i,j,st,en,lab,in[ASIZE]; float dur; AEntry *ae; ll=GetLabelList(t,1); st=1; en=CountLabs(ll); /* If first label is enterId then we need to skip it */ l = GetLabN(ll,1); if (l->labid==enterId) st++; /* If the final label is exitId then it should be skipped */ l = GetLabN(ll,en); if (l->labid==exitId) en--; /* Coerce previous labels to be enterId */ for (i=0; i<ASIZE; i++) in[i]=(int)enterId->aux; lt = lTab+(int)enterId->aux; ++lt->count; /* Process actual labels in list */ for (i=st; i<=en; i++) { l = GetLabN(ll,i); lab=(int)l->labid->aux; dur = (float)(l->end - l->start)/10000.0; lt=lTab+lab; /* increment stats */ lt->count++; lt->sumDur += dur; if (dur < lt->minDur) lt->minDur=dur; if (dur > lt->maxDur) lt->maxDur=dur; lt->pCntr->count++; if (doBigram) { /* We ignore all transitions into enterId and exitId */ /* May wish to warn user about badly formed sentences */ if (!(lab==(int)enterId->aux || (lab==(int)exitId->aux))) { for (j=ASIZE-1;j>0;j--) in[j]=in[j-1]; in[0]=lab; ae = GetAEntry(in,TRUE); ae->count++; } } } /* Deal with transition into EXIT */ if (doBigram) { for (j=ASIZE-1;j>0;j--) in[j]=in[j-1]; in[0]=(int)exitId->aux; ae = GetAEntry(in,TRUE); ae->count++; } lt = lTab+(int)exitId->aux; ++lt->count; }
/* WriteStateDurations: output state duration to file */ void WriteStateDurations(char *labfn, GenInfo * genInfo) { char fn[MAXFNAMELEN]; int i, j, k, s, cnt, nState, modeldur; float modelMean; Label *label; FILE *durfp; Vector mean = NULL; Boolean isPipe; /* open file pointer for saving state durations */ MakeFN(labfn, genDir, durExt, fn); if ((durfp = FOpen(fn, NoOFilter, &isPipe)) == NULL) HError(9911, "WriteStateDurations: Cannot create output file %s", fn); /* prepare mean vector */ mean = CreateVector(genInfo->genMem, genInfo->maxStates); for (i = 1; i <= genInfo->labseqlen; i++) { label = GetLabN(genInfo->labseq->head, i); nState = genInfo->hmm[i]->numStates - 2; /* compose mean vector of the i-th state duration model */ for (s = cnt = 1; s <= genInfo->dset->swidth[0]; s++) { for (k = 1; k <= genInfo->dset->swidth[s]; k++, cnt++) mean[cnt] = genInfo->dm[i]->svec[2].info->pdf[s].info->spdf.cpdf[1].mpdf->mean[k]; } modeldur = 0; modelMean = 0.0; for (j = 1; genInfo->sindex[i][j] != 0; j++) { /* output state duration */ fprintf(durfp, "%s.state[%d]: duration=%d (frame), mean=%e\n", label->labid->name, genInfo->sindex[i][j], genInfo->durations[i][j], mean[genInfo->sindex[i][j] - 1]); fflush(durfp); if (trace & T_DUR) { printf("%s.state[%d]: duration=%d (frame), mean=%e\n", label->labid->name, genInfo->sindex[i][j], genInfo->durations[i][j], mean[genInfo->sindex[i][j] - 1]); fflush(stdout); } modeldur += genInfo->durations[i][j]; modelMean += mean[genInfo->sindex[i][j] - 1]; } fprintf(durfp, "%s: duration=%d (frame), mean=%e\n", label->labid->name, modeldur, modelMean); fflush(durfp); if (trace & T_DUR) { printf("%s: duration=%d (frame), mean=%e\n", label->labid->name, modeldur, modelMean); fflush(stdout); } } /* dispose mean vector */ FreeVector(genInfo->genMem, mean); /* close file pointer for saving state durations */ FClose(durfp, isPipe); return; }