|
Packit |
67f6e7 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
Packit |
67f6e7 |
/* ***** BEGIN LICENSE BLOCK *****
|
|
Packit |
67f6e7 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The contents of this file are subject to the Mozilla Public License Version
|
|
Packit |
67f6e7 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
Packit |
67f6e7 |
* the License. You may obtain a copy of the License at
|
|
Packit |
67f6e7 |
* http://www.mozilla.org/MPL/
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
Packit |
67f6e7 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
Packit |
67f6e7 |
* for the specific language governing rights and limitations under the
|
|
Packit |
67f6e7 |
* License.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The Original Code is Mozilla Communicator client code.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The Initial Developer of the Original Code is
|
|
Packit |
67f6e7 |
* Netscape Communications Corporation.
|
|
Packit |
67f6e7 |
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
Packit |
67f6e7 |
* the Initial Developer. All Rights Reserved.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Contributor(s):
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Alternatively, the contents of this file may be used under the terms of
|
|
Packit |
67f6e7 |
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
Packit |
67f6e7 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
Packit |
67f6e7 |
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
Packit |
67f6e7 |
* of those above. If you wish to allow use of your version of this file only
|
|
Packit |
67f6e7 |
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
Packit |
67f6e7 |
* use your version of this file under the terms of the MPL, indicate your
|
|
Packit |
67f6e7 |
* decision by deleting the provisions above and replace them with the notice
|
|
Packit |
67f6e7 |
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
Packit |
67f6e7 |
* the provisions above, a recipient may use your version of this file under
|
|
Packit |
67f6e7 |
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* ***** END LICENSE BLOCK ***** */
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#include "CharDistribution.h"
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#include "JISFreq.tab"
|
|
Packit |
67f6e7 |
#include "Big5Freq.tab"
|
|
Packit |
67f6e7 |
#include "EUCKRFreq.tab"
|
|
Packit |
67f6e7 |
#include "EUCTWFreq.tab"
|
|
Packit |
67f6e7 |
#include "GB2312Freq.tab"
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#define SURE_YES 0.99f
|
|
Packit |
67f6e7 |
#define SURE_NO 0.01f
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
//return confidence base on received data
|
|
Packit |
67f6e7 |
float CharDistributionAnalysis::GetConfidence()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
//if we didn't receive any character in our consideration range, return negative answer
|
|
Packit |
67f6e7 |
if (mTotalChars <= 0)
|
|
Packit |
67f6e7 |
return SURE_NO;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
if (mTotalChars != mFreqChars) {
|
|
Packit |
67f6e7 |
float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio);
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
if (r < SURE_YES)
|
|
Packit |
67f6e7 |
return r;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
//normalize confidence, (we don't want to be 100% sure)
|
|
Packit |
67f6e7 |
return SURE_YES;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
EUCTWDistributionAnalysis::EUCTWDistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = EUCTWCharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = EUCTW_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = EUCKRCharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = EUCKR_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
GB2312DistributionAnalysis::GB2312DistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = GB2312CharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = GB2312_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
Big5DistributionAnalysis::Big5DistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = Big5CharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = BIG5_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
SJISDistributionAnalysis::SJISDistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = JISCharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = JIS_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCharToFreqOrder = JISCharToFreqOrder;
|
|
Packit |
67f6e7 |
mTableSize = JIS_TABLE_SIZE;
|
|
Packit |
67f6e7 |
mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
|