• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • localization
  • probers
CharDistribution.cpp
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* -*- C++ -*-
3 * Copyright (C) 1998 <developer@mozilla.org>
4 *
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27#include "CharDistribution.h"
28
29#include "tables/JISFreq.tab"
30#include "tables/Big5Freq.tab"
31#include "tables/EUCKRFreq.tab"
32#include "tables/GB2312Freq.tab"
33
34#define SURE_YES 0.99f
35#define SURE_NO 0.01f
36
37namespace kencodingprober {
38//return confidence base on received data
39float CharDistributionAnalysis::GetConfidence()
40{
41 //if we didn't receive any character in our consideration range, return negative answer
42 if (mTotalChars <= 0)
43 return SURE_NO;
44
45 if (mTotalChars != mFreqChars) {
46 float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio);
47
48 if (r < SURE_YES)
49 return r;
50 }
51 //normalize confidence, (we don't want to be 100% sure)
52 return SURE_YES;
53}
54
55EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
56{
57 mCharToFreqOrder = EUCKRCharToFreqOrder;
58 mTableSize = EUCKR_TABLE_SIZE;
59 mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
60}
61
62GB2312DistributionAnalysis::GB2312DistributionAnalysis()
63{
64 mCharToFreqOrder = GB2312CharToFreqOrder;
65 mTableSize = GB2312_TABLE_SIZE;
66 mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
67}
68
69Big5DistributionAnalysis::Big5DistributionAnalysis()
70{
71 mCharToFreqOrder = Big5CharToFreqOrder;
72 mTableSize = BIG5_TABLE_SIZE;
73 mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
74}
75
76SJISDistributionAnalysis::SJISDistributionAnalysis()
77{
78 mCharToFreqOrder = JISCharToFreqOrder;
79 mTableSize = JIS_TABLE_SIZE;
80 mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
81}
82
83EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
84{
85 mCharToFreqOrder = JISCharToFreqOrder;
86 mTableSize = JIS_TABLE_SIZE;
87 mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
88}
89}
90
SURE_YES
#define SURE_YES
Definition: CharDistribution.cpp:34
SURE_NO
#define SURE_NO
Definition: CharDistribution.cpp:35
CharDistribution.h
kencodingprober::Big5DistributionAnalysis::Big5DistributionAnalysis
Big5DistributionAnalysis()
Definition: CharDistribution.cpp:69
kencodingprober::CharDistributionAnalysis::mCharToFreqOrder
const short * mCharToFreqOrder
Definition: CharDistribution.h:98
kencodingprober::CharDistributionAnalysis::mFreqChars
unsigned int mFreqChars
Definition: CharDistribution.h:92
kencodingprober::CharDistributionAnalysis::GetConfidence
float GetConfidence()
Definition: CharDistribution.cpp:39
kencodingprober::CharDistributionAnalysis::mTotalChars
unsigned int mTotalChars
Definition: CharDistribution.h:95
kencodingprober::CharDistributionAnalysis::mTypicalDistributionRatio
float mTypicalDistributionRatio
Definition: CharDistribution.h:105
kencodingprober::CharDistributionAnalysis::mTableSize
unsigned int mTableSize
Definition: CharDistribution.h:101
kencodingprober::EUCJPDistributionAnalysis::EUCJPDistributionAnalysis
EUCJPDistributionAnalysis()
Definition: CharDistribution.cpp:83
kencodingprober::EUCKRDistributionAnalysis::EUCKRDistributionAnalysis
EUCKRDistributionAnalysis()
Definition: CharDistribution.cpp:55
kencodingprober::GB2312DistributionAnalysis::GB2312DistributionAnalysis
GB2312DistributionAnalysis()
Definition: CharDistribution.cpp:62
kencodingprober::SJISDistributionAnalysis::SJISDistributionAnalysis
SJISDistributionAnalysis()
Definition: CharDistribution.cpp:76
kencodingprober
Definition: CharDistribution.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal