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

KDECore

  • sources
  • kde-4.12
  • 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/EUCTWFreq.tab"
33 #include "tables/GB2312Freq.tab"
34 
35 #define SURE_YES 0.99f
36 #define SURE_NO 0.01f
37 
38 namespace kencodingprober {
39 //return confidence base on received data
40 float CharDistributionAnalysis::GetConfidence()
41 {
42  //if we didn't receive any character in our consideration range, return negative answer
43  if (mTotalChars <= 0)
44  return SURE_NO;
45 
46  if (mTotalChars != mFreqChars) {
47  float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio);
48 
49  if (r < SURE_YES)
50  return r;
51  }
52  //normalize confidence, (we don't want to be 100% sure)
53  return SURE_YES;
54 }
55 
56 EUCTWDistributionAnalysis::EUCTWDistributionAnalysis()
57 {
58  mCharToFreqOrder = EUCTWCharToFreqOrder;
59  mTableSize = EUCTW_TABLE_SIZE;
60  mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO;
61 }
62 
63 EUCKRDistributionAnalysis::EUCKRDistributionAnalysis()
64 {
65  mCharToFreqOrder = EUCKRCharToFreqOrder;
66  mTableSize = EUCKR_TABLE_SIZE;
67  mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO;
68 }
69 
70 GB2312DistributionAnalysis::GB2312DistributionAnalysis()
71 {
72  mCharToFreqOrder = GB2312CharToFreqOrder;
73  mTableSize = GB2312_TABLE_SIZE;
74  mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO;
75 }
76 
77 Big5DistributionAnalysis::Big5DistributionAnalysis()
78 {
79  mCharToFreqOrder = Big5CharToFreqOrder;
80  mTableSize = BIG5_TABLE_SIZE;
81  mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO;
82 }
83 
84 SJISDistributionAnalysis::SJISDistributionAnalysis()
85 {
86  mCharToFreqOrder = JISCharToFreqOrder;
87  mTableSize = JIS_TABLE_SIZE;
88  mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
89 }
90 
91 EUCJPDistributionAnalysis::EUCJPDistributionAnalysis()
92 {
93  mCharToFreqOrder = JISCharToFreqOrder;
94  mTableSize = JIS_TABLE_SIZE;
95  mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO;
96 }
97 }
98 
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:36
kencodingprober::CharDistributionAnalysis::mTableSize
unsigned int mTableSize
Definition: CharDistribution.h:101
kencodingprober::EUCJPDistributionAnalysis::EUCJPDistributionAnalysis
EUCJPDistributionAnalysis()
Definition: CharDistribution.cpp:91
kencodingprober::EUCTWDistributionAnalysis::EUCTWDistributionAnalysis
EUCTWDistributionAnalysis()
Definition: CharDistribution.cpp:56
CharDistribution.h
kencodingprober::CharDistributionAnalysis::mTotalChars
unsigned int mTotalChars
Definition: CharDistribution.h:95
kencodingprober::SJISDistributionAnalysis::SJISDistributionAnalysis
SJISDistributionAnalysis()
Definition: CharDistribution.cpp:84
kencodingprober::EUCKRDistributionAnalysis::EUCKRDistributionAnalysis
EUCKRDistributionAnalysis()
Definition: CharDistribution.cpp:63
SURE_YES
#define SURE_YES
Definition: CharDistribution.cpp:35
kencodingprober::GB2312DistributionAnalysis::GB2312DistributionAnalysis
GB2312DistributionAnalysis()
Definition: CharDistribution.cpp:70
kencodingprober::CharDistributionAnalysis::mCharToFreqOrder
const short * mCharToFreqOrder
Definition: CharDistribution.h:98
kencodingprober::Big5DistributionAnalysis::Big5DistributionAnalysis
Big5DistributionAnalysis()
Definition: CharDistribution.cpp:77
kencodingprober::CharDistributionAnalysis::GetConfidence
float GetConfidence()
Definition: CharDistribution.cpp:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:07 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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