Class: UniversalDetector::Big5DistributionAnalysis

Inherits:
CharDistributionAnalysis show all
Defined in:
lib/CharDistributionAnalysis.rb

Constant Summary

Constants inherited from CharDistributionAnalysis

CharDistributionAnalysis::ENOUGH_DATA_THRESHOLD, CharDistributionAnalysis::SURE_NO, CharDistributionAnalysis::SURE_YES

Instance Method Summary collapse

Methods inherited from CharDistributionAnalysis

#feed, #get_confidence, #got_enough_data, #reset

Constructor Details

#initializeBig5DistributionAnalysis

Returns a new instance of Big5DistributionAnalysis.



172
173
174
175
176
177
# File 'lib/CharDistributionAnalysis.rb', line 172

def initialize
    super
    @_mCharToFreqOrder = Big5CharToFreqOrder
    @_mTableSize = BIG5_TABLE_SIZE
    @_mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
end

Instance Method Details

#get_order(aStr) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/CharDistributionAnalysis.rb', line 179

def get_order(aStr)
    # for big5 encoding, we are interested 
    #   first  byte range: 0xa4 -- 0xfe
    #   second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
    # no validation needed here. State machine has done that
    if aStr[0] >= 0xA4
        if aStr[1] >= 0xA1
            return 157 * (aStr[0] - 0xA4) + aStr[1] - 0xA1 + 63
        else
            return 157 * (aStr[0] - 0xA4) + aStr[1] - 0x40
        end
    else
        return -1
    end
end