mecab-light 0.1.1 → 0.2.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: 9bc1034d15fd3f35b2b1ad7d0ef37c2cc73cc827
4
- data.tar.gz: cfbdc262474d9d30a56e9963e9f8b586f319dd33
3
+ metadata.gz: 8a5511af0c985b3d07f4d529ca04c7138657867c
4
+ data.tar.gz: 89da28098265ec53e39c01bd3b6fedc75ff614f5
5
5
  SHA512:
6
- metadata.gz: 1880e49178c264d6c9fb4e702d022d41742f2f6d9d0f9c46fd25367b155744b55c61518063d03e743dcd9734f10b306070c06bf6ff678f2d29ddcefc9203b614
7
- data.tar.gz: aa31d0b6a51a66a097815dc30ca973a20fb23d468a8f1ef8cf68ff562f23cf409f4087fe2deaaeea13b23a84a2ed9acba32706ddd781bca038c9f77ed20bfdcf
6
+ metadata.gz: f1a8cbd1738fcab2d3b3d508cd45440c3755791fe8a061704ba91dad37aef5254719c42f60820ad3fdbf533de9101170e159b57c4cf7bed7529e19a4cec5d52e
7
+ data.tar.gz: 29244fa47f165c0e26ddffc1e8a733fa97945250988a82ff088eea7da13dde505c4877c7acf51fe9d89b54119d3a8b839e09f2244515f7b46330e7a7b1572040
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
- # mecab-light [![Build Status](https://travis-ci.org/hadzimme/mecab-light.png)](https://travis-ci.org/hadzimme/mecab-light)
1
+ # MeCab::Light [![Build Status](https://travis-ci.org/hadzimme/mecab-light.png)](https://travis-ci.org/hadzimme/mecab-light)
2
2
 
3
3
  Use a sequence of results as an Enumerable object.
4
4
 
5
5
  ## Installation
6
6
 
7
- At first, install the official gem "mecab-ruby" manually.
7
+ This gem works without official binding.
8
+ MeCab::Light is a 'light' tool.
9
+ This supports only the 'parse' method for now,
10
+ and the method's feature is totally different from its original.
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
@@ -0,0 +1,10 @@
1
+ module MeCab
2
+ module Light
3
+ module Binding
4
+ extend FFI::Library
5
+ ffi_lib 'mecab'
6
+ attach_function :mecab_new2, [:string], :pointer
7
+ attach_function :mecab_sparse_tostr, [:pointer, :string], :string
8
+ end
9
+ end
10
+ end
@@ -1,12 +1,22 @@
1
1
  module MeCab
2
2
  module Light
3
3
  class Tagger
4
- def initialize(*args)
5
- @core_tagger = MeCab::Tagger.new(*args)
4
+ def initialize
5
+ @mecab = Binding.mecab_new2('')
6
6
  end
7
7
 
8
8
  def parse(string)
9
- Result.new(@core_tagger.parse_to_enum(string))
9
+ Result.new(parse_to_enum(string))
10
+ end
11
+
12
+ private
13
+ def parse_to_enum(string)
14
+ parse_to_str(string).sub(/EOS\n$/, '').each_line
15
+ end
16
+
17
+ def parse_to_str(string)
18
+ encoding = Encoding.default_external
19
+ Binding.mecab_sparse_tostr(@mecab, string).force_encoding(encoding)
10
20
  end
11
21
  end
12
22
  end
@@ -1,5 +1,5 @@
1
1
  module MeCab
2
2
  module Light
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/mecab/light.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'MeCab'
2
- require 'mecab/tagger'
1
+ require 'ffi'
3
2
  require 'mecab/light/version'
4
3
  require 'mecab/light/morpheme'
5
4
  require 'mecab/light/result'
6
5
  require 'mecab/light/tagger'
6
+ require 'mecab/light/binding'
data/mecab-light.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.required_ruby_version = '>= 1.9'
20
20
 
21
+ gem.add_runtime_dependency 'ffi'
22
+
21
23
  gem.add_development_dependency 'rake'
22
24
  gem.add_development_dependency 'rspec'
23
25
  end
data/spec/mecab_spec.rb CHANGED
@@ -1,9 +1,27 @@
1
1
  # coding: utf-8
2
2
 
3
- $:.unshift(File.expand_path(File.dirname(__FILE__)) + '/lib')
4
-
5
3
  require 'rspec'
6
- require 'mecab/light'
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
+ module Binding
14
+ def self.mecab_new2(arg)
15
+ :dummy_mecab
16
+ end
17
+
18
+ def self.mecab_sparse_tostr(mecab, string)
19
+ result = "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
20
+ result.force_encoding('ASCII-8BIT')
21
+ end
22
+ end
23
+ end
24
+ end
7
25
 
8
26
  describe MeCab::Light::Morpheme do
9
27
  context 'when initialized with the result line of the word "見る"' do
@@ -14,11 +32,11 @@ describe MeCab::Light::Morpheme do
14
32
  subject { @morpheme }
15
33
  its(:surface){ should eq '見る' }
16
34
  its(:feature){ should eq '動詞,自立,*,*,一段,基本形,見る,ミル,ミル' }
17
- describe '#surface' do
35
+ describe 'surface' do
18
36
  subject { @morpheme.surface }
19
37
  its(:encoding){ should be Encoding::UTF_8 }
20
38
  end
21
- describe '#feature' do
39
+ describe 'feature' do
22
40
  subject { @morpheme.feature }
23
41
  its(:encoding){ should be Encoding::UTF_8 }
24
42
  end
@@ -34,7 +52,7 @@ describe MeCab::Light::Result do
34
52
  it { should respond_to :each }
35
53
  it { should be_an Enumerable }
36
54
  its(:count){ should be 1 }
37
- describe '#each' do
55
+ describe 'each' do
38
56
  context 'with block' do
39
57
  subject { @result.each{} }
40
58
  it 'should return self' do
@@ -48,13 +66,13 @@ describe MeCab::Light::Result do
48
66
  end
49
67
  end
50
68
  end
51
- describe '#[]' do
69
+ describe '[]' do
52
70
  context 'when argument 0' do
53
71
  subject { @result[0] }
54
72
  it { should be_an_instance_of MeCab::Light::Morpheme }
55
73
  end
56
74
  end
57
- describe '#at' do
75
+ describe 'at' do
58
76
  context 'when argument 0' do
59
77
  subject { @result.at(0) }
60
78
  it { should be_an_instance_of MeCab::Light::Morpheme }
@@ -62,25 +80,11 @@ describe MeCab::Light::Result do
62
80
  end
63
81
  end
64
82
  end
65
- describe MeCab::Tagger do
66
- before { @tagger = MeCab::Tagger.new }
67
- subject { @tagger }
68
- it { should respond_to :parse_to_enum }
69
- describe '#parse_to_enum' do
70
- context 'when argument "見る"' do
71
- subject { @tagger.parse_to_enum('見る') }
72
- it 'should return Enumerator' do
73
- should be_an_instance_of Enumerator
74
- end
75
- its(:count){ should be 1 }
76
- end
77
- end
78
- end
79
83
  describe MeCab::Light::Tagger do
80
84
  before { @tagger = MeCab::Light::Tagger.new }
81
85
  subject { @tagger }
82
86
  it { should respond_to :parse }
83
- describe '#parse' do
87
+ describe 'parse' do
84
88
  context 'when argument "見る"' do
85
89
  before { @result = @tagger.parse('見る') }
86
90
  subject { @result }
@@ -88,15 +92,15 @@ describe MeCab::Light::Tagger do
88
92
  should be_an_instance_of MeCab::Light::Result
89
93
  end
90
94
  its(:count){ should be 1 }
91
- describe 'returned MeCab::Light::Result object' do
92
- context '#[0]' do
95
+ describe 'MeCab::Light::Result (returned)' do
96
+ context '[0]' do
93
97
  before { @morpheme = @result[0] }
94
98
  subject { @morpheme }
95
99
  it 'should return MeCab::Light::Morpheme object' do
96
100
  should be_an_instance_of MeCab::Light::Morpheme
97
101
  end
98
- describe 'returned MeCab::Light::Morpheme object' do
99
- context '#surface' do
102
+ describe 'MeCab::Light::Morpheme (returned)' do
103
+ context 'surface' do
100
104
  subject { @morpheme.surface }
101
105
  it { should eq '見る' }
102
106
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mecab-light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
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-03-19 00:00:00.000000000 Z
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -51,13 +65,12 @@ files:
51
65
  - README.md
52
66
  - Rakefile
53
67
  - lib/mecab/light.rb
68
+ - lib/mecab/light/binding.rb
54
69
  - lib/mecab/light/morpheme.rb
55
70
  - lib/mecab/light/result.rb
56
71
  - lib/mecab/light/tagger.rb
57
72
  - lib/mecab/light/version.rb
58
- - lib/mecab/tagger.rb
59
73
  - mecab-light.gemspec
60
- - spec/lib/MeCab.rb
61
74
  - spec/mecab_spec.rb
62
75
  homepage: https://github.com/hadzimme/mecab-light
63
76
  licenses: []
@@ -83,5 +96,4 @@ signing_key:
83
96
  specification_version: 4
84
97
  summary: A Thin Wrapper for mecab-ruby
85
98
  test_files:
86
- - spec/lib/MeCab.rb
87
99
  - spec/mecab_spec.rb
data/lib/mecab/tagger.rb DELETED
@@ -1,7 +0,0 @@
1
- module MeCab
2
- class Tagger
3
- def parse_to_enum(string)
4
- self.parse(string).sub(/EOS\n$/, '').each_line
5
- end
6
- end
7
- end
data/spec/lib/MeCab.rb DELETED
@@ -1,9 +0,0 @@
1
- # coding: utf-8
2
-
3
- module MeCab
4
- class Tagger
5
- def parse(string)
6
- "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
7
- end
8
- end
9
- end