ThirdParty/CharDet/chardet/latin1prober.py

Fri, 25 Apr 2014 22:07:19 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Fri, 25 Apr 2014 22:07:19 +0200
changeset 3537
7662053c3906
parent 12
1d8dd9706f46
child 5310
f2b774d78b4a
permissions
-rw-r--r--

updated CharDet to 2.2.1, updated changelog

3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
1 ######################## BEGIN LICENSE BLOCK ########################
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
2 # The Original Code is Mozilla Universal charset detector code.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
3 #
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
4 # The Initial Developer of the Original Code is
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
5 # Netscape Communications Corporation.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
6 # Portions created by the Initial Developer are Copyright (C) 2001
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
7 # the Initial Developer. All Rights Reserved.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
8 #
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
9 # Contributor(s):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
10 # Mark Pilgrim - port to Python
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
11 # Shy Shalom - original C code
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
12 #
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
13 # This library is free software; you can redistribute it and/or
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
14 # modify it under the terms of the GNU Lesser General Public
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
15 # License as published by the Free Software Foundation; either
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
16 # version 2.1 of the License, or (at your option) any later version.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
17 #
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
18 # This library is distributed in the hope that it will be useful,
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
21 # Lesser General Public License for more details.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
22 #
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
23 # You should have received a copy of the GNU Lesser General Public
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
24 # License along with this library; if not, write to the Free Software
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
25 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
26 # 02110-1301 USA
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
27 ######################### END LICENSE BLOCK #########################
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
28
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
29 from .charsetprober import CharSetProber
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
30 from .constants import eNotMe
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
31 from .compat import wrap_ord
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
32
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
33 FREQ_CAT_NUM = 4
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
34
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
35 UDF = 0 # undefined
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
36 OTH = 1 # other
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
37 ASC = 2 # ascii capital letter
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
38 ASS = 3 # ascii small letter
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
39 ACV = 4 # accent capital vowel
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
40 ACO = 5 # accent capital other
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
41 ASV = 6 # accent small vowel
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
42 ASO = 7 # accent small other
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
43 CLASS_NUM = 8 # total classes
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
44
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
45 Latin1_CharToClass = (
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
46 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
47 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
48 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
49 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
50 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
51 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
52 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
53 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
54 OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
55 ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
56 ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
57 ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
58 OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
59 ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
60 ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
61 ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
62 OTH, UDF, OTH, ASO, OTH, OTH, OTH, OTH, # 80 - 87
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
63 OTH, OTH, ACO, OTH, ACO, UDF, ACO, UDF, # 88 - 8F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
64 UDF, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 90 - 97
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
65 OTH, OTH, ASO, OTH, ASO, UDF, ASO, ACO, # 98 - 9F
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
66 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A0 - A7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
67 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A8 - AF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
68 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
69 OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B8 - BF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
70 ACV, ACV, ACV, ACV, ACV, ACV, ACO, ACO, # C0 - C7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
71 ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # C8 - CF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
72 ACO, ACO, ACV, ACV, ACV, ACV, ACV, OTH, # D0 - D7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
73 ACV, ACV, ACV, ACV, ACV, ACO, ACO, ACO, # D8 - DF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
74 ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASO, # E0 - E7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
75 ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # E8 - EF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
76 ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, # F0 - F7
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
77 ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, # F8 - FF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
78 )
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
79
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
80 # 0 : illegal
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
81 # 1 : very unlikely
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
82 # 2 : normal
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
83 # 3 : very likely
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
84 Latin1ClassModel = (
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
85 # UDF OTH ASC ASS ACV ACO ASV ASO
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
86 0, 0, 0, 0, 0, 0, 0, 0, # UDF
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
87 0, 3, 3, 3, 3, 3, 3, 3, # OTH
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
88 0, 3, 3, 3, 3, 3, 3, 3, # ASC
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
89 0, 3, 3, 3, 1, 1, 3, 3, # ASS
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
90 0, 3, 3, 3, 1, 2, 1, 2, # ACV
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
91 0, 3, 3, 3, 3, 3, 3, 3, # ACO
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
92 0, 3, 1, 3, 1, 1, 1, 3, # ASV
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
93 0, 3, 1, 3, 1, 1, 3, 3, # ASO
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
94 )
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
95
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
96
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
97 class Latin1Prober(CharSetProber):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
98 def __init__(self):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
99 CharSetProber.__init__(self)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
100 self.reset()
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
101
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
102 def reset(self):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
103 self._mLastCharClass = OTH
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
104 self._mFreqCounter = [0] * FREQ_CAT_NUM
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
105 CharSetProber.reset(self)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
106
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
107 def get_charset_name(self):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
108 return "windows-1252"
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
109
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
110 def feed(self, aBuf):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
111 aBuf = self.filter_with_english_letters(aBuf)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
112 for c in aBuf:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
113 charClass = Latin1_CharToClass[wrap_ord(c)]
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
114 freq = Latin1ClassModel[(self._mLastCharClass * CLASS_NUM)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
115 + charClass]
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
116 if freq == 0:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
117 self._mState = eNotMe
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
118 break
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
119 self._mFreqCounter[freq] += 1
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
120 self._mLastCharClass = charClass
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
121
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
122 return self.get_state()
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
123
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
124 def get_confidence(self):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
125 if self.get_state() == eNotMe:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
126 return 0.01
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
127
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
128 total = sum(self._mFreqCounter)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
129 if total < 0.01:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
130 confidence = 0.0
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
131 else:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
132 confidence = ((self._mFreqCounter[3] / total)
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
133 - (self._mFreqCounter[1] * 20.0 / total))
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
134 if confidence < 0.0:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
135 confidence = 0.0
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
136 # lower the confidence of latin1 so that other more accurate
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
137 # detector can take priority.
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
138 confidence = confidence * 0.5
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
139 return confidence

eric ide

mercurial