class CharDet::CharSetGroupProber

Attributes

probers[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/rchardet/charsetgroupprober.rb, line 32
def initialize
  super
  @activeNum = 0
  @probers = []
  @bestGuessProber = nil
end

Public Instance Methods

feed(aBuf) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
Calls superclass method
# 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