natto 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -5
- data/lib/natto.rb +19 -12
- data/lib/natto/version.rb +1 -1
- data/test/test_natto.rb +4 -1
- metadata +7 -5
data/README.md
CHANGED
@@ -33,8 +33,7 @@ e.g., for Cygwin
|
|
33
33
|
mecab = Natto::MeCab.new
|
34
34
|
=> #<Natto::MeCab:0x28d93dd4 @options={}, \
|
35
35
|
@dicts=[#<Natto::DictionaryInfo:0x28d93d34>], \
|
36
|
-
@ptr=#<FFI::Pointer address=0x28af3e58
|
37
|
-
@version="0.98">
|
36
|
+
@ptr=#<FFI::Pointer address=0x28af3e58>>
|
38
37
|
|
39
38
|
puts mecab.version
|
40
39
|
=> 0.98
|
@@ -47,7 +46,6 @@ e.g., for Cygwin
|
|
47
46
|
=> utf8
|
48
47
|
|
49
48
|
puts mecab.parse('暑い日にはもってこいの一品ですね。')
|
50
|
-
暑い日にはもってこいの一品ですね。
|
51
49
|
暑い 形容詞,自立,*,*,形容詞・アウオ段,基本形,暑い,アツイ,アツイ
|
52
50
|
日 名詞,非自立,副詞可能,*,*,*,日,ヒ,ヒ
|
53
51
|
に 助詞,格助詞,一般,*,*,*,に,ニ,ニ
|
@@ -72,11 +70,15 @@ e.g., for Cygwin
|
|
72
70
|
|
73
71
|
## Changelog
|
74
72
|
|
73
|
+
- __2011/01/19__: 0.2.0 release.
|
74
|
+
- Added support for mecab option allocate-sentence
|
75
|
+
- Continuing update of documentation
|
76
|
+
|
75
77
|
- __2011/01/15__: 0.1.1 release.
|
76
|
-
-
|
78
|
+
- Refactored Natto::DictionaryInfo#method_missing
|
77
79
|
- Continuing update of documentation
|
78
80
|
|
79
|
-
- __2011/01/
|
81
|
+
- __2011/01/15__: 0.1.0 release.
|
80
82
|
- Added accessors to Natto::DictionaryInfo
|
81
83
|
- Added accessor for version in Natto::MeCab
|
82
84
|
- Continuing update of documentation
|
data/lib/natto.rb
CHANGED
@@ -17,8 +17,7 @@ module Natto
|
|
17
17
|
# mecab = Natto::MeCab.new
|
18
18
|
# => #<Natto::MeCab:0x28d93dd4 @options={}, \
|
19
19
|
# @dicts=[#<Natto::DictionaryInfo:0x28d93d34>], \
|
20
|
-
# @ptr=#<FFI::Pointer address=0x28af3e58
|
21
|
-
# @version="0.98">
|
20
|
+
# @ptr=#<FFI::Pointer address=0x28af3e58>>
|
22
21
|
#
|
23
22
|
# puts mecab.parse("ネバネバの組み合わせ美味しいです。")
|
24
23
|
# ネバネバ 名詞,サ変接続,*,*,*,*,ネバネバ,ネバネバ,ネバネバ
|
@@ -32,14 +31,14 @@ module Natto
|
|
32
31
|
#
|
33
32
|
class MeCab
|
34
33
|
|
35
|
-
attr_reader :options, :dicts
|
34
|
+
attr_reader :options, :dicts
|
36
35
|
|
37
36
|
# Supported options to the <tt>mecab</tt> parser.
|
38
37
|
# See the <tt>mecab</tt> help for more details.
|
39
38
|
SUPPORTED_OPTS = [ :rcfile, :dicdir, :userdic, :lattice_level, :all_morphs,
|
40
39
|
:output_format_type, :partial, :node_format, :unk_format,
|
41
40
|
:bos_format, :eos_format, :eon_format, :unk_feature,
|
42
|
-
:nbest, :theta, :cost_factor ].freeze
|
41
|
+
:allocate_sentence, :nbest, :theta, :cost_factor ].freeze
|
43
42
|
|
44
43
|
# Initializes the wrapped <tt>mecab</tt> instance with the
|
45
44
|
# given <tt>options</tt> hash.
|
@@ -59,6 +58,7 @@ module Natto
|
|
59
58
|
# - :eos_format -- user-defined end-of-sentence format
|
60
59
|
# - :eon_format -- user-defined end-of-NBest format
|
61
60
|
# - :unk_feature -- feature for unknown word
|
61
|
+
# - :allocate_sentence -- allocate new memory for input sentence
|
62
62
|
# - :nbest -- output N best results (integer, default 1)
|
63
63
|
# - :theta -- temperature parameter theta (float, default 0.75)
|
64
64
|
# - :cost_factor -- cost factor (integer, default 700)
|
@@ -69,8 +69,7 @@ module Natto
|
|
69
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
|
-
# @version="0.98">
|
72
|
+
# @ptr=#<FFI::Pointer address=0x28e3b268>>
|
74
73
|
#
|
75
74
|
# puts mecab.parse('簡単で美味しくて良いですよね。')
|
76
75
|
# 簡単 カンタン
|
@@ -100,8 +99,6 @@ module Natto
|
|
100
99
|
@dicts << Natto::DictionaryInfo.new(@dicts.last[:next])
|
101
100
|
end
|
102
101
|
|
103
|
-
@version = Natto::Binding.mecab_version
|
104
|
-
|
105
102
|
ObjectSpace.define_finalizer(self, self.class.create_free_proc(@ptr))
|
106
103
|
end
|
107
104
|
|
@@ -115,6 +112,13 @@ module Natto
|
|
115
112
|
raise(MeCabError.new(Natto::Binding.mecab_strerror(@ptr)))
|
116
113
|
end
|
117
114
|
|
115
|
+
# Returns the <tt>mecab</tt> library version.
|
116
|
+
#
|
117
|
+
# @return [String] <tt>mecab</tt> library version
|
118
|
+
def version
|
119
|
+
Natto::Binding.mecab_version
|
120
|
+
end
|
121
|
+
|
118
122
|
# Returns a <tt>Proc</tt> that will properly free resources
|
119
123
|
# when this <tt>MeCab</tt> instance is garbage collected.
|
120
124
|
# The <tt>Proc</tt> returned is registered to be invoked
|
@@ -139,8 +143,8 @@ module Natto
|
|
139
143
|
SUPPORTED_OPTS.each do |k|
|
140
144
|
if options.has_key? k
|
141
145
|
key = k.to_s.gsub('_', '-')
|
142
|
-
# all-morphs and
|
143
|
-
if %w( all-morphs partial ).include? key
|
146
|
+
# all-morphs, partial, and allocate-sentence are just flags
|
147
|
+
if %w( all-morphs partial allocate-sentence ).include? key
|
144
148
|
opt << "--#{key}" if options[k]==true
|
145
149
|
else
|
146
150
|
opt << "--#{key}=#{options[k]}"
|
@@ -227,8 +231,11 @@ module Natto
|
|
227
231
|
# @raise [NoMethodError] if <tt>methName</tt> is not a member of this <tt>mecab</tt> dictionary <tt>FFI::Struct</tt>
|
228
232
|
def method_missing(methName)
|
229
233
|
member_sym = methName.id2name.to_sym
|
230
|
-
|
231
|
-
|
234
|
+
if self.members.include?(member_sym)
|
235
|
+
self[member_sym]
|
236
|
+
else
|
237
|
+
raise(NoMethodError.new("undefined method '#{methName}' for #{self}"))
|
238
|
+
end
|
232
239
|
end
|
233
240
|
end
|
234
241
|
end
|
data/lib/natto/version.rb
CHANGED
data/test/test_natto.rb
CHANGED
@@ -69,6 +69,9 @@ class TestNatto < Test::Unit::TestCase
|
|
69
69
|
res = Natto::MeCab.build_options_str(:unk_feature=>'%m\t%f[7]\n')
|
70
70
|
assert_equal('--unk-feature=%m\t%f[7]\n', res)
|
71
71
|
|
72
|
+
res = Natto::MeCab.build_options_str(:allocate_sentence=>true)
|
73
|
+
assert_equal('--allocate-sentence', res)
|
74
|
+
|
72
75
|
res = Natto::MeCab.build_options_str(:nbest=>42)
|
73
76
|
assert_equal('--nbest=42', res)
|
74
77
|
|
@@ -102,7 +105,7 @@ class TestNatto < Test::Unit::TestCase
|
|
102
105
|
end
|
103
106
|
assert_equal(opts, m.options)
|
104
107
|
|
105
|
-
opts = {:all_morphs=>true, :partial=>true}
|
108
|
+
opts = {:all_morphs=>true, :partial=>true, :allocate_sentence=>true}
|
106
109
|
assert_nothing_raised do
|
107
110
|
m = Natto::MeCab.new(opts)
|
108
111
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brooke M. Fujita
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-20 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -54,8 +54,10 @@ licenses:
|
|
54
54
|
- BSD
|
55
55
|
post_install_message:
|
56
56
|
rdoc_options:
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
57
59
|
- --title
|
58
|
-
- natto 0.
|
60
|
+
- natto 0.2.0 -- Ruby-Mecab binding
|
59
61
|
- --main
|
60
62
|
- README.md
|
61
63
|
- -c UTF-8
|