natto 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.md +21 -4
  2. data/lib/natto/version.rb +1 -1
  3. data/lib/natto.rb +34 -22
  4. metadata +3 -3
data/README.md CHANGED
@@ -27,13 +27,26 @@ e.g., for Cygwin
27
27
  export MECAB_PATH=cygmecab-1
28
28
 
29
29
  ## Usage
30
+ require 'rubygems' if RUBY_VERSION.to_f < 1.9
30
31
  require 'natto'
31
32
 
32
- m = Natto::MeCab.new
33
+ mecab = Natto::MeCab.new
33
34
  => #<Natto::MeCab:0x28d93dd4 @options={}, \
34
35
  @dicts=[#<Natto::DictionaryInfo:0x28d93d34>], \
35
- @ptr=#<FFI::Pointer address=0x28af3e58>>
36
- puts m.parse('暑い日にはもってこいの一品ですね。')
36
+ @ptr=#<FFI::Pointer address=0x28af3e58>, \
37
+ @version="0.98">
38
+
39
+ puts mecab.version
40
+ => 0.98
41
+
42
+ sysdic = mecab.dicts.first
43
+ puts sysdic.filename
44
+ => /usr/local/lib/mecab/dic/ipadic/sys.dic
45
+
46
+ puts sysdic.charset
47
+ => utf8
48
+
49
+ puts mecab.parse('暑い日にはもってこいの一品ですね。')
37
50
  暑い日にはもってこいの一品ですね。
38
51
  暑い 形容詞,自立,*,*,形容詞・アウオ段,基本形,暑い,アツイ,アツイ
39
52
  日 名詞,非自立,副詞可能,*,*,*,日,ヒ,ヒ
@@ -59,7 +72,11 @@ e.g., for Cygwin
59
72
 
60
73
  ## Changelog
61
74
 
62
- - __2011/01/15__: 0.1.0 release.
75
+ - __2011/01/15__: 0.1.1 release.
76
+ - Internal tweak to accessor for version in Natto::MeCab
77
+ - Continuing update of documentation
78
+
79
+ - __2011/01/14__: 0.1.0 release.
63
80
  - Added accessors to Natto::DictionaryInfo
64
81
  - Added accessor for version in Natto::MeCab
65
82
  - Continuing update of documentation
data/lib/natto/version.rb CHANGED
@@ -16,5 +16,5 @@
16
16
  # which are made available via <tt>FFI</tt> bindings to <tt>mecab</tt>.
17
17
  module Natto
18
18
  # Version string for this Rubygem.
19
- VERSION = "0.1.0"
19
+ VERSION = "0.1.1"
20
20
  end
data/lib/natto.rb CHANGED
@@ -10,29 +10,29 @@ module Natto
10
10
  # initialization.
11
11
  #
12
12
  # <h2>Usage</h2>
13
- # Here is how to use natto under Ruby 1.8.n:<br/>
14
13
  #
15
- # require 'rubygems'
14
+ # require 'rubygems' if RUBY_VERSION.to_f < 1.9
16
15
  # require 'natto'
17
16
  #
18
- # m = Natto::MeCab.new
17
+ # mecab = Natto::MeCab.new
19
18
  # => #<Natto::MeCab:0x28d93dd4 @options={}, \
20
19
  # @dicts=[#<Natto::DictionaryInfo:0x28d93d34>], \
21
- # @ptr=#<FFI::Pointer address=0x28af3e58>>
22
- # puts m.parse("ネバネバの組み合わせ美味しいです。")
20
+ # @ptr=#<FFI::Pointer address=0x28af3e58>, \
21
+ # @version="0.98">
22
+ #
23
+ # puts mecab.parse("ネバネバの組み合わせ美味しいです。")
23
24
  # ネバネバ 名詞,サ変接続,*,*,*,*,ネバネバ,ネバネバ,ネバネバ
24
25
  # の 助詞,連体化,*,*,*,*,の,ノ,ノ
25
26
  # 組み合わせ 名詞,一般,*,*,*,*,組み合わせ,クミアワセ,クミアワセ
26
- # 美味しいです 形容詞,自立,*,*,形容詞・イ段,基本形,美味しい,オイシイ,オイシイ
27
+ # 美味しい 形容詞,自立,*,*,形容詞・イ段,基本形,美味しい,オイシイ,オイシイ
27
28
  # です 助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
28
29
  # 。 デス記号,句点,*,*,*,*,。,。,。
29
30
  # EOS
30
31
  # => nil
31
32
  #
32
- # The <tt>require 'rubygems'</tt> can be omitted for Ruby 1.9.n.
33
33
  class MeCab
34
34
 
35
- attr_reader :options, :dicts
35
+ attr_reader :options, :dicts, :version
36
36
 
37
37
  # Supported options to the <tt>mecab</tt> parser.
38
38
  # See the <tt>mecab</tt> help for more details.
@@ -66,11 +66,13 @@ module Natto
66
66
  # <i>Use single-quotes to preserve format options that contain escape chars.</i><br/>
67
67
  # e.g.<br/>
68
68
  #
69
- # m = Natto::MeCab.new(:node_format=>'%m\t%f[7]\n')
69
+ # mecab = Natto::MeCab.new(:node_format=>'%m\t%f[7]\n')
70
70
  # => #<Natto::MeCab:0x28d8886c @options={:node_format=>"%m\\t%f[7]\\n"}, \
71
71
  # @dicts=[#<Natto::DictionaryInfo:0x28d8863c>], \
72
- # @ptr=#<FFI::Pointer address=0x28e3b268>>
73
- # puts m.parse('簡単で美味しくて良いですよね。')
72
+ # @ptr=#<FFI::Pointer address=0x28e3b268>, \
73
+ # @version="0.98">
74
+ #
75
+ # puts mecab.parse('簡単で美味しくて良いですよね。')
74
76
  # 簡単 カンタン
75
77
  # で デ
76
78
  # 美味しくて オイシクテ
@@ -98,6 +100,8 @@ module Natto
98
100
  @dicts << Natto::DictionaryInfo.new(@dicts.last[:next])
99
101
  end
100
102
 
103
+ @version = Natto::Binding.mecab_version
104
+
101
105
  ObjectSpace.define_finalizer(self, self.class.create_free_proc(@ptr))
102
106
  end
103
107
 
@@ -111,15 +115,11 @@ module Natto
111
115
  raise(MeCabError.new(Natto::Binding.mecab_strerror(@ptr)))
112
116
  end
113
117
 
114
- # Returns the <tt>mecab</tt> version.
115
- #
116
- # @return <tt>mecab</tt> version
117
- def version
118
- Natto::Binding.mecab_version
119
- end
120
-
121
- # Returns a <tt>Proc</tt> that is registered to be invoked
122
- # after the object owning <tt>ptr</tt> has been destroyed.
118
+ # Returns a <tt>Proc</tt> that will properly free resources
119
+ # when this <tt>MeCab</tt> instance is garbage collected.
120
+ # The <tt>Proc</tt> returned is registered to be invoked
121
+ # after the <tt>MeCab</tt> instance owning <tt>ptr</tt>
122
+ # has been destroyed.
123
123
  #
124
124
  # @param [FFI::Pointer] ptr
125
125
  # @return [Proc] to release <tt>mecab</tt> resources properly
@@ -139,6 +139,7 @@ module Natto
139
139
  SUPPORTED_OPTS.each do |k|
140
140
  if options.has_key? k
141
141
  key = k.to_s.gsub('_', '-')
142
+ # all-morphs and partial are just flags
142
143
  if %w( all-morphs partial ).include? key
143
144
  opt << "--#{key}" if options[k]==true
144
145
  else
@@ -171,11 +172,15 @@ module Natto
171
172
  # - :next
172
173
  #
173
174
  # <h2>Usage</h2>
175
+ # <tt>mecab</tt> dictionary attributes can be obtained by
176
+ # using the corresponding accessor.
174
177
  #
175
- # m = Natto::MeCab.new
178
+ # mecab = Natto::MeCab.new
176
179
  # sysdic = m.dicts.first
180
+ #
177
181
  # puts sysdic.filename
178
182
  # => /usr/local/lib/mecab/dic/ipadic/sys.dic
183
+ #
179
184
  # puts sysdic.charset
180
185
  # => utf8
181
186
  #
@@ -185,6 +190,7 @@ module Natto
185
190
  #
186
191
  # puts sysdic[:filename]
187
192
  # => /usr/local/lib/mecab/dic/ipadic/sys.dic
193
+ #
188
194
  # puts sysdic[:charset]
189
195
  # => utf8
190
196
  #
@@ -202,7 +208,13 @@ module Natto
202
208
  # Hack to avoid that deprecation message Object#type.
203
209
  if RUBY_VERSION.to_f < 1.9
204
210
  alias_method :deprecated_type, :type
205
- # @private
211
+ # <tt>Object#type</tt> override defined when <tt>RUBY_VERSION</tt> is
212
+ # less than 1.9. This is a hack to avoid the <tt>Object#type</tt>
213
+ # deprecation warning thrown up in Ruby 1.8.7.
214
+ #
215
+ # <i>This method override is not defined when the Ruby interpreter
216
+ # is 1.9 or greater.</i>
217
+ # @return [Fixnum] <tt>mecab</tt> dictionary type
206
218
  def type
207
219
  self[:type]
208
220
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brooke M. Fujita
@@ -55,7 +55,7 @@ licenses:
55
55
  post_install_message:
56
56
  rdoc_options:
57
57
  - --title
58
- - natto 0.1.0 -- Ruby-Mecab binding
58
+ - natto 0.1.1 -- Ruby-Mecab binding
59
59
  - --main
60
60
  - README.md
61
61
  - -c UTF-8