Class: Igo::CharCategory

Inherits:
Object
  • Object
show all
Defined in:
lib/igo/dictionary.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir) ⇒ CharCategory

Returns a new instance of CharCategory.



27
28
29
30
31
32
33
# File 'lib/igo/dictionary.rb', line 27

def initialize(data_dir)
  @categories = CharCategory.read_categories(data_dir)
  fmis = FileMappedInputStream.new(data_dir + "/code2category")
  @char2id = fmis.get_int_array(fmis.size / 4 / 2)
  @eql_masks = fmis.get_int_array(fmis.size / 4 /2)
  fmis.close
end

Class Method Details

.read_categories(data_dir) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/igo/dictionary.rb', line 43

def self.read_categories(data_dir)
  data = FileMappedInputStream::get_int_array(data_dir + "/char.category")
  size = data.size / 4
  ary = []
  for i in 0 .. (size - 1)
    ary.push(Category.new(data[i * 4], data[i * 4 + 1], data[i * 4 + 2] == 1, data[i * 4 + 3] == 1))
  end
  return ary
end

Instance Method Details

#category(code) ⇒ Object



35
36
37
# File 'lib/igo/dictionary.rb', line 35

def category(code)
  return @categories[@char2id[code]]
end

#compatible?(code1, code2) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/igo/dictionary.rb', line 39

def compatible?(code1, code2)
  return (@eql_masks[code1] & @eql_masks[code2]) != 0
end