Class: UniversalDetector::CharSetGroupProber
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.
34
35
36
37
38
|
# File 'lib/CharSetGroupProber.rb', line 34
def initialize
@_mActiveNum = 0
@_mProbers = []
@_mBestGuessProber = nil
end
|
Instance Method Details
#feed(aBuf) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/CharSetGroupProber.rb', line 62
def feed(aBuf)
for prober in @_mProbers
unless prober then next end
unless prober.active then next end
st = prober.feed(aBuf)
unless st then next end
if st == :FoundIt
@_mBestGuessProber = prober
return get_state()
elsif st == :NotMe
prober.active = false
@_mActiveNum -= 1
if @_mActiveNum <= 0
@_mState = :NotMe
return get_state()
end
end
end
return get_state()
end
|
#get_charset_name ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/CharSetGroupProber.rb', line 53
def get_charset_name
unless @_mBestGuessProber
get_confidence()
unless @_mBestGuessProber then return nil end
end
return @_mBestGuessProber.get_charset_name()
end
|
#get_confidence ⇒ Object
83
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
109
110
111
112
|
# File 'lib/CharSetGroupProber.rb', line 83
def get_confidence
st = get_state()
if st == :FoundIt
return 0.99
elsif st == :NotMe
return 0.01
end
bestConf = 0.0
@_mBestGuessProber = nil
for prober in @_mProbers
unless prober then next end
unless prober.active
if UniversalDetector::DEBUG
p(prober.get_charset_name() + ' not active\n')
end
next
end
cf = prober.get_confidence()
if UniversalDetector::DEBUG
p('%s confidence = %s\n' % [prober.get_charset_name(), cf])
end
if bestConf < cf
bestConf = cf
@_mBestGuessProber = prober
end
end
unless @_mBestGuessProber then return 0.0 end
return bestConf
end
|
#reset ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/CharSetGroupProber.rb', line 40
def reset
super
@_mActiveNum = 0
for prober in @_mProbers
if prober
prober.reset()
prober.active = true
@_mActiveNum += 1
end
end
@_mBestGuessProber = nil
end
|