nsSBCharSetProber.h

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Universal charset detector code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *          Shy Shalom <shooshX@gmail.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsSingleByteCharSetProber_h__
00039 #define nsSingleByteCharSetProber_h__
00040 
00041 #include "nsCharSetProber.h"
00042 
00043 #define SAMPLE_SIZE 64
00044 #define SB_ENOUGH_REL_THRESHOLD  1024
00045 #define POSITIVE_SHORTCUT_THRESHOLD  (float)0.95
00046 #define NEGATIVE_SHORTCUT_THRESHOLD  (float)0.05
00047 #define SYMBOL_CAT_ORDER  250
00048 #define NUMBER_OF_SEQ_CAT 4
00049 #define POSITIVE_CAT   (NUMBER_OF_SEQ_CAT-1)
00050 #define NEGATIVE_CAT   0
00051 
00052 typedef struct
00053 {
00054   unsigned char *charToOrderMap;    // [256] table use to find a char's order
00055   unsigned char *precedenceMatrix;           // [SAMPLE_SIZE][SAMPLE_SIZE]; table to find a 2-char sequence's frequency
00056   float  mTypicalPositiveRatio;     // = freqSeqs / totalSeqs 
00057   PRBool keepEnglishLetter;         // says if this script contains English characters (not implemented)
00058   const char* charsetName;
00059 } SequenceModel;
00060 
00061 
00062 class nsSingleByteCharSetProber : public nsCharSetProber{
00063 public:
00064   nsSingleByteCharSetProber(SequenceModel *model) 
00065     :mModel(model), mReversed(PR_FALSE), mNameProber(0) { Reset(); }
00066   nsSingleByteCharSetProber(SequenceModel *model, PRBool reversed, nsCharSetProber* nameProber)
00067     :mModel(model), mReversed(reversed), mNameProber(nameProber) { Reset(); }
00068 
00069   virtual const char* GetCharSetName();
00070   virtual nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
00071   virtual nsProbingState GetState(void) {return mState;};
00072   virtual void      Reset(void);
00073   virtual float     GetConfidence(void);
00074   virtual void      SetOpion() {};
00075   
00076   // This feature is not implemented yet. any current language model
00077   // contain this parameter as PR_FALSE. No one is looking at this
00078   // parameter or calling this method.
00079   // Moreover, the nsSBCSGroupProber which calls the HandleData of this
00080   // prober has a hard-coded call to FilterWithoutEnglishLetters which gets rid
00081   // of the English letters.
00082   PRBool KeepEnglishLetters() {return mModel->keepEnglishLetter;}; // (not implemented)
00083 
00084 #ifdef DEBUG_chardet
00085   virtual void  DumpStatus();
00086 #endif
00087 
00088 protected:
00089   nsProbingState mState;
00090   const SequenceModel *mModel;
00091   const PRBool mReversed; // PR_TRUE if we need to reverse every pair in the model lookup
00092 
00093   //char order of last character
00094   unsigned char mLastOrder;
00095 
00096   PRUint32 mTotalSeqs;
00097   PRUint32 mSeqCounters[NUMBER_OF_SEQ_CAT];
00098 
00099   PRUint32 mTotalChar;
00100   //characters that fall in our sampling range
00101   PRUint32 mFreqChar;
00102   
00103   // Optional auxiliary prober for name decision. created and destroyed by the GroupProber
00104   nsCharSetProber* mNameProber; 
00105 
00106 };
00107 
00108 
00109 extern SequenceModel Koi8rModel;
00110 extern SequenceModel Win1251Model;
00111 extern SequenceModel Latin5Model;
00112 extern SequenceModel MacCyrillicModel;
00113 extern SequenceModel Ibm866Model;
00114 extern SequenceModel Ibm855Model;
00115 extern SequenceModel Latin7Model;
00116 extern SequenceModel Win1253Model;
00117 extern SequenceModel Latin5BulgarianModel;
00118 extern SequenceModel Win1251BulgarianModel;
00119 extern SequenceModel Latin2HungarianModel;
00120 extern SequenceModel Win1250HungarianModel;
00121 extern SequenceModel Win1255Model;
00122 
00123 #endif /* nsSingleByteCharSetProber_h__ */
00124 
Generated by  doxygen 1.6.2-20100208