Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
EUCJPContextAnalysis Class Reference

#include <JpCntx.h>

Inheritance diagram for EUCJPContextAnalysis:
Inheritance graph
[legend]
Collaboration diagram for EUCJPContextAnalysis:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void HandleData (const char *aBuf, PRUint32 aLen)
void HandleOneChar (const char *aStr, PRUint32 aCharLen)
float GetConfidence ()
void Reset (void)
void SetOpion ()
PRBool GotEnoughData ()

Protected Member Functions

PRInt32 GetOrder (const char *str, PRUint32 *charLen)
PRInt32 GetOrder (const char *str)

Protected Attributes

PRUint32 mRelSample [NUM_OF_CATEGORY]
PRUint32 mTotalRel
PRInt32 mLastCharOrder
PRUint32 mNeedToSkipCharNum
PRBool mDone

Detailed Description

Definition at line 121 of file JpCntx.h.


Member Function Documentation

Definition at line 184 of file JpCntx.cpp.

{
  //This is just one way to calculate confidence. It works well for me.
  if (mTotalRel > MINIMUM_DATA_THRESHOLD)
    return ((float)(mTotalRel - mRelSample[0]))/mTotalRel;
  else 
    return (float)DONT_KNOW;
}

Here is the caller graph for this function:

PRInt32 EUCJPContextAnalysis::GetOrder ( const char *  str,
PRUint32 charLen 
) [protected, virtual]

Implements JapaneseContextAnalysis.

Definition at line 211 of file JpCntx.cpp.

{
  //find out current char's byte length
  if ((unsigned char)*str == (unsigned char)0x8e ||
      (unsigned char)*str >= (unsigned char)0xa1 && 
      (unsigned char)*str <= (unsigned char)0xfe)
      *charLen = 2;
  else if ((unsigned char)*str == (unsigned char)0x8f)
    *charLen = 3;
  else
    *charLen = 1;

  //return its order if it is hiragana
  if ((unsigned char)*str == (unsigned char)0xa4 &&
      (unsigned char)*(str+1) >= (unsigned char)0xa1 && 
      (unsigned char)*(str+1) <= (unsigned char)0xf3)
     return (unsigned char)*(str+1) - (unsigned char)0xa1;
  return -1;
}
PRInt32 EUCJPContextAnalysis::GetOrder ( const char *  str) [inline, protected, virtual]

Implements JapaneseContextAnalysis.

Definition at line 125 of file JpCntx.h.

  {
    if (*str == '\244' &&
          (unsigned char)*(str+1) >= (unsigned char)0xa1 &&
          (unsigned char)*(str+1) <= (unsigned char)0xf3)
      return (unsigned char)*(str+1) - (unsigned char)0xa1;
    return -1;
  };

Definition at line 80 of file JpCntx.h.

Here is the caller graph for this function:

void JapaneseContextAnalysis::HandleData ( const char *  aBuf,
PRUint32  aLen 
) [inherited]

Definition at line 131 of file JpCntx.cpp.

{
  PRUint32 charLen;
  PRInt32 order;
  PRUint32 i;
  
  if (mDone)
    return;

  //The buffer we got is byte oriented, and a character may span in more than one
  //buffers. In case the last one or two byte in last buffer is not complete, we 
  //record how many byte needed to complete that character and skip these bytes here.
  //We can choose to record those bytes as well and analyse the character once it 
  //is complete, but since a character will not make much difference, by simply skipping
  //this character will simply our logic and improve performance.
  for (i = mNeedToSkipCharNum; i < aLen; )
  {
    order = GetOrder(aBuf+i, &charLen);
    i+= charLen;
    if (i > aLen){
      mNeedToSkipCharNum = i - aLen;
      mLastCharOrder = -1;
    }
    else 
    {
      if (order != -1 && mLastCharOrder != -1)
      {
        mTotalRel ++;
        if (mTotalRel > MAX_REL_THRESHOLD)
        {
          mDone = PR_TRUE;
          break;
        }
        mRelSample[jp2CharContext[mLastCharOrder][order]]++;
      }
      mLastCharOrder = order;
    }
  }
  
  return;
}

Here is the call graph for this function:

void JapaneseContextAnalysis::HandleOneChar ( const char *  aStr,
PRUint32  aCharLen 
) [inline, inherited]

Definition at line 58 of file JpCntx.h.

  {
    PRInt32 order;

    //if we received enough data, stop here   
    if (mTotalRel > MAX_REL_THRESHOLD)   mDone = PR_TRUE;
    if (mDone)       return;
     
    //Only 2-bytes characters are of our interest
    order = (aCharLen == 2) ? GetOrder(aStr) : -1;
    if (order != -1 && mLastCharOrder != -1)
    {
      mTotalRel++;
      //count this sequence to its category counter
      mRelSample[jp2CharContext[mLastCharOrder][order]]++;
    }
    mLastCharOrder = order;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 173 of file JpCntx.cpp.

Here is the caller graph for this function:

void JapaneseContextAnalysis::SetOpion ( ) [inline, inherited]

Definition at line 79 of file JpCntx.h.

{};

Member Data Documentation

PRBool JapaneseContextAnalysis::mDone [protected, inherited]

Definition at line 100 of file JpCntx.h.

Definition at line 93 of file JpCntx.h.

Definition at line 97 of file JpCntx.h.

Definition at line 87 of file JpCntx.h.

Definition at line 90 of file JpCntx.h.


The documentation for this class was generated from the following files: