| 1 |
|
| /* -*- Mode: C++; tab-width: 2; 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 Communicator client code. |
| 16 |
|
| * |
| 17 |
|
| * The Initial Developer of the Original Code is |
| 18 |
|
| * Netscape Communications Corporation. |
| 19 |
|
| * Portions created by the Initial Developer are Copyright (C) 1998 |
| 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 |
|
| #include "CharDistribution.h" |
| 39 |
|
| |
| 40 |
|
| #include "JISFreq.tab" |
| 41 |
|
| #include "Big5Freq.tab" |
| 42 |
|
| #include "EUCKRFreq.tab" |
| 43 |
|
| #include "EUCTWFreq.tab" |
| 44 |
|
| #include "GB2312Freq.tab" |
| 45 |
|
| |
| 46 |
|
| #define SURE_YES 0.99f |
| 47 |
|
| #define SURE_NO 0.01f |
| 48 |
|
| |
| 49 |
|
| //return confidence base on received data |
| 50 |
10 |
| float CharDistributionAnalysis::GetConfidence() |
| 51 |
|
| { |
| 52 |
|
| //if we didn't receive any character in our consideration range, return negative answer |
| 53 |
10 |
▶ | if (mTotalChars <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mTotalChars <= 0) |
4 |
6 |
10 |
|
| 54 |
4 |
| return SURE_NO; |
| 55 |
|
| |
| 56 |
6 |
▶ | if (mTotalChars != mFreqChars) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mTotalChars != mFreqChars) { |
4 |
2 |
6 |
|
| 57 |
4 |
| float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio); |
| 58 |
|
| |
| 59 |
4 |
▶ | if (r < SURE_YES) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r < SURE_YES) |
4 |
0 |
4 |
|
| 60 |
4 |
| return r; |
| 61 |
|
| } |
| 62 |
|
| //normalize confidence, (we don't want to be 100% sure) |
| 63 |
2 |
| return SURE_YES; |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
4 |
| EUCTWDistributionAnalysis::EUCTWDistributionAnalysis() |
| 67 |
|
| { |
| 68 |
4 |
| mCharToFreqOrder = EUCTWCharToFreqOrder; |
| 69 |
4 |
| mTableSize = EUCTW_TABLE_SIZE; |
| 70 |
4 |
| mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO; |
| 71 |
4 |
| } |
| 72 |
|
| |
| 73 |
4 |
| EUCKRDistributionAnalysis::EUCKRDistributionAnalysis() |
| 74 |
|
| { |
| 75 |
4 |
| mCharToFreqOrder = EUCKRCharToFreqOrder; |
| 76 |
4 |
| mTableSize = EUCKR_TABLE_SIZE; |
| 77 |
4 |
| mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO; |
| 78 |
4 |
| } |
| 79 |
|
| |
| 80 |
4 |
| GB2312DistributionAnalysis::GB2312DistributionAnalysis() |
| 81 |
|
| { |
| 82 |
4 |
| mCharToFreqOrder = GB2312CharToFreqOrder; |
| 83 |
4 |
| mTableSize = GB2312_TABLE_SIZE; |
| 84 |
4 |
| mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO; |
| 85 |
4 |
| } |
| 86 |
|
| |
| 87 |
4 |
| Big5DistributionAnalysis::Big5DistributionAnalysis() |
| 88 |
|
| { |
| 89 |
4 |
| mCharToFreqOrder = Big5CharToFreqOrder; |
| 90 |
4 |
| mTableSize = BIG5_TABLE_SIZE; |
| 91 |
4 |
| mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO; |
| 92 |
4 |
| } |
| 93 |
|
| |
| 94 |
4 |
| SJISDistributionAnalysis::SJISDistributionAnalysis() |
| 95 |
|
| { |
| 96 |
4 |
| mCharToFreqOrder = JISCharToFreqOrder; |
| 97 |
4 |
| mTableSize = JIS_TABLE_SIZE; |
| 98 |
4 |
| mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO; |
| 99 |
4 |
| } |
| 100 |
|
| |
| 101 |
4 |
| EUCJPDistributionAnalysis::EUCJPDistributionAnalysis() |
| 102 |
|
| { |
| 103 |
4 |
| mCharToFreqOrder = JISCharToFreqOrder; |
| 104 |
4 |
| mTableSize = JIS_TABLE_SIZE; |
| 105 |
4 |
| mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO; |
| 106 |
4 |
| } |
| 107 |
|
| |