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/. */
6
#include "CharDistribution.h"
9
#include "Big5Freq.tab"
10
#include "EUCKRFreq.tab"
11
#include "EUCTWFreq.tab"
12
#include "GB2312Freq.tab"
15
#define SURE_YES 0.99f
18
//return confidence base on received data
19
float CharDistributionAnalysis::GetConfidence(void)
21
//if we didn't receive any character in our consideration range, or the
22
// number of frequent characters is below the minimum threshold, return
24
if (mTotalChars <= 0 || mFreqChars <= mDataThreshold)
27
if (mTotalChars != mFreqChars) {
28
float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio);
33
//normalize confidence, (we don't want to be 100% sure)
37
EUCTWDistributionAnalysis::EUCTWDistributionAnalysis()
39
mCharToFreqOrder = EUCTWCharToFreqOrder;
40
mTableSize = NS_ARRAY_LENGTH(EUCTWCharToFreqOrder);
41
mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO;
44
EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
46
mCharToFreqOrder = EUCKRCharToFreqOrder;
47
mTableSize = NS_ARRAY_LENGTH(EUCKRCharToFreqOrder);
48
mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
51
GB2312DistributionAnalysis::GB2312DistributionAnalysis()
53
mCharToFreqOrder = GB2312CharToFreqOrder;
54
mTableSize = NS_ARRAY_LENGTH(GB2312CharToFreqOrder);
55
mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
58
Big5DistributionAnalysis::Big5DistributionAnalysis()
60
mCharToFreqOrder = Big5CharToFreqOrder;
61
mTableSize = NS_ARRAY_LENGTH(Big5CharToFreqOrder);
62
mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
65
SJISDistributionAnalysis::SJISDistributionAnalysis()
67
mCharToFreqOrder = JISCharToFreqOrder;
68
mTableSize = NS_ARRAY_LENGTH(JISCharToFreqOrder);
69
mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
72
EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
74
mCharToFreqOrder = JISCharToFreqOrder;
75
mTableSize = NS_ARRAY_LENGTH(JISCharToFreqOrder);
76
mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;