Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "CharDistribution.h"
7 :
8 : #include "JISFreq.tab"
9 : #include "mozilla/ArrayUtils.h"
10 :
11 : #define SURE_YES 0.99f
12 : #define SURE_NO 0.01f
13 :
14 : //return confidence base on received data
15 0 : float CharDistributionAnalysis::GetConfidence(void)
16 : {
17 : //if we didn't receive any character in our consideration range, or the
18 : // number of frequent characters is below the minimum threshold, return
19 : // negative answer
20 0 : if (mTotalChars <= 0 || mFreqChars <= mDataThreshold)
21 0 : return SURE_NO;
22 :
23 0 : if (mTotalChars != mFreqChars) {
24 0 : float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio);
25 :
26 0 : if (r < SURE_YES)
27 0 : return r;
28 : }
29 : //normalize confidence, (we don't want to be 100% sure)
30 0 : return SURE_YES;
31 : }
32 :
33 0 : SJISDistributionAnalysis::SJISDistributionAnalysis()
34 : {
35 0 : mCharToFreqOrder = JISCharToFreqOrder;
36 0 : mTableSize = mozilla::ArrayLength(JISCharToFreqOrder);
37 0 : mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
38 0 : }
39 :
40 0 : EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
41 : {
42 0 : mCharToFreqOrder = JISCharToFreqOrder;
43 0 : mTableSize = mozilla::ArrayLength(JISCharToFreqOrder);
44 0 : mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
45 0 : }
46 :
|