class Natto::DictionaryInfo

`DictionaryInfo` is a wrapper for the `struct mecab_dictionary_info_t` structure holding the MeCab instance's related dictionary information.

Values for the MeCab dictionary attributes may be obtained by using the following `Symbol`s as keys to the layout associative array of `FFI::Struct` members.

## Usage MeCab dictionary attributes can be obtained by using their corresponding accessor.

nm = Natto::MeCab.new

sysdic = nm.dicts.first

# display the real path to the mecab lib
puts sysdic.filepath
=> /usr/local/lib/mecab/dic/ipadic/sys.dic

# what charset (encoding) is the system dictionary?
puts sysdic.charset
=> utf8

# is this really the system dictionary?
puts sysdic.is_sysdic?
=> true

Constants

SYS_DIC

System dictionary.

UNK_DIC

Unknown dictionary.

USR_DIC

User dictionary.

Attributes

filepath[R]

@return [String] Absolute filepath to MeCab dictionary.

Public Class Methods

new(ptr) click to toggle source

Initializes this dictionary info instance. Sets the `DictionaryInfo` filepath value. @param ptr [FFI::Pointer] pointer to MeCab dictionary

Calls superclass method
# File lib/natto/struct.rb, line 96
def initialize(ptr)
  super(ptr)

  @filepath = File.absolute_path(self[:filename])
end

Public Instance Methods

inspect() click to toggle source

Overrides `Object#inspect`. @return [String] encoded object id, dictionary filename, and charset @see to_s

# File lib/natto/struct.rb, line 121
def inspect
  self.to_s
end
is_sysdic?() click to toggle source

Returns `true` if this is a system dictionary. @return [Boolean]

# File lib/natto/struct.rb, line 127
def is_sysdic?
  self.type == SYS_DIC
end
is_unkdic?() click to toggle source

Returns `true` if this is a unknown dictionary type. @return [Boolean]

# File lib/natto/struct.rb, line 139
def is_unkdic?
  self.type == UNK_DIC
end
is_usrdic?() click to toggle source

Returns `true` if this is a user dictionary. @return [Boolean]

# File lib/natto/struct.rb, line 133
def is_usrdic?
  self.type == USR_DIC
end
to_s() click to toggle source

Returns human-readable details for this MeCab dictionary. Overrides `Object#to_s`.

  • encoded object id

  • real file path to this dictionary

  • dictionary charset

  • dictionary type

@return [String] encoded object id, file path to dictionary, charset and type

Calls superclass method
# File lib/natto/struct.rb, line 111
def to_s
  [ super.chop,
    "@filepath=\"#{@filepath}\",", 
     "charset=#{self.charset},", 
     "type=#{self.type}>" ].join(' ')
end
type() click to toggle source

`Object#type` override defined when both `type` and `class` are Object methods. This is a hack to avoid the `Object#type` deprecation warning thrown up in Ruby 1.8.7 and in JRuby. @return [Fixnum] MeCab dictionary type

# File lib/natto/struct.rb, line 88
def type
  self[:type]
end