eric6/ThirdParty/CharDet/chardet/sbcharsetprober.py

Wed, 13 Jan 2021 19:05:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jan 2021 19:05:48 +0100
changeset 7974
f425b578ede7
parent 6942
2602857055c5
permissions
-rw-r--r--

Third Party Packages
- updated chardet to 4.0.0

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
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
29 from collections import namedtuple
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
30
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
31 from .charsetprober import CharSetProber
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
32 from .enums import CharacterCategory, ProbingState, SequenceLikelihood
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
33
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
34
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
35 SingleByteCharSetModel = namedtuple('SingleByteCharSetModel',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
36 ['charset_name',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
37 'language',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
38 'char_to_order_map',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
39 'language_model',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
40 'typical_positive_ratio',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
41 'keep_ascii_letters',
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
42 'alphabet'])
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
43
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
44
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
45 class SingleByteCharSetProber(CharSetProber):
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
46 SAMPLE_SIZE = 64
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
47 SB_ENOUGH_REL_THRESHOLD = 1024 # 0.25 * SAMPLE_SIZE^2
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
48 POSITIVE_SHORTCUT_THRESHOLD = 0.95
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
49 NEGATIVE_SHORTCUT_THRESHOLD = 0.05
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
50
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
51 def __init__(self, model, reversed=False, name_prober=None):
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
52 super(SingleByteCharSetProber, self).__init__()
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
53 self._model = model
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
54 # TRUE if we need to reverse every pair in the model lookup
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
55 self._reversed = reversed
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
56 # Optional auxiliary prober for name decision
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
57 self._name_prober = name_prober
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
58 self._last_order = None
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
59 self._seq_counters = None
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
60 self._total_seqs = None
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
61 self._total_char = None
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
62 self._freq_char = None
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
63 self.reset()
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
64
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
65 def reset(self):
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
66 super(SingleByteCharSetProber, self).reset()
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
67 # char order of last character
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
68 self._last_order = 255
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
69 self._seq_counters = [0] * SequenceLikelihood.get_num_categories()
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
70 self._total_seqs = 0
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
71 self._total_char = 0
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
72 # characters that fall in our sampling range
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
73 self._freq_char = 0
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
74
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
75 @property
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
76 def charset_name(self):
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
77 if self._name_prober:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
78 return self._name_prober.charset_name
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
79 else:
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
80 return self._model.charset_name
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
81
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
82 @property
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
83 def language(self):
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
84 if self._name_prober:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
85 return self._name_prober.language
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
86 else:
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
87 return self._model.language
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
88
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
89 def feed(self, byte_str):
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
90 # TODO: Make filter_international_words keep things in self.alphabet
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
91 if not self._model.keep_ascii_letters:
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
92 byte_str = self.filter_international_words(byte_str)
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
93 if not byte_str:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
94 return self.state
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
95 char_to_order_map = self._model.char_to_order_map
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
96 language_model = self._model.language_model
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
97 for char in byte_str:
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
98 order = char_to_order_map.get(char, CharacterCategory.UNDEFINED)
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
99 # XXX: This was SYMBOL_CAT_ORDER before, with a value of 250, but
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
100 # CharacterCategory.SYMBOL is actually 253, so we use CONTROL
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
101 # to make it closer to the original intent. The only difference
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
102 # is whether or not we count digits and control characters for
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
103 # _total_char purposes.
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
104 if order < CharacterCategory.CONTROL:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
105 self._total_char += 1
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
106 # TODO: Follow uchardet's lead and discount confidence for frequent
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
107 # control characters.
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
108 # See https://github.com/BYVoid/uchardet/commit/55b4f23971db61
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
109 if order < self.SAMPLE_SIZE:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
110 self._freq_char += 1
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
111 if self._last_order < self.SAMPLE_SIZE:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
112 self._total_seqs += 1
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
113 if not self._reversed:
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
114 lm_cat = language_model[self._last_order][order]
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
115 else:
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
116 lm_cat = language_model[order][self._last_order]
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
117 self._seq_counters[lm_cat] += 1
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
118 self._last_order = order
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
119
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
120 charset_name = self._model.charset_name
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
121 if self.state == ProbingState.DETECTING:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
122 if self._total_seqs > self.SB_ENOUGH_REL_THRESHOLD:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
123 confidence = self.get_confidence()
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
124 if confidence > self.POSITIVE_SHORTCUT_THRESHOLD:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
125 self.logger.debug('%s confidence = %s, we have a winner',
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
126 charset_name, confidence)
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
127 self._state = ProbingState.FOUND_IT
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
128 elif confidence < self.NEGATIVE_SHORTCUT_THRESHOLD:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
129 self.logger.debug('%s confidence = %s, below negative '
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
130 'shortcut threshhold %s', charset_name,
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
131 confidence,
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
132 self.NEGATIVE_SHORTCUT_THRESHOLD)
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
133 self._state = ProbingState.NOT_ME
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
134
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
135 return self.state
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
136
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
137 def get_confidence(self):
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
138 r = 0.01
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
139 if self._total_seqs > 0:
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
140 r = ((1.0 * self._seq_counters[SequenceLikelihood.POSITIVE]) /
7974
f425b578ede7 Third Party Packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
141 self._total_seqs / self._model.typical_positive_ratio)
5714
90c57b50600f Updated chardet to 3.0.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3537
diff changeset
142 r = r * self._freq_char / self._total_char
3537
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
143 if r >= 1.0:
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
144 r = 0.99
7662053c3906 updated CharDet to 2.2.1, updated changelog
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 12
diff changeset
145 return r

eric ide

mercurial