Пример #1
0
nsProbingState nsSJISProber::HandleData(const char* aBuf, PRUint32 aLen)
{
  nsSMState codingState;

  for (PRUint32 i = 0; i < aLen; i++)
  {
    codingState = mCodingSM->NextState(aBuf[i]);
    if (codingState == eItsMe)
    {
      mState = eFoundIt;
      break;
    }
    if (codingState == eStart)
    {
      PRUint32 charLen = mCodingSM->GetCurrentCharLen();
      if (i == 0)
      {
        mLastChar[1] = aBuf[0];
        mContextAnalyser.HandleOneChar(mLastChar+2-charLen, charLen);
        mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
      }
      else
      {
        mContextAnalyser.HandleOneChar(aBuf+i+1-charLen, charLen);
        mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
      }
    }
  }

  mLastChar[0] = aBuf[aLen-1];

  if (mState == eDetecting)
    if (mContextAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
      mState = eFoundIt;

  return mState;
}
Пример #2
0
nsProbingState nsUTF8Prober::HandleData(const char* aBuf, uint32_t aLen)
{
  nsSMState codingState;

  for (uint32_t i = 0; i < aLen; i++)
  {
    codingState = mCodingSM->NextState(aBuf[i]);
    if (codingState == eItsMe)
    {
      mState = eFoundIt;
      break;
    }
    if (codingState == eStart)
    {
      if (mCodingSM->GetCurrentCharLen() >= 2)
        mNumOfMBChar++;
    }
  }

  if (mState == eDetecting)
    if (GetConfidence() > SHORTCUT_THRESHOLD)
      mState = eFoundIt;
  return mState;
}
void  nsLatin1Prober::DumpStatus()
{
    printf(" Latin1Prober: %1.3f [%s]\r\n", GetConfidence(), GetCharSetName());
}
void nsSingleByteCharSetProber::DumpStatus()
{
  printf("  SBCS: %1.3f [%s]\r\n", GetConfidence(), GetCharSetName());
}
MojErr ConnectionManagerProxy::UpdateWANStatus(const MojObject& response)
{
	MojErr err;
	bool wanAvailable = false;
	bool updated = false;
	MojInt64 confidence = (MojInt64)ConnectionConfidenceUnknown;

	MojObject wan;
	bool found = response.get(_T("wan"), wan);
	if (found) {
		updated = m_wanRequirementCore->SetCurrentValue(wan);

		MojString wanConnected;
		found = false;
		err = wan.get(_T("state"), wanConnected, found);
		MojErrCheck(err);

		if (!found) {
			LOG_WARNING(MSGID_WAN_CONN_STATUS_UNKNOWN, 0, "WAN connection status not returned by Connection Manager");
		} else if (wanConnected == "connected") {
			MojString wanNetwork;
			found = false;
			err = wan.get(_T("network"), wanNetwork, found);
			MojErrCheck(err);

			if (!found) {
				LOG_WARNING(MSGID_WAN_NW_MODE_UNKNOWN, 0, "WAN network mode not returned by Connection Manager");
			} else if (wanNetwork != "unusable") {
				MojString onInternet;
				err = wan.get(_T("onInternet"), onInternet, found);
				MojErrCheck(err);

				if (onInternet == "yes") {
					wanAvailable = true;
					confidence = GetConfidence(wan);
				}
			}
		}
	}

	if (wanAvailable) {
		if (!m_wanRequirementCore->IsMet()) {
			LOG_DEBUG("WAN connection is now available");
			m_wanRequirementCore->Met();
			std::for_each(m_wanRequirements.begin(), m_wanRequirements.end(),
				boost::mem_fn(&Requirement::Met));
		} else if (updated) {
			std::for_each(m_wanRequirements.begin(), m_wanRequirements.end(),
				boost::mem_fn(&Requirement::Updated));
		}
	} else {
		if (m_wanRequirementCore->IsMet()) {
			LOG_DEBUG("WAN connection is no longer available");
			m_wanRequirementCore->Unmet();
			std::for_each(m_wanRequirements.begin(), m_wanRequirements.end(),
				boost::mem_fn(&Requirement::Unmet));
		}
	}

	if (m_wanConfidence != (int)confidence) {
		m_wanConfidence = (int)confidence;
		LOG_DEBUG("WAN confidence level changed to %d",
			m_wanConfidence);
		UpdateConfidenceRequirements(m_wanConfidenceCores,
			m_wanConfidenceRequirements, m_wanConfidence);
	}

	return MojErrNone;
}
Пример #6
0
// output an N-best list derived from a Transcription
void ARec::OutTranscription(Transcription *trans)
{
	//for each transcription
	int i, j,n;
	LabList *ll;
	LLink p;
	char *w, *t;
	char buf[20];
	float acScore,lm,score;     // various likelihoods
	float confidence;      // acoustic confidence
	HTime tst,tet;         // start and end times
	PhraseType k;
	float lmScore;
	int startseqnum, altseqnum, numTrans=1;

	ll = trans->head;
	startseqnum=altseqnum=outseqnum;
	for (i=1; i<=trans->numLists; i++,ll=ll->next) {
		score=0.0;
		//set the alt tag  ( the start seq of the next transcription)
		if(i==trans->numLists) {
			altseqnum=0;
		} else {
			altseqnum=outseqnum+3;
			for (p=ll->head->succ; p->succ!= NULL; p=p->succ)
				altseqnum++;
		}
		//output an open tag
		OutPacket(OpenTag_PT, "", "",startseqnum,altseqnum,0.0,0.0,
			score,-1,(float)tact/frameCount,ll->head->succ->start+stTime,
			ll->head->succ->start+stTime);
		// scan the transcription
		for (p=ll->head->succ,j=1; p->succ!=NULL; p=p->succ,j++) {
			w=t=NULL;
			//get info from label
			w=p->labid->name;
			if (w == NULL || strcmp(w,"!NULL")==0){
				k = Null_PT; w=NULL;
			} else {
				k = Word_PT;
			}
			tst=p->start; tet=p->end;
			acScore=lmScore=0.0;
			for (n=1; n<=ll->maxAuxLab; n++){   //Aux labels
				if(p->auxLab[n]!=NULL) {
					if(strcmp(p->auxLab[n]->name, "acscore")==0)
						acScore=p->auxScore[n];
					if(strcmp(p->auxLab[n]->name, "lmscore")==0)
						lmScore=p->auxScore[n];
					if(n==LAB_TAG)
						t=p->auxLab[n]->name;
				}
			}
			if (t!=NULL){
				if (strstr(t,"!SUBLAT_(") != NULL){
					k=OpenTag_PT;  t = NULL;
				}else if (strstr(t,"!)_SUBLAT-") != NULL){
					k=CloseTag_PT; t += 10;
				}
			}
			wordPen = float((k==Word_PT)?pri->wordPen:0.0);
			lm = lmScore + wordPen;
			char *none="";
			confidence =GetConfidence(pri,int (tst/sampPeriod)+1,int (tet/sampPeriod),
				                      acScore,(w!=NULL)?w:none);
			score+=lm+acScore;
			//output packet - if first word, alter traceback/alt info
			OutPacket(k, string((w!=NULL)?w:""), string((t!=NULL)?t:""),
				outseqnum, 0,
				acScore, lm, score, confidence,
				(float)tact/frameCount, tst+stTime, tet+stTime);

		}
		//output a closetag
		sprintf(buf, "%d / %d",i,trans->numLists);
		OutPacket(CloseTag_PT, "", buf,outseqnum,0,0.0,0.0,
			score,-1,(float)tact/frameCount,ll->tail->pred->end+stTime,
			ll->tail->pred->end+stTime);

	}
}
Пример #7
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);
   }
}
bool Gesture::GestureSuccess()
{
    return ( GetConfidence() >= GESTURE_CONFIDENCETHRESHOLD &&
             GetMahalanobis() <= GESTURE_MAHALANOBISTHRESHOLD );
}