mecab-light 0.2.2 → 0.2.3

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: 974e912e189f8360bb6262bd58cd1d429bf3c0e8
4
- data.tar.gz: 30c75d49c243b6607af51332cff756d882760cf3
3
+ metadata.gz: c610ca8725dff12d78f4c8e57aed3a669cb4dfd9
4
+ data.tar.gz: 2c7400b6c7355e26bf1cf0c11f9dbd9a98401330
5
5
  SHA512:
6
- metadata.gz: 00e60f2b160e885a58cbab9ce939b62846968e89b2b34d8fb18ba6cb658041297b9272949b0939b535f1e934ad89c96d0ba31e11d1deeb04165aa07d878dc4c0
7
- data.tar.gz: 98223a90310d0be19a82f7084faaf4536431b2ec4e4ed25547c9b3c87f3969f4e3731726ee005c41438b7eb0d1b6f1c6625d800834496a60b778bdf28a27aaa4
6
+ metadata.gz: 68e644215d1733e15152650d68923532d20e6cfeae91f0150f1e8b9c9b56503ce42cfc090c9d5cc4f6db26ce971784117d081937d2c61507b8d80c93e9ccaa6d
7
+ data.tar.gz: df72e4d97b55674761e303e218d8087bf470e9d730be9017eaef8a059bff3a53fbb5c85938f00bc00e79099b6a03e8fb4bac028fafaddc9a408cc5dd4de27cf2
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 2.0.0
data/README.md CHANGED
@@ -18,10 +18,10 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- This gem works without official binding.
22
- MeCab::Light is a 'light' tool.
23
- This supports only the 'parse' method for now,
24
- and the method's feature is totally different from its original.
21
+ MeCab::Light is a lightweight tool.
22
+ This gem works without the official binding.
23
+ This supports only Tagger#parse method for now.
24
+ Note that the method's feature is totally different from its original.
25
25
 
26
26
  ```ruby
27
27
  require 'mecab/light'
@@ -31,7 +31,7 @@ string = 'この文を形態素解析してください。'
31
31
  result = tagger.parse(string)
32
32
  result[0].surface #=> "この"
33
33
  result.kind_of?(Enumerable) #=> true
34
- result.map{|morpheme| morpheme.surface }
34
+ result.map { |morpheme| morpheme.surface }
35
35
  #=> ["この", "文", "を", "形態素", "解析", "し", "て", "ください", "。"]
36
36
  ```
37
37
 
@@ -2,52 +2,49 @@
2
2
  #include <ruby/encoding.h>
3
3
  #include <mecab.h>
4
4
 
5
- struct binding {
6
- mecab_t* mecab;
7
- };
5
+ typedef struct {
6
+ mecab_t* ptr;
7
+ } MeCab;
8
8
 
9
9
  static VALUE
10
- binding_alloc(VALUE klass)
10
+ mecab_alloc(VALUE klass)
11
11
  {
12
- struct binding* ptr = ALLOC(struct binding);
13
- return Data_Wrap_Struct(klass, 0, -1, ptr);
12
+ MeCab* mecab = ALLOC(MeCab);
13
+ return Data_Wrap_Struct(klass, 0, 0, mecab);
14
14
  }
15
15
 
16
16
  static VALUE
17
- rb_mecab_light_binding_initialize(VALUE self, VALUE arg)
17
+ rb_mecab_initialize(VALUE self, VALUE arg)
18
18
  {
19
- struct binding* ptr;
19
+ MeCab* mecab;
20
20
 
21
- Data_Get_Struct(self, struct binding, ptr);
22
- ptr->mecab = mecab_new2(RSTRING_PTR(arg));
21
+ Data_Get_Struct(self, MeCab, mecab);
22
+ mecab->ptr = mecab_new2(RSTRING_PTR(arg));
23
23
  return Qnil;
24
24
  }
25
25
 
26
26
  static VALUE
27
- rb_mecab_light_binding_parse_to_s(VALUE self, VALUE str)
27
+ rb_mecab_parse_to_s(VALUE self, VALUE str)
28
28
  {
29
- struct binding* ptr;
29
+ MeCab* mecab;
30
30
  const char* result;
31
31
  rb_encoding* enc;
32
32
 
33
- Data_Get_Struct(self, struct binding, ptr);
33
+ Data_Get_Struct(self, MeCab, mecab);
34
34
  enc = rb_enc_get(str);
35
- result = mecab_sparse_tostr(ptr->mecab, RSTRING_PTR(str));
35
+ result = mecab_sparse_tostr(mecab->ptr, RSTRING_PTR(str));
36
36
  return rb_enc_associate(rb_str_new2(result), enc);
37
37
  }
38
38
 
39
39
  void
40
40
  Init_binding()
41
41
  {
42
- VALUE rb_mMeCab, rb_mMeCab_Light, rb_cMeCab_Light_Binding;
42
+ VALUE rb_mMeCab, rb_mLight, rb_cBinding;
43
43
 
44
44
  rb_mMeCab = rb_define_module("MeCab");
45
- rb_mMeCab_Light = rb_define_module_under(rb_mMeCab, "Light");
46
- rb_cMeCab_Light_Binding = rb_define_class_under(rb_mMeCab_Light,
47
- "Binding", rb_cObject);
48
- rb_define_alloc_func(rb_cMeCab_Light_Binding, binding_alloc);
49
- rb_define_private_method(rb_cMeCab_Light_Binding, "initialize",
50
- rb_mecab_light_binding_initialize, 1);
51
- rb_define_method(rb_cMeCab_Light_Binding, "parse_to_s",
52
- rb_mecab_light_binding_parse_to_s, 1);
45
+ rb_mLight = rb_define_module_under(rb_mMeCab, "Light");
46
+ rb_cBinding = rb_define_class_under(rb_mLight, "Binding", rb_cObject);
47
+ rb_define_alloc_func(rb_cBinding, mecab_alloc);
48
+ rb_define_private_method(rb_cBinding, "initialize", rb_mecab_initialize, 1);
49
+ rb_define_method(rb_cBinding, "parse_to_s", rb_mecab_parse_to_s, 1);
53
50
  }
@@ -1,5 +1,12 @@
1
1
  require 'mkmf'
2
2
 
3
+ begin
4
+ require 'Win32API'
5
+
6
+ dir_config('opt', 'c:\MeCab\sdk', 'c:\MeCab\bin')
7
+ rescue LoadError
8
+ end
9
+
3
10
  if have_header('mecab.h') && have_library('mecab')
4
11
  create_makefile('mecab/light/binding')
5
12
  else
@@ -2,8 +2,9 @@ module MeCab
2
2
  module Light
3
3
  class Result
4
4
  include Enumerable
5
- def initialize(line_enum)
6
- @morphemes = line_enum.map{|line| Morpheme.new(line) }
5
+
6
+ def initialize(parsed)
7
+ @morphemes = parsed.each_line.map { |line| Morpheme.new(line) }
7
8
  end
8
9
 
9
10
  def each(&block)
@@ -6,12 +6,12 @@ module MeCab
6
6
  end
7
7
 
8
8
  def parse(string)
9
- Result.new(parse_to_enum(string))
9
+ Result.new(parse_to_s(string))
10
10
  end
11
11
 
12
12
  private
13
- def parse_to_enum(string)
14
- @mecab.parse_to_s(string).sub(/EOS\n$/, '').each_line
13
+ def parse_to_s(string)
14
+ @mecab.parse_to_s(string).sub(/EOS\n$/, '')
15
15
  end
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module MeCab
2
2
  module Light
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe MeCab::Light::Morpheme do
4
+ let(:morpheme) { MeCab::Light::Morpheme.new("surface\tfeature\n") }
5
+
6
+ context 'the class' do
7
+ it { expect(MeCab::Light::Morpheme).to respond_to(:new).with(1).argument }
8
+ end
9
+
10
+ context 'an instance initialized with "surface\tfeature\n"' do
11
+ it { expect(morpheme).to respond_to(:surface).with(0).arguments }
12
+ it { expect(morpheme).to respond_to(:feature).with(0).arguments }
13
+
14
+ context 'surface' do
15
+ it { expect(morpheme.surface).to eq('surface') }
16
+
17
+ context 'encoding' do
18
+ it { expect(morpheme.surface.encoding).to eq(Encoding::UTF_8) }
19
+ end
20
+ end
21
+
22
+ context 'feature' do
23
+ it { expect(morpheme.feature).to eq('feature') }
24
+
25
+ context 'encoding' do
26
+ it { expect(morpheme.feature.encoding).to eq(Encoding::UTF_8) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe MeCab::Light::Result do
4
+ let(:morpheme) { double('MeCab::Light::Morpheme') }
5
+ let(:result) { MeCab::Light::Result.new("surface\tfeature\n") }
6
+ before do
7
+ MeCab::Light::Morpheme.stub(:new).and_return(morpheme)
8
+ end
9
+
10
+ context 'class' do
11
+ it { expect(MeCab::Light::Result).to respond_to(:new).with(1).argument }
12
+
13
+ context 'new with "surface\tfeature\n"' do
14
+ context 'MeCab::Light::Morpheme class' do
15
+ after do
16
+ MeCab::Light::Result.new("surface\tfeature\n")
17
+ end
18
+
19
+ it 'should receive #new with "surface\tfeature\n"' do
20
+ expect(MeCab::Light::Morpheme).to receive(:new).with("surface\tfeature\n")
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'an instance initialized with ""' do
27
+ it { expect(result).to respond_to(:each).with(0).arguments }
28
+ it { expect(result).to be_an(Enumerable) }
29
+
30
+ context 'count' do
31
+ it { expect(result.count).to eq(1) }
32
+ end
33
+
34
+ context 'each' do
35
+ context 'with block' do
36
+ it 'should return self' do
37
+ expect(result.each{}).to eq(result)
38
+ end
39
+ it { expect { |b| result.each(&b) }.to yield_control }
40
+ it 'should yield with args(MeCab::Light::Morpheme)' do
41
+ expect { |b| result.each(&b) }.to yield_with_args(morpheme)
42
+ end
43
+ end
44
+
45
+ context 'without block' do
46
+ it { expect(result.each).to be_an_instance_of(Enumerator) }
47
+ end
48
+ end
49
+
50
+ context '[] with 0' do
51
+ it 'should be an instance of Morpheme' do
52
+ expect(result[0]).to eq(morpheme)
53
+ end
54
+ end
55
+
56
+ context 'at with 0' do
57
+ it 'should be an instance of Morpheme' do
58
+ expect(result.at(0)).to eq(morpheme)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe MeCab::Light::Tagger do
4
+ let(:binding) { double( parse_to_s: "surface\tfeature\nEOS\n" ) }
5
+ let(:result) { double('MeCab::Light::Result') }
6
+ let(:tagger) { MeCab::Light::Tagger.new }
7
+ before do
8
+ MeCab::Light::Binding.stub(:new).and_return(binding)
9
+ MeCab::Light::Result.stub(:new).and_return(result)
10
+ end
11
+
12
+ context 'the class' do
13
+ it { expect(MeCab::Light::Tagger).to respond_to(:new).with(0).arguments }
14
+
15
+ context 'new' do
16
+ context 'MeCab::Light::Binding class' do
17
+ after do
18
+ MeCab::Light::Tagger.new
19
+ end
20
+
21
+ it 'should receive #new with ""' do
22
+ expect(MeCab::Light::Binding).to receive(:new).with('')
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'an instance' do
29
+ it { expect(tagger).to respond_to(:parse).with(1).argument }
30
+
31
+ context 'parse with "surface"' do
32
+ it 'should be an instance of MeCab::Light::Result' do
33
+ expect(tagger.parse('surface')).to eq(result)
34
+ end
35
+
36
+ context 'MeCab::Light::Result class' do
37
+ after do
38
+ tagger.parse('surface')
39
+ end
40
+
41
+ it 'should receive #new with "surface\tfeature\n"' do
42
+ expect(MeCab::Light::Result).to receive(:new).with("surface\tfeature\n")
43
+ end
44
+ end
45
+
46
+ context 'a MeCab::Light::Binding object' do
47
+ after do
48
+ tagger.parse('surface')
49
+ end
50
+
51
+ it 'should receive #parse_to_s with "surface"' do
52
+ expect(binding).to receive(:parse_to_s).with('surface')
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'mecab/light/morpheme'
4
+ require 'mecab/light/result'
5
+ require 'mecab/light/tagger'
6
+
7
+ class MeCab::Light::Binding
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mecab-light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hajime WAKAHARA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -47,6 +47,7 @@ extensions:
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - .gitignore
50
+ - .travis.yml
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
@@ -59,7 +60,10 @@ files:
59
60
  - lib/mecab/light/tagger.rb
60
61
  - lib/mecab/light/version.rb
61
62
  - mecab-light.gemspec
62
- - spec/mecab_spec.rb
63
+ - spec/mecab-light-morpheme_spec.rb
64
+ - spec/mecab-light-result_spec.rb
65
+ - spec/mecab-light-tagger_spec.rb
66
+ - spec/spec_helper.rb
63
67
  homepage: https://github.com/hadzimme/mecab-light
64
68
  licenses: []
65
69
  metadata: {}
@@ -79,9 +83,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  version: '0'
80
84
  requirements: []
81
85
  rubyforge_project:
82
- rubygems_version: 2.0.0
86
+ rubygems_version: 2.1.9
83
87
  signing_key:
84
88
  specification_version: 4
85
89
  summary: An simple interface for MeCab (UNOFFICIAL)
86
90
  test_files:
87
- - spec/mecab_spec.rb
91
+ - spec/mecab-light-morpheme_spec.rb
92
+ - spec/mecab-light-result_spec.rb
93
+ - spec/mecab-light-tagger_spec.rb
94
+ - spec/spec_helper.rb
data/spec/mecab_spec.rb DELETED
@@ -1,110 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'rspec'
4
- begin
5
- require 'mecab/light'
6
- rescue LoadError
7
- puts 'loaded mecab-light but MeCab does not exist.'
8
- puts 'dummy binding will be loaded.'
9
- end
10
-
11
- module MeCab
12
- module Light
13
- class Binding
14
- def initialize(option)
15
- end
16
-
17
- def parse_to_s(string)
18
- "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
19
- end
20
- end
21
- end
22
- end
23
-
24
- describe MeCab::Light::Morpheme do
25
- context 'when initialized with the result line of the word "見る"' do
26
- before do
27
- @morpheme = MeCab::Light::Morpheme.new(
28
- "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n")
29
- end
30
- subject { @morpheme }
31
- its(:surface){ should eq '見る' }
32
- its(:feature){ should eq '動詞,自立,*,*,一段,基本形,見る,ミル,ミル' }
33
- describe 'surface' do
34
- subject { @morpheme.surface }
35
- its(:encoding){ should be Encoding::UTF_8 }
36
- end
37
- describe 'feature' do
38
- subject { @morpheme.feature }
39
- its(:encoding){ should be Encoding::UTF_8 }
40
- end
41
- end
42
- end
43
- describe MeCab::Light::Result do
44
- context 'when initialized with the result Enumerator of the word "見る"' do
45
- before do
46
- @result = MeCab::Light::Result.new(
47
- ["見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\n"].to_enum)
48
- end
49
- subject { @result }
50
- it { should respond_to :each }
51
- it { should be_an Enumerable }
52
- its(:count){ should be 1 }
53
- describe 'each' do
54
- context 'with block' do
55
- subject { @result.each{} }
56
- it 'should return self' do
57
- should be @result
58
- end
59
- end
60
- context 'without block' do
61
- subject { @result.each }
62
- it 'should return Enumerator' do
63
- should be_an_instance_of Enumerator
64
- end
65
- end
66
- end
67
- describe '[]' do
68
- context 'when argument 0' do
69
- subject { @result[0] }
70
- it { should be_an_instance_of MeCab::Light::Morpheme }
71
- end
72
- end
73
- describe 'at' do
74
- context 'when argument 0' do
75
- subject { @result.at(0) }
76
- it { should be_an_instance_of MeCab::Light::Morpheme }
77
- end
78
- end
79
- end
80
- end
81
- describe MeCab::Light::Tagger do
82
- before { @tagger = MeCab::Light::Tagger.new }
83
- subject { @tagger }
84
- it { should respond_to :parse }
85
- describe 'parse' do
86
- context 'when argument "見る"' do
87
- before { @result = @tagger.parse('見る') }
88
- subject { @result }
89
- it 'should return MeCab::Light::Result object' do
90
- should be_an_instance_of MeCab::Light::Result
91
- end
92
- its(:count){ should be 1 }
93
- describe 'MeCab::Light::Result (returned)' do
94
- context '[0]' do
95
- before { @morpheme = @result[0] }
96
- subject { @morpheme }
97
- it 'should return MeCab::Light::Morpheme object' do
98
- should be_an_instance_of MeCab::Light::Morpheme
99
- end
100
- describe 'MeCab::Light::Morpheme (returned)' do
101
- context 'surface' do
102
- subject { @morpheme.surface }
103
- it { should eq '見る' }
104
- end
105
- end
106
- end
107
- end
108
- end
109
- end
110
- end