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.
-
:filename - filename of dictionary; on Windows, filename is stored in UTF-8 encoding
-
:charset - character set of the dictionary
-
:size - number of words contained in dictionary
-
:type - dictionary type: 0 (system), 1 (user-defined), 2 (unknown)
-
:lsize - left attributes size
-
:rsize - right attributes size
-
:version - version of this dictionary
-
:next - pointer to next dictionary in list
## 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
@return [String] Absolute filepath to MeCab
dictionary.
Public Class Methods
Initializes this dictionary info instance. Sets the `DictionaryInfo` filepath value. @param ptr [FFI::Pointer] pointer to MeCab
dictionary
# File lib/natto/struct.rb, line 96 def initialize(ptr) super(ptr) @filepath = File.absolute_path(self[:filename]) end
Public Instance Methods
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
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
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
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
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
# File lib/natto/struct.rb, line 111 def to_s [ super.chop, "@filepath=\"#{@filepath}\",", "charset=#{self.charset},", "type=#{self.type}>" ].join(' ') end
`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