Esempio n. 1
0
void LabelMap::RegisterLabel(const std::string& label, u16 lval, LabelType type)
{
  u16 old_value;
  if (GetLabelValue(label, &old_value) && old_value != lval)
  {
    printf("WARNING: Redefined label %s to %04x - old value %04x\n", label.c_str(), lval,
           old_value);
    DeleteLabel(label);
  }
  labels.emplace_back(label, lval, type);
}
Esempio n. 2
0
/* FilterLevel: remove all but given level from transcription */
static void FilterLevel(Transcription *t, int lev)
{
   LabList *ll;
   LLink p;   
   
   for (ll = t->head; ll != NULL; ll = ll->next) {
      if (ll->maxAuxLab < lev)
         HError(6570,"FilterLevel: level %d > max[%d]",lev,ll->maxAuxLab);
      if (lev > 0) {
         for (p=ll->head->succ; p->succ!=NULL; p=p->succ) {
            if (p->auxLab[lev] != NULL) {
               p->labid = p->auxLab[lev];
               p->score = p->auxScore[lev];
               p->end = AuxLabEndTime(p,lev);
            } else
               DeleteLabel(p);
         }
      }
      ll->maxAuxLab = 0;
   }
}
Esempio n. 3
0
/* ChopLabs: Chop trans around stime to etime. end = 0 means to end of file */
void ChopLabs(Transcription *t, HTime start, HTime end)
{
   LabList *ll;
   LLink p;
   HTime del = tgtSampRate;
   
   /* assume ClampStEn has already been called, so start and end are OK */
   if(trace & T_SEGMENT)
      printf("ChopLab: extracting labels %.0f to %.0f\n",start,end);
   for (ll = t->head; ll != NULL; ll = ll->next){
      for (p=ll->head->succ; p->succ!= NULL; p=p->succ){
         if((p->start < start-del) || ((end > 0.0 ) && (p->end > end+del))) {
            DeleteLabel(p);
         }
         else {
            p->start -= start;
            p->end -= start;
         }
      }
   }
}
Esempio n. 4
0
/* TraceBack

     Finds best token in end state and returns path.

*/
Transcription *TraceBack(MemHeap *heap, DecoderInst *dec)
{
   Transcription *trans;
   LabList *ll;
   LLink lab, nextlab;
   WordendHyp *weHyp;
   TokenSet *ts;
   RelToken *bestTok=NULL;
   LogFloat prevScore, score;
   RelTokScore bestDelta;
   Pron pron;
   int i;
   HTime start;

   if (dec->net->end->inst && dec->net->end->inst->ts->n > 0)
      ts = dec->net->end->inst->ts;
   else {
      HError (-9999, "no token survived to sent end!");

      ts = BestTokSet (dec);
      if (!ts) {        /* return empty transcription */
         HError (-9999, "best inst is dead as well!");
         trans = CreateTranscription (heap);
         ll = CreateLabelList (heap, 0);
         AddLabelList (ll, trans);
         
         return trans;
      }
   }

   bestDelta = LZERO;
   for (i = 0; i < ts->n; ++i)
      if (ts->relTok[i].delta > bestDelta) {
         bestTok = &ts->relTok[i];
         bestDelta = bestTok->delta;
      }
   assert (bestDelta <= 0.1);   /* 0.1 for accuracy reasons */
   
   if (trace & T_PROP)
      PrintTokSet (dec, ts);

   if (trace & T_TOP) {
      printf ("best score %f\n", ts->score);
      PrintRelTok (dec, bestTok);
   }

   trans = CreateTranscription (heap);
   ll = CreateLabelList (heap, 0);

   /* going backwards from </s> to <s> */
   for (weHyp = bestTok->path; weHyp; weHyp = weHyp->prev) {
      lab = CreateLabel (heap, ll->maxAuxLab);
      pron = dec->net->pronlist[weHyp->pron];
      if ((weHyp->user & 3) == 1)
         pron = pron->next;             /* sp */
      else if ((weHyp->user & 3) == 2)
         pron = pron->next->next;       /* sil */

      lab->labid = pron->outSym;
      lab->score = weHyp->score;
      lab->start = 0.0;
      lab->end = weHyp->frame * dec->frameDur * 1.0e7;
      lab->succ = ll->head->succ;
      lab->pred = ll->head;
      lab->succ->pred = lab->pred->succ = lab;
   }

   start = 0.0;
   prevScore = 0.0;
   for (lab = ll->head->succ; lab != ll->tail; lab = lab->succ) {
      lab->start = start;
      start = lab->end;
      score = lab->score - prevScore;
      prevScore = lab->score;
      lab->score = score;
   }

   for (lab = ll->head->succ; lab != ll->tail; lab = nextlab) {
      nextlab = lab->succ;
      if (!lab->labid)          /* delete words with [] outSym */
         DeleteLabel (lab);
   }

   AddLabelList (ll, trans);
   
   return trans;
}