#include <nsSBCharSetProber.h>
Public Member Functions | |
nsSingleByteCharSetProber (SequenceModel *model) | |
nsSingleByteCharSetProber (SequenceModel *model, PRBool reversed, nsCharSetProber *nameProber) | |
virtual const char * | GetCharSetName () |
virtual nsProbingState | HandleData (const char *aBuf, PRUint32 aLen) |
virtual nsProbingState | GetState (void) |
virtual void | Reset (void) |
virtual float | GetConfidence (void) |
virtual void | SetOpion () |
PRBool | KeepEnglishLetters () |
Protected Attributes | |
nsProbingState | mState |
const SequenceModel * | mModel |
const PRBool | mReversed |
unsigned char | mLastOrder |
PRUint32 | mTotalSeqs |
PRUint32 | mSeqCounters [NUMBER_OF_SEQ_CAT] |
PRUint32 | mTotalChar |
PRUint32 | mFreqChar |
nsCharSetProber * | mNameProber |
Definition at line 62 of file nsSBCharSetProber.h.
nsSingleByteCharSetProber::nsSingleByteCharSetProber | ( | SequenceModel * | model | ) | [inline] |
Definition at line 64 of file nsSBCharSetProber.h.
References Reset().
00065 :mModel(model), mReversed(PR_FALSE), mNameProber(0) { Reset(); }
nsSingleByteCharSetProber::nsSingleByteCharSetProber | ( | SequenceModel * | model, | |
PRBool | reversed, | |||
nsCharSetProber * | nameProber | |||
) | [inline] |
Definition at line 66 of file nsSBCharSetProber.h.
References Reset().
00067 :mModel(model), mReversed(reversed), mNameProber(nameProber) { Reset(); }
const char * nsSingleByteCharSetProber::GetCharSetName | ( | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 114 of file nsSBCharSetProber.cpp.
References SequenceModel::charsetName, nsCharSetProber::GetCharSetName(), mModel, and mNameProber.
00115 { 00116 if (!mNameProber) 00117 return mModel->charsetName; 00118 return mNameProber->GetCharSetName(); 00119 }
float nsSingleByteCharSetProber::GetConfidence | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 93 of file nsSBCharSetProber.cpp.
References mFreqChar, mModel, mSeqCounters, mTotalChar, mTotalSeqs, SequenceModel::mTypicalPositiveRatio, NEGATIVE_CAT, and POSITIVE_CAT.
Referenced by HandleData().
00094 { 00095 #ifdef NEGATIVE_APPROACH 00096 if (mTotalSeqs > 0) 00097 if (mTotalSeqs > mSeqCounters[NEGATIVE_CAT]*10 ) 00098 return ((float)(mTotalSeqs - mSeqCounters[NEGATIVE_CAT]*10))/mTotalSeqs * mFreqChar / mTotalChar; 00099 return (float)0.01; 00100 #else //POSITIVE_APPROACH 00101 float r; 00102 00103 if (mTotalSeqs > 0) { 00104 r = ((float)1.0) * mSeqCounters[POSITIVE_CAT] / mTotalSeqs / mModel->mTypicalPositiveRatio; 00105 r = r*mFreqChar/mTotalChar; 00106 if (r >= (float)1.00) 00107 r = (float)0.99; 00108 return r; 00109 } 00110 return (float)0.01; 00111 #endif 00112 }
virtual nsProbingState nsSingleByteCharSetProber::GetState | ( | void | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 71 of file nsSBCharSetProber.h.
References mState.
00071 {return mState;};
nsProbingState nsSingleByteCharSetProber::HandleData | ( | const char * | aBuf, | |
PRUint32 | aLen | |||
) | [virtual] |
Implements nsCharSetProber.
Definition at line 41 of file nsSBCharSetProber.cpp.
References SequenceModel::charToOrderMap, eDetecting, eFoundIt, eNotMe, GetConfidence(), mFreqChar, mLastOrder, mModel, mReversed, mSeqCounters, mState, mTotalChar, mTotalSeqs, NEGATIVE_SHORTCUT_THRESHOLD, POSITIVE_SHORTCUT_THRESHOLD, SequenceModel::precedenceMatrix, SAMPLE_SIZE, SB_ENOUGH_REL_THRESHOLD, and SYMBOL_CAT_ORDER.
00042 { 00043 unsigned char order; 00044 00045 for (PRUint32 i = 0; i < aLen; i++) 00046 { 00047 order = mModel->charToOrderMap[(unsigned char)aBuf[i]]; 00048 00049 if (order < SYMBOL_CAT_ORDER) 00050 mTotalChar++; 00051 if (order < SAMPLE_SIZE) 00052 { 00053 mFreqChar++; 00054 00055 if (mLastOrder < SAMPLE_SIZE) 00056 { 00057 mTotalSeqs++; 00058 if (!mReversed) 00059 ++(mSeqCounters[mModel->precedenceMatrix[mLastOrder*SAMPLE_SIZE+order]]); 00060 else // reverse the order of the letters in the lookup 00061 ++(mSeqCounters[mModel->precedenceMatrix[order*SAMPLE_SIZE+mLastOrder]]); 00062 } 00063 } 00064 mLastOrder = order; 00065 } 00066 00067 if (mState == eDetecting) 00068 if (mTotalSeqs > SB_ENOUGH_REL_THRESHOLD) 00069 { 00070 float cf = GetConfidence(); 00071 if (cf > POSITIVE_SHORTCUT_THRESHOLD) 00072 mState = eFoundIt; 00073 else if (cf < NEGATIVE_SHORTCUT_THRESHOLD) 00074 mState = eNotMe; 00075 } 00076 00077 return mState; 00078 }
PRBool nsSingleByteCharSetProber::KeepEnglishLetters | ( | ) | [inline] |
Definition at line 82 of file nsSBCharSetProber.h.
00082 {return mModel->keepEnglishLetter;}; // (not implemented)
void nsSingleByteCharSetProber::Reset | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 80 of file nsSBCharSetProber.cpp.
References eDetecting, mFreqChar, mLastOrder, mSeqCounters, mState, mTotalChar, mTotalSeqs, and NUMBER_OF_SEQ_CAT.
Referenced by nsSingleByteCharSetProber().
00081 { 00082 mState = eDetecting; 00083 mLastOrder = 255; 00084 for (PRUint32 i = 0; i < NUMBER_OF_SEQ_CAT; i++) 00085 mSeqCounters[i] = 0; 00086 mTotalSeqs = 0; 00087 mTotalChar = 0; 00088 mFreqChar = 0; 00089 }
virtual void nsSingleByteCharSetProber::SetOpion | ( | ) | [inline, virtual] |
PRUint32 nsSingleByteCharSetProber::mFreqChar [protected] |
Definition at line 101 of file nsSBCharSetProber.h.
Referenced by GetConfidence(), HandleData(), and Reset().
unsigned char nsSingleByteCharSetProber::mLastOrder [protected] |
Definition at line 94 of file nsSBCharSetProber.h.
Referenced by HandleData(), and Reset().
const SequenceModel* nsSingleByteCharSetProber::mModel [protected] |
Definition at line 90 of file nsSBCharSetProber.h.
Referenced by GetCharSetName(), GetConfidence(), and HandleData().
nsCharSetProber* nsSingleByteCharSetProber::mNameProber [protected] |
Definition at line 104 of file nsSBCharSetProber.h.
Referenced by GetCharSetName().
const PRBool nsSingleByteCharSetProber::mReversed [protected] |
Definition at line 91 of file nsSBCharSetProber.h.
Referenced by HandleData().
PRUint32 nsSingleByteCharSetProber::mSeqCounters[NUMBER_OF_SEQ_CAT] [protected] |
Definition at line 97 of file nsSBCharSetProber.h.
Referenced by GetConfidence(), HandleData(), and Reset().
nsProbingState nsSingleByteCharSetProber::mState [protected] |
Definition at line 82 of file nsSBCharSetProber.h.
Referenced by GetState(), HandleData(), and Reset().
PRUint32 nsSingleByteCharSetProber::mTotalChar [protected] |
Definition at line 99 of file nsSBCharSetProber.h.
Referenced by GetConfidence(), HandleData(), and Reset().
PRUint32 nsSingleByteCharSetProber::mTotalSeqs [protected] |
Definition at line 96 of file nsSBCharSetProber.h.
Referenced by GetConfidence(), HandleData(), and Reset().