Class: CharDet::CharSetGroupProber
Instance Attribute Summary collapse
#active
Instance Method Summary
collapse
#filter_high_bit_only, #filter_with_english_letters, #filter_without_english_letters, #get_state
Constructor Details
Returns a new instance of CharSetGroupProber.
32
33
34
35
36
37
|
# File 'lib/rchardet/charsetgroupprober.rb', line 32
def initialize
super
@activeNum = 0
@probers = []
@bestGuessProber = nil
end
|
Instance Attribute Details
#probers ⇒ Object
Returns the value of attribute probers.
31
32
33
|
# File 'lib/rchardet/charsetgroupprober.rb', line 31
def probers
@probers
end
|
Instance Method Details
#feed(aBuf) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/rchardet/charsetgroupprober.rb', line 63
def feed(aBuf)
for prober in @probers
next unless prober
next unless prober.active
st = prober.feed(aBuf)
next unless st
if st == EFoundIt
@bestGuessProber = prober
return get_state()
elsif st == ENotMe
prober.active = false
@activeNum -= 1
if @activeNum <= 0
@state = ENotMe
return get_state()
end
end
end
return get_state()
end
|
#get_charset_name ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/rchardet/charsetgroupprober.rb', line 53
def get_charset_name
if !@bestGuessProber
get_confidence()
if !@bestGuessProber
return nil
end
end
return @bestGuessProber.get_charset_name()
end
|
#get_confidence ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/rchardet/charsetgroupprober.rb', line 84
def get_confidence()
st = get_state()
if st == EFoundIt
return 0.99
elsif st == ENotMe
return 0.01
end
bestConf = 0.0
@bestGuessProber = nil
for prober in @probers
next unless prober
unless prober.active
$stderr << "#{prober.get_charset_name()} not active\n" if $debug
next
end
cf = prober.get_confidence()
$stderr << "#{prober.get_charset_name} confidence = #{cf}\n" if $debug
if bestConf < cf
bestConf = cf
@bestGuessProber = prober
end
end
return 0.0 unless @bestGuessProber
return bestConf
end
|
#reset ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/rchardet/charsetgroupprober.rb', line 39
def reset
super
@activeNum = 0
for prober in @probers
if prober
prober.reset()
prober.active = true
@activeNum += 1
end
end
@bestGuessProber = nil
end
|