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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • 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 
37 namespace kencodingprober {
38 //return confidence base on received data
39 float 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 
55 EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
56 {
57  mCharToFreqOrder = EUCKRCharToFreqOrder;
58  mTableSize = EUCKR_TABLE_SIZE;
59  mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
60 }
61 
62 GB2312DistributionAnalysis::GB2312DistributionAnalysis()
63 {
64  mCharToFreqOrder = GB2312CharToFreqOrder;
65  mTableSize = GB2312_TABLE_SIZE;
66  mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
67 }
68 
69 Big5DistributionAnalysis::Big5DistributionAnalysis()
70 {
71  mCharToFreqOrder = Big5CharToFreqOrder;
72  mTableSize = BIG5_TABLE_SIZE;
73  mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
74 }
75 
76 SJISDistributionAnalysis::SJISDistributionAnalysis()
77 {
78  mCharToFreqOrder = JISCharToFreqOrder;
79  mTableSize = JIS_TABLE_SIZE;
80  mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
81 }
82 
83 EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
84 {
85  mCharToFreqOrder = JISCharToFreqOrder;
86  mTableSize = JIS_TABLE_SIZE;
87  mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
88 }
89 }
90 
kencodingprober::CharDistributionAnalysis::mTypicalDistributionRatio
float mTypicalDistributionRatio
Definition: CharDistribution.h:105
kencodingprober::CharDistributionAnalysis::mFreqChars
unsigned int mFreqChars
Definition: CharDistribution.h:92
SURE_NO
#define SURE_NO
Definition: CharDistribution.cpp:35
kencodingprober::CharDistributionAnalysis::mTableSize
unsigned int mTableSize
Definition: CharDistribution.h:101
kencodingprober::EUCJPDistributionAnalysis::EUCJPDistributionAnalysis
EUCJPDistributionAnalysis()
Definition: CharDistribution.cpp:83
CharDistribution.h
kencodingprober::CharDistributionAnalysis::mTotalChars
unsigned int mTotalChars
Definition: CharDistribution.h:95
kencodingprober::SJISDistributionAnalysis::SJISDistributionAnalysis
SJISDistributionAnalysis()
Definition: CharDistribution.cpp:76
kencodingprober::EUCKRDistributionAnalysis::EUCKRDistributionAnalysis
EUCKRDistributionAnalysis()
Definition: CharDistribution.cpp:55
SURE_YES
#define SURE_YES
Definition: CharDistribution.cpp:34
kencodingprober::GB2312DistributionAnalysis::GB2312DistributionAnalysis
GB2312DistributionAnalysis()
Definition: CharDistribution.cpp:62
kencodingprober::CharDistributionAnalysis::mCharToFreqOrder
const short * mCharToFreqOrder
Definition: CharDistribution.h:98
kencodingprober::Big5DistributionAnalysis::Big5DistributionAnalysis
Big5DistributionAnalysis()
Definition: CharDistribution.cpp:69
kencodingprober::CharDistributionAnalysis::GetConfidence
float GetConfidence()
Definition: CharDistribution.cpp:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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