Class: CharDet::CharSetGroupProber

Inherits:
CharSetProber show all
Defined in:
lib/rchardet/charsetgroupprober.rb

Direct Known Subclasses

MBCSGroupProber, SBCSGroupProber

Instance Attribute Summary collapse

Attributes inherited from CharSetProber

#active

Instance Method Summary collapse

Methods inherited from CharSetProber

#filter_high_bit_only, #filter_with_english_letters, #filter_without_english_letters, #result, #state

Constructor Details

#initializeCharSetGroupProber

Returns a new instance of CharSetGroupProber.



32
33
34
35
36
37
# File 'lib/rchardet/charsetgroupprober.rb', line 32

def initialize
  super
  @_mActiveNum = 0
  @_mProbers = []
  @_mBestGuessProber = nil
end

Instance Attribute Details

#_mProbersObject

Returns the value of attribute _mProbers.



31
32
33
# File 'lib/rchardet/charsetgroupprober.rb', line 31

def _mProbers
  @_mProbers
end

Instance Method Details

#charset_nameObject



53
54
55
56
57
58
59
60
# File 'lib/rchardet/charsetgroupprober.rb', line 53

def charset_name
  if not @_mBestGuessProber
    confidence()
    return nil unless @_mBestGuessProber
    #                self._mBestGuessProber = self._mProbers[0]
  end
  return @_mBestGuessProber.charset_name()
end

#confidenceObject



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
# File 'lib/rchardet/charsetgroupprober.rb', line 83

def confidence()
  st = state()
  if st == EFoundIt
    return 0.99
  elsif st == ENotMe
    return 0.01
  end
  bestConf = 0.0
  @_mBestGuessProber = nil
  for prober in @_mProbers
    next unless prober
    unless prober.active
      $stderr << "#{prober.charset_name()} not active\n" if $debug
      next
    end
    cf = prober.confidence()
    $stderr << "#{prober.charset_name} confidence = #{cf}\n" if $debug
    if bestConf < cf
      bestConf = cf
      @_mBestGuessProber = prober
    end
  end
  return 0.0 unless @_mBestGuessProber
  return bestConf
  #        else:
  #            self._mBestGuessProber = self._mProbers[0]
  #            return self._mBestGuessProber.confidence()
end

#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/rchardet/charsetgroupprober.rb', line 62

def feed(aBuf)
  for prober in @_mProbers
    next unless prober
    next unless prober.active
    st = prober.feed(aBuf)
    next unless st
    if st == EFoundIt
      @_mBestGuessProber = prober
      return state()
    elsif st == ENotMe
      prober.active = false
      @_mActiveNum -= 1
      if @_mActiveNum <= 0
        @_mState = ENotMe
        return state()
      end
    end
  end
  return state()
end

#resetObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rchardet/charsetgroupprober.rb', line 39

def reset
  super
  @_mActiveNum = 0

  for prober in @_mProbers
    if prober
      prober.reset()
      prober.active = true
      @_mActiveNum += 1
    end
  end
  @_mBestGuessProber = nil
end