| 1 | /* -*- C++ -*- |
|---|---|
| 2 | SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org> |
| 3 | |
| 4 | SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #include "CharDistribution.h" |
| 8 | |
| 9 | #include "tables/Big5Freq.tab" |
| 10 | #include "tables/EUCKRFreq.tab" |
| 11 | #include "tables/GB2312Freq.tab" |
| 12 | #include "tables/JISFreq.tab" |
| 13 | |
| 14 | #define SURE_YES 0.99f |
| 15 | #define SURE_NO 0.01f |
| 16 | |
| 17 | namespace kencodingprober |
| 18 | { |
| 19 | // return confidence base on received data |
| 20 | float CharDistributionAnalysis::GetConfidence() |
| 21 | { |
| 22 | // if we didn't receive any character in our consideration range, return negative answer |
| 23 | if (mTotalChars == 0) { |
| 24 | return SURE_NO; |
| 25 | } |
| 26 | |
| 27 | if (mTotalChars != mFreqChars) { |
| 28 | float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio); |
| 29 | |
| 30 | if (r < SURE_YES) { |
| 31 | return r; |
| 32 | } |
| 33 | } |
| 34 | // normalize confidence, (we don't want to be 100% sure) |
| 35 | return SURE_YES; |
| 36 | } |
| 37 | |
| 38 | EUCKRDistributionAnalysis::EUCKRDistributionAnalysis() |
| 39 | { |
| 40 | mCharToFreqOrder = EUCKRCharToFreqOrder; |
| 41 | mTableSize = EUCKR_TABLE_SIZE; |
| 42 | mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO; |
| 43 | } |
| 44 | |
| 45 | GB2312DistributionAnalysis::GB2312DistributionAnalysis() |
| 46 | { |
| 47 | mCharToFreqOrder = GB2312CharToFreqOrder; |
| 48 | mTableSize = GB2312_TABLE_SIZE; |
| 49 | mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO; |
| 50 | } |
| 51 | |
| 52 | Big5DistributionAnalysis::Big5DistributionAnalysis() |
| 53 | { |
| 54 | mCharToFreqOrder = Big5CharToFreqOrder; |
| 55 | mTableSize = BIG5_TABLE_SIZE; |
| 56 | mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO; |
| 57 | } |
| 58 | |
| 59 | SJISDistributionAnalysis::SJISDistributionAnalysis() |
| 60 | { |
| 61 | mCharToFreqOrder = JISCharToFreqOrder; |
| 62 | mTableSize = JIS_TABLE_SIZE; |
| 63 | mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO; |
| 64 | } |
| 65 | |
| 66 | EUCJPDistributionAnalysis::EUCJPDistributionAnalysis() |
| 67 | { |
| 68 | mCharToFreqOrder = JISCharToFreqOrder; |
| 69 | mTableSize = JIS_TABLE_SIZE; |
| 70 | mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO; |
| 71 | } |
| 72 | } |
| 73 |
