Class: 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.



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

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



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

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



33
34
35
# File 'lib/igo/dictionary.rb', line 33

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

#compatible?(code1, code2) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/igo/dictionary.rb', line 37

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