Пример #1
0
// Draw output line in main output box - char by char
void ARec::DrawOutLine(PhraseType k, HTime t, string wrd, string tag)
{
   char buf[1000];

   HSetFontSize(win,-14);
   switch(k){
   case Start_PT:
      ScrollOutBox();
      sprintf(buf,"%4.1f: ",t/1e7);
      rdline = string(buf);
      break;
   case OpenTag_PT:
      rdline = rdline + " (";
      break;
   case CloseTag_PT:  rdline = rdline + " )";
      if (tag != "") rdline = rdline + tag;
      break;
   case Null_PT:
      if (tag != "") rdline = rdline + " <"+tag+">";
      break;
   case Word_PT:
      rdline = rdline + " " + wrd;
      if (tag != "") rdline = rdline + "<"+tag+">";
      break;
   case End_PT:
      HSetColour(win,BLACK);
      HPrintf(win,x0+3,rdly,"%s",rdline.c_str());
      break;
   }
   int len,w = x1-x0-6;
   if (HTextWidth(win,rdline.c_str()) > w) {
      strcpy(buf,rdline.c_str());
      do {
         len = strlen(buf); --len;
         assert(len>5);
         buf[len] = '\0';
      } while (HTextWidth(win,buf) > w);
      HSetColour(win,BLACK);
      HPrintf(win,x0+3,rdly,"%s",buf);
      ScrollOutBox();
      rdline.erase(0,len);
      rdline = "   " + rdline;
   }
   HSetFontSize(win,0);
}
Пример #2
0
HWin MakeAWindow(char *name,int x, int y, int w, int h, int n)
{
	HWin win;
	int xx,yy;
	char buf[100];

	win = MakeHWin(name,x,y,w,h,1);

	strcpy(buf,"Window: "); strcat(buf,name);
	xx = CentreX(win,w/2,buf);
	yy = CentreY(win,h/2,buf);
	HSetColour(win,RED+n);
	HDrawLine(win,0,0,w,h);
	HPrintf(win,xx,yy,"%s",buf);
	return win;
}
Пример #3
0
/* EXPORT->RedrawHButton: readraw a single button object */
void RedrawHButton(HButton *btn)
{
   int pad = 2;
   int x, y, w, h, r, s, pos;
   HPoint poly[9], shad[4];
   char sbuf[256], nullchar = '\0';
     
   x = btn->x;   y=btn->y;   w=btn->w;   h=btn->h;   r=3; s=1;
     
   /* set up the polygon */
   poly[0].x = x;         poly[0].y = y+r;
   poly[1].x = x;         poly[1].y = y+h-r;
   poly[2].x = x+r;       poly[2].y = y+h;
   poly[3].x = x+w-r;     poly[3].y = y+h;
   poly[4].x = x+w;       poly[4].y = y+h-r;
   poly[5].x = x+w;       poly[5].y = y+r;
   poly[6].x = x+w-r;     poly[6].y = y;
   poly[7].x = x+r;       poly[7].y = y;
   poly[8].x = x;         poly[8].y = y+r;
   /* set up the extra lines for the shadow */
   shad[0].x = x+r+s;     shad[0].y = y+h+s;
   shad[1].x = x+w-r+s;   shad[1].y = y+h+s;
   shad[2].x = x+w+s;     shad[2].y = y+h-r+s;
   shad[3].x = x+w+s;     shad[3].y = y+r+s;
     
   if (btn->lit) 
      HSetColour(btn->fg);
   else 
      HSetColour(btn->bg);
   HFillPolygon(poly, 9);
   HSetColour(btn->fg);
   HDrawLines(poly, 9);
   HDrawLines(shad, 4);
   if (btn->active)
      if (btn->lit)
         HSetColour(btn->bg);
      else 
         HSetColour(btn->fg);
   else
      HSetGrey(30);
   strcpy(sbuf, btn->str);
   pos = strlen(sbuf); 
   while(HTextWidth(sbuf) > (w - 2*pad)) 
      sbuf[--pos]=nullchar;
   HPrintf(CentreX(x+w/2, sbuf), CentreY(y+h/2, sbuf), "%s", sbuf);
}
Пример #4
0
// Initialise sizes for display window
void ARec::InitDrawRD()
{
   const int margin = 4;
   int textheight;
   int nlines;

   textheight = HTextHeight(win,"ABCD");

   x0 = margin; y0 = margin; x1 = width-margin;
   x2 = x0 + HTextWidth(win,"Status") + 2;
   x3 = x2+20;
   x4 = x3+ 2*margin;
   x5 = x4 + HTextWidth(win,"Time") + 2;
   x6 = x5 + HTextWidth(win,"9999.9s") + 2;
   x7 = x6 + HTextWidth(win,"Score") + 2;
   x8 = x7 + 40;
   x9 = x8 + 4*margin;
   x10 = x9 + HTextWidth(win,"HMM") + 4;
   x11 = x10 + HTextWidth(win,"aa-yy+bb") + 4;
   x12 = x11 + HTextWidth(win,"Nact") + 6;
   x13 = x12 + HTextWidth(win,"9999") + 6;
   x14 = x13 + HTextWidth(win,"Mode") + 4;
   y9 = height - margin;
   y8 = y9 - margin;
   y5 = y8 - margin;
   y4 = y5 - textheight - 1;
   y3 = y4 - margin;
   y6 = (int) (y3 - textheight*1.5);
   y1 = y6 - margin;
   y7 = y1 - margin-2;
   HSetFontSize(win,-14);
   textheight = HTextHeight(win,"ABCD");
   rdlyinc = textheight+2;
   HSetFontSize(win,0);
   nlines = (y7-y0) / rdlyinc; --nlines;
   rdly = y7 - nlines*rdlyinc;
   // paint background
   HSetGrey(win,PANELGREY2);
   HFillRectangle(win,0,0,width,height);
   // paint output panel
   HDrawPanel(win,x0,y0,x1,y1,PANELGREY1);
   // paint traceback panel
   HDrawPanel(win,x0,y6,x1,y3,PANELGREY1);
   // write labels
   HSetGrey(win,PANELGREY0);
   HPrintf(win,x0,y5,"Status");
   HPrintf(win,x4,y5,"Time");
   HPrintf(win,x6,y5,"Score");
   HPrintf(win,x9,y5,"HMM");
   HPrintf(win,x11,y5,"NAct");
   HPrintf(win,x13,y5,"Mode");
}
Пример #5
0
// Do traceback and if showRD then update display
void ARec::TraceBackRecogniser()
{
   int i,st,en;
   char *p,buf[10];
   MLink m;
   Path *pp;
   float tnow,confidence,ac;
   int iscore;
   PartialPath pptb,ppcb;

   ppcb = CurrentBestPath(pri);

   // get the word that the current best path is within
   p="";
   if (ppcb.node!=NULL && ppcb.node->wordset!=NULL)
      p = ppcb.node->wordset->name;

   // update time
   tnow = float((pri->frame*sampPeriod + stTime)/1e7);
   if (showRD){
      HSetColour(win,BLACK);
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x5-1,y4-1,x6+1,y5+1);
      HSetColour(win,BLACK);
      HPrintf(win,x5,y5,"%.1fs",tnow);
   }

   // update HMM, nactive, and score (but ignore silence)
   if (showRD){
      m=FindMacroStruct(hset,'h',pri->genMaxNode->info.hmm);
      assert(m!=NULL);
      if (strcmp(m->id->name,"sil") != 0 && strcmp(m->id->name,"sp") != 0) {
         st = trbakFrame; en = pri->frame;
         ac = float(pri->genMaxTok.like - trbakAc);
         confidence = GetConfidence(pri,st+1,en,ac,"");
         //printf("CONFA %d->%d = %f [%f - %f = %f]\n",st,en,confidence,pri->genMaxTok.like,trbakAc,ac);
         trbakFrame = pri->frame;
         trbakAc = float(pri->genMaxTok.like);
         iscore = (int) (float(x7) + confidence*float(x8-x7));
         if (iscore<=x7) {
            HSetColour(win,RED); HFillRectangle(win,x7,y4+4,x8,y5+1);
         }else if (iscore>=x8) {
            HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,x8,y5+1);
         }else {
            HSetColour(win,RED); HFillRectangle(win,iscore,y4+4,x8,y5+1);
            HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,iscore,y5+1);
         }
      }
      // update HMM
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x10,y4-1,x11,y5+3);
      HSetColour(win,BLACK);
      HPrintf(win,x10,y5,"%s",m->id->name);
      // update nactive
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x12,y4-1,x13,y5+1);
      HSetColour(win,BLACK);
      HPrintf(win,x12,y5,"%d", pri->nact);
      // update mode
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x14,y4-1,x1,y5+1);
      HSetColour(win,BLACK);
      strcpy(buf,"    ");
      if (runmode&ONESHOT_MODE) buf[0] = '1';
      if (runmode&CONTINUOUS_MODE) buf[0] = 'C';
      if (runmode&RUN_IMMED) buf[1] = 'I';
      if (runmode&FLUSH_TOMARK) buf[1] = 'M';
      if (runmode&FLUSH_TOSPEECH) buf[1] = 'S';
      if (runmode&STOP_IMMED) buf[2] = 'I';
      if (runmode&STOP_ATMARK) buf[2] = 'M';
      if (runmode&STOP_ATSIL) buf[2] = 'S';
      if (runmode&RESULT_ATEND) buf[3] = 'E';
      if (runmode&RESULT_IMMED) buf[3] = 'I';
      if (runmode&RESULT_ASAP) buf[3] = 'A';
      if ((runmode&RESULT_ALL) == RESULT_ALL) buf[3] = 'X';
      HPrintf(win,x14,y5,"%s",buf);
   }

   // if showRD do full traceback
   if (showRD){
      string s = p;
      char buf[256],*bp;

      for (pp = ppcb.path; pp!=NULL; pp=pp->prev){
         if (pp->owner->node->info.pron != NULL)  // it might be a !NULL tag
            s = string(pp->owner->node->info.pron->word->wordName->name) + string(" ") + s;
      }
      if (s != trbak){
         int w = x1-x0-8,txtw;
         trbak = s;
         HSetGrey(win,PANELGREY1);
         strcpy(buf,s.c_str());  bp = buf;
         txtw = HTextWidth(win,bp);
         while (txtw>w) txtw = HTextWidth(win,++bp);
         HFillRectangle(win,x0+1,y6+2,x0+trbakLastWidth+5,y3-2);
         HSetColour(win,BLACK);
         HPrintf(win,x0+4,y3-4,"%s",bp);
         trbakLastWidth = txtw;
      }
   }

   // runmode is RESULT_ASAP, see if anything more can be disambiguated
   if (runmode&RESULT_ASAP){
      pptb = DoTraceBack(pri);
      if (pptb.n>0){
         if (trace&T_PAN) {
            printf(" traceback at frame %.1f\n",tnow);
            PrintPartialPath(pptb,FALSE);
         }
         for (i=1; i<=pptb.n; i++)
            OutPathElement(i,pptb);
      }
   }
   // runmode is RESULT_IMMED, output any new words regardless
   if ((runmode&RESULT_IMMED) && (ppcb.n>0)){
      if (trace&T_IAN) {
         printf(" current best at frame %.1f\n",tnow);
         PrintPartialPath(ppcb,FALSE);
      }
      for (i=1; i<=ppcb.n; i++)
         OutPathElement(i,ppcb);
   }
}