mecab-ext 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86a39f9280e431a9e303a48b944241abd455bafa
4
- data.tar.gz: 7e35368ddb085a3043299f68ea15ce15d331053a
3
+ metadata.gz: 4dc676d5e4c1a78ca8abfc4f512a713ebe433559
4
+ data.tar.gz: 279467bf6ad5b0bb7113076aaaf7a91ee63ab3cd
5
5
  SHA512:
6
- metadata.gz: 9a9b8065e323666f937788134a60e292974e825ccebc8ceb8a94f798e31aeb215ec38210a9e45809a949c9710426429cf41053a66b9f4a4f6333c27121385e51
7
- data.tar.gz: 52a6dae9f4b862290fc6fc2d9d05e378c9b66884b1ff9e009955ca3a7359380fa32af4a04a461da054420d88d4a5e17c3035195c304fe54261cdbc76d5fda394
6
+ metadata.gz: 748528cc0005a661b828c11b275015cf3333a5002a4a719bebb19ead76ca23f54c2fb43cd13d04134f918146ace85cbba9e9f10904891d181b2e969b302eee52
7
+ data.tar.gz: 677af930e706ebcdfd6db45cf5949a6a474366a687af422a59db12ec2aef077892e53336c675f1e30a0405b6588035f0ad4332a5049a62e9304b51d21a1a4cca
data/README.md CHANGED
@@ -37,12 +37,21 @@ nodes.each {|node| p node }
37
37
  # Extented node class has Enumerable methods
38
38
  nodes.map {|node| node.surface }
39
39
  nodes.select {|node| node.surface == "テスト" }
40
+ nodes.map {|n| n.surface }.join
40
41
 
41
42
  # If you need only surfaces, call Mecab::Ext::Node#each_surface
42
43
  nodes.each_surface {|surface| p surface }
43
44
 
45
+ # Iterate original node's method returns
46
+ nodes.surfaces.each {|surface| p surface }
47
+ nodes.surfaces.select {|surface| surface == "テスト" }
48
+
49
+ %w(surfaces features lengths ids char_types isbests wcosts costs).each do |name|
50
+ nodes.respond_to? name #=> true
51
+ end
52
+
44
53
  # mecab-ext cuts beginning of line node and end of line node for handiness
45
- nodes.size #=> 2
54
+ nodes.count #=> 2
46
55
  ```
47
56
 
48
57
  ## Contributing
@@ -1,3 +1,4 @@
1
+ require "active_support/inflector"
1
2
  require "active_support/core_ext/module/delegation"
2
3
  require "MeCab"
3
4
 
@@ -11,14 +11,7 @@ module Mecab
11
11
  end
12
12
 
13
13
  def to_enum
14
- Enumerator.new do |y|
15
- node = @generator.call
16
- while node
17
- node = node.next
18
- y << node if node.respond_to?(:surface) && !node.surface.empty?
19
- end
20
- self
21
- end
14
+ gen_enumrator
22
15
  end
23
16
 
24
17
  def each_surface
@@ -28,6 +21,28 @@ module Mecab
28
21
  def each_feature
29
22
  each {|node| yield node.feature }
30
23
  end
24
+
25
+ %w(surfaces features lengths ids char_types isbests wcosts costs).each do |plural_name|
26
+ define_method(plural_name) do
27
+ gen_enumrator(plural_name.singularize)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def gen_enumrator(name = nil)
34
+ Enumerator.new do |y|
35
+ node = @generator.call
36
+ while node
37
+ node = node.next
38
+ unless node.nil? || node.surface.empty?
39
+ y << (name ? node.__send__(name) : node)
40
+ end
41
+ end
42
+ self
43
+ end
44
+ end
45
+
31
46
  end
32
47
  end
33
48
  end
@@ -1,5 +1,5 @@
1
1
  module Mecab
2
2
  module Ext
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -53,7 +53,10 @@ describe Mecab::Ext::Node do
53
53
  end
54
54
 
55
55
  context "with node mocks" do
56
- let(:node) { mock("node").tap {|o| o.stub(:next).and_return(nil) } }
56
+ let(:node) do
57
+ n = mock("node").tap {|o| o.stub(:next).and_return(nil) }
58
+ n.tap {|o| o.should_receive(:surface).and_return("test") }
59
+ end
57
60
  let(:parent_node) { mock("node").tap {|o| o.should_receive(:next).and_return(node) } }
58
61
  let(:generator) { double("generator").tap {|o| o.stub(:call).and_return(parent_node) } }
59
62
  subject { described_class.new(generator) }
@@ -93,7 +96,8 @@ describe Mecab::Ext::Node do
93
96
 
94
97
  it "yields each surface" do
95
98
  subject.each_surface {|surface| tests.push surface }
96
- expect(tests).to eq ["test", "string"]
99
+ expect(tests).to be_include "test"
100
+ expect(tests).to be_include "string"
97
101
  end
98
102
  end
99
103
  end
@@ -107,9 +111,46 @@ describe Mecab::Ext::Node do
107
111
 
108
112
  it "yields each features" do
109
113
  subject.each_feature {|feature| tests.push feature }
110
- expect(tests).to eq ["test feature", "string feature"]
114
+ expect(tests).to be_include "test feature"
115
+ expect(tests).to be_include "string feature"
111
116
  end
112
117
  end
113
118
  end
114
119
 
120
+ describe "its plural methods" do
121
+ context %(with mecab nodes which given "test string"), mecab: :nodes do
122
+
123
+ describe "#surfaces" do
124
+ it "returns enumerator" do
125
+ expect(subject.surfaces).to be_instance_of Enumerator
126
+ end
127
+
128
+ it "iterates nodes surfaces" do
129
+ subject.surfaces.each {|surface| tests.push surface }
130
+ expect(tests).to have(2).surfaces
131
+ expect(tests).to be_include "test"
132
+ expect(tests).to be_include "string"
133
+ end
134
+
135
+ it "can fold" do
136
+ expect(subject.surfaces.reduce("", &:+)).to eq "teststring"
137
+ end
138
+ end
139
+
140
+ %w(features lengths ids char_types isbests wcosts costs).each do |name|
141
+ describe "##{name}" do
142
+ it "iterates #{name}" do
143
+ expect(subject.send(name)).to be_instance_of Enumerator
144
+ end
145
+
146
+ it "iterates #{name.singularize} value" do
147
+ second_node.stub(name.singularize).and_return(:test)
148
+ subject.send(name) {|test| expect(test).to equal :test }
149
+ end
150
+ end
151
+ end
152
+
153
+ end
154
+ end
155
+
115
156
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mecab-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki ONO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-09 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport