Class: Natto::DictionaryInfo
- Inherits:
-
MeCabStruct
- Object
- FFI::Struct
- MeCabStruct
- Natto::DictionaryInfo
- Defined in:
- lib/natto/struct.rb
Overview
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 Symbols 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
Constant Summary collapse
- SYS_DIC =
System dictionary.
0- USR_DIC =
User dictionary.
1- UNK_DIC =
Unknown dictionary.
2
Instance Attribute Summary collapse
-
#filepath ⇒ String
readonly
Absolute filepath to MeCab dictionary.
Instance Method Summary collapse
- #deprecated_type ⇒ Object
-
#initialize(ptr) ⇒ DictionaryInfo
constructor
Initializes this dictionary info instance.
-
#inspect ⇒ String
Overrides
Object#inspect. -
#is_sysdic? ⇒ Boolean
Returns
trueif this is a system dictionary. -
#is_unkdic? ⇒ Boolean
Returns
trueif this is a unknown dictionary type. -
#is_usrdic? ⇒ Boolean
Returns
trueif this is a user dictionary. -
#to_s ⇒ String
Returns human-readable details for this MeCab dictionary.
-
#type ⇒ Fixnum
Object#typeoverride defined when bothtypeandclassare Object methods.
Methods inherited from MeCabStruct
Constructor Details
#initialize(ptr) ⇒ DictionaryInfo
Initializes this dictionary info instance.
Sets the DictionaryInfo filepath value.
96 97 98 99 100 |
# File 'lib/natto/struct.rb', line 96 def initialize(ptr) super(ptr) @filepath = File.absolute_path(self[:filename]) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Natto::MeCabStruct
Instance Attribute Details
#filepath ⇒ String (readonly)
Returns Absolute filepath to MeCab dictionary.
61 62 63 |
# File 'lib/natto/struct.rb', line 61 def filepath @filepath end |
Instance Method Details
#deprecated_type ⇒ Object
82 |
# File 'lib/natto/struct.rb', line 82 alias_method :deprecated_type, :type |
#inspect ⇒ String
Overrides Object#inspect.
121 122 123 |
# File 'lib/natto/struct.rb', line 121 def inspect self.to_s end |
#is_sysdic? ⇒ Boolean
Returns true if this is a system dictionary.
127 128 129 |
# File 'lib/natto/struct.rb', line 127 def is_sysdic? self.type == SYS_DIC end |
#is_unkdic? ⇒ Boolean
Returns true if this is a unknown dictionary type.
139 140 141 |
# File 'lib/natto/struct.rb', line 139 def is_unkdic? self.type == UNK_DIC end |
#is_usrdic? ⇒ Boolean
Returns true if this is a user dictionary.
133 134 135 |
# File 'lib/natto/struct.rb', line 133 def is_usrdic? self.type == USR_DIC end |
#to_s ⇒ String
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 type
111 112 113 114 115 116 |
# File 'lib/natto/struct.rb', line 111 def to_s [ super.chop, "@filepath=\"#{@filepath}\",", "charset=#{self.charset},", "type=#{self.type}>" ].join(' ') end |
#type ⇒ Fixnum
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.
88 89 90 |
# File 'lib/natto/struct.rb', line 88 def type self[:type] end |