LCOV - code coverage report
Current view: directory - extensions/universalchardet/src/base - nsHebrewProber.h (source / functions) Found Hit Coverage
Test: app.info Lines: 6 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

       1                 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Universal charset detector code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  *          Shy Shalom <shooshX@gmail.com>
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer: All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsHebrewProber_h__
      39                 : #define nsHebrewProber_h__
      40                 : 
      41                 : #include "nsSBCharSetProber.h"
      42                 : 
      43                 : // This prober doesn't actually recognize a language or a charset.
      44                 : // It is a helper prober for the use of the Hebrew model probers
      45                 : class nsHebrewProber: public nsCharSetProber
      46                 : {
      47                 : public:
      48               0 :   nsHebrewProber(void) :mLogicalProb(0), mVisualProb(0) { Reset(); }
      49                 : 
      50               0 :   virtual ~nsHebrewProber(void) {}
      51                 :   virtual nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
      52                 :   virtual const char* GetCharSetName();
      53                 :   virtual void Reset(void);
      54                 : 
      55                 :   virtual nsProbingState GetState(void);
      56                 : 
      57               0 :   virtual float     GetConfidence(void) { return (float)0.0; }
      58               0 :   virtual void      SetOpion() {}
      59                 : 
      60               0 :   void SetModelProbers(nsCharSetProber *logicalPrb, nsCharSetProber *visualPrb) 
      61               0 :   { mLogicalProb = logicalPrb; mVisualProb = visualPrb; }
      62                 : 
      63                 : #ifdef DEBUG_chardet
      64                 :   virtual void  DumpStatus();
      65                 : #endif
      66                 : 
      67                 : protected:
      68                 :   static bool isFinal(char c);
      69                 :   static bool isNonFinal(char c);
      70                 : 
      71                 :   PRInt32 mFinalCharLogicalScore, mFinalCharVisualScore;
      72                 : 
      73                 :   // The two last characters seen in the previous buffer.
      74                 :   char mPrev, mBeforePrev;
      75                 : 
      76                 :   // These probers are owned by the group prober.
      77                 :   nsCharSetProber *mLogicalProb, *mVisualProb;
      78                 : };
      79                 : 
      80                 : /**
      81                 :  * ** General ideas of the Hebrew charset recognition **
      82                 :  *
      83                 :  * Four main charsets exist in Hebrew:
      84                 :  * "ISO-8859-8" - Visual Hebrew
      85                 :  * "windows-1255" - Logical Hebrew 
      86                 :  * "ISO-8859-8-I" - Logical Hebrew
      87                 :  * "x-mac-hebrew" - ?? Logical Hebrew ??
      88                 :  *
      89                 :  * Both "ISO" charsets use a completely identical set of code points, whereas
      90                 :  * "windows-1255" and "x-mac-hebrew" are two different proper supersets of 
      91                 :  * these code points. windows-1255 defines additional characters in the range
      92                 :  * 0x80-0x9F as some misc punctuation marks as well as some Hebrew-specific 
      93                 :  * diacritics and additional 'Yiddish' ligature letters in the range 0xc0-0xd6.
      94                 :  * x-mac-hebrew defines similar additional code points but with a different 
      95                 :  * mapping.
      96                 :  *
      97                 :  * As far as an average Hebrew text with no diacritics is concerned, all four 
      98                 :  * charsets are identical with respect to code points. Meaning that for the 
      99                 :  * main Hebrew alphabet, all four map the same values to all 27 Hebrew letters 
     100                 :  * (including final letters).
     101                 :  *
     102                 :  * The dominant difference between these charsets is their directionality.
     103                 :  * "Visual" directionality means that the text is ordered as if the renderer is
     104                 :  * not aware of a BIDI rendering algorithm. The renderer sees the text and 
     105                 :  * draws it from left to right. The text itself when ordered naturally is read 
     106                 :  * backwards. A buffer of Visual Hebrew generally looks like so:
     107                 :  * "[last word of first line spelled backwards] [whole line ordered backwards
     108                 :  * and spelled backwards] [first word of first line spelled backwards] 
     109                 :  * [end of line] [last word of second line] ... etc' "
     110                 :  * adding punctuation marks, numbers and English text to visual text is
     111                 :  * naturally also "visual" and from left to right.
     112                 :  * 
     113                 :  * "Logical" directionality means the text is ordered "naturally" according to
     114                 :  * the order it is read. It is the responsibility of the renderer to display 
     115                 :  * the text from right to left. A BIDI algorithm is used to place general 
     116                 :  * punctuation marks, numbers and English text in the text.
     117                 :  *
     118                 :  * Texts in x-mac-hebrew are almost impossible to find on the Internet. From 
     119                 :  * what little evidence I could find, it seems that its general directionality
     120                 :  * is Logical.
     121                 :  *
     122                 :  * To sum up all of the above, the Hebrew probing mechanism knows about two
     123                 :  * charsets:
     124                 :  * Visual Hebrew - "ISO-8859-8" - backwards text - Words and sentences are
     125                 :  *    backwards while line order is natural. For charset recognition purposes
     126                 :  *    the line order is unimportant (In fact, for this implementation, even 
     127                 :  *    word order is unimportant).
     128                 :  * Logical Hebrew - "windows-1255" - normal, naturally ordered text.
     129                 :  *
     130                 :  * "ISO-8859-8-I" is a subset of windows-1255 and doesn't need to be 
     131                 :  *    specifically identified.
     132                 :  * "x-mac-hebrew" is also identified as windows-1255. A text in x-mac-hebrew
     133                 :  *    that contain special punctuation marks or diacritics is displayed with
     134                 :  *    some unconverted characters showing as question marks. This problem might
     135                 :  *    be corrected using another model prober for x-mac-hebrew. Due to the fact
     136                 :  *    that x-mac-hebrew texts are so rare, writing another model prober isn't 
     137                 :  *    worth the effort and performance hit.
     138                 :  *
     139                 :  * *** The Prober ***
     140                 :  *
     141                 :  * The prober is divided between two nsSBCharSetProbers and an nsHebrewProber,
     142                 :  * all of which are managed, created, fed data, inquired and deleted by the
     143                 :  * nsSBCSGroupProber. The two nsSBCharSetProbers identify that the text is in
     144                 :  * fact some kind of Hebrew, Logical or Visual. The final decision about which
     145                 :  * one is it is made by the nsHebrewProber by combining final-letter scores
     146                 :  * with the scores of the two nsSBCharSetProbers to produce a final answer.
     147                 :  *
     148                 :  * The nsSBCSGroupProber is responsible for stripping the original text of HTML
     149                 :  * tags, English characters, numbers, low-ASCII punctuation characters, spaces
     150                 :  * and new lines. It reduces any sequence of such characters to a single space.
     151                 :  * The buffer fed to each prober in the SBCS group prober is pure text in
     152                 :  * high-ASCII.
     153                 :  * The two nsSBCharSetProbers (model probers) share the same language model:
     154                 :  * Win1255Model.
     155                 :  * The first nsSBCharSetProber uses the model normally as any other
     156                 :  * nsSBCharSetProber does, to recognize windows-1255, upon which this model was
     157                 :  * built. The second nsSBCharSetProber is told to make the pair-of-letter
     158                 :  * lookup in the language model backwards. This in practice exactly simulates
     159                 :  * a visual Hebrew model using the windows-1255 logical Hebrew model.
     160                 :  *
     161                 :  * The nsHebrewProber is not using any language model. All it does is look for
     162                 :  * final-letter evidence suggesting the text is either logical Hebrew or visual
     163                 :  * Hebrew. Disjointed from the model probers, the results of the nsHebrewProber
     164                 :  * alone are meaningless. nsHebrewProber always returns 0.00 as confidence
     165                 :  * since it never identifies a charset by itself. Instead, the pointer to the
     166                 :  * nsHebrewProber is passed to the model probers as a helper "Name Prober".
     167                 :  * When the Group prober receives a positive identification from any prober,
     168                 :  * it asks for the name of the charset identified. If the prober queried is a
     169                 :  * Hebrew model prober, the model prober forwards the call to the
     170                 :  * nsHebrewProber to make the final decision. In the nsHebrewProber, the
     171                 :  * decision is made according to the final-letters scores maintained and Both
     172                 :  * model probers scores. The answer is returned in the form of the name of the
     173                 :  * charset identified, either "windows-1255" or "ISO-8859-8".
     174                 :  *
     175                 :  */
     176                 : #endif /* nsHebrewProber_h__ */

Generated by: LCOV version 1.7