mecab-light 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a5511af0c985b3d07f4d529ca04c7138657867c
4
- data.tar.gz: 89da28098265ec53e39c01bd3b6fedc75ff614f5
3
+ metadata.gz: 77a05bf9485489ccba812f53eb6976d9688fa170
4
+ data.tar.gz: 5352eec6b99dd1f96754a70a54e06d0c8e773c68
5
5
  SHA512:
6
- metadata.gz: f1a8cbd1738fcab2d3b3d508cd45440c3755791fe8a061704ba91dad37aef5254719c42f60820ad3fdbf533de9101170e159b57c4cf7bed7529e19a4cec5d52e
7
- data.tar.gz: 29244fa47f165c0e26ddffc1e8a733fa97945250988a82ff088eea7da13dde505c4877c7acf51fe9d89b54119d3a8b839e09f2244515f7b46330e7a7b1572040
6
+ metadata.gz: 11117258db644f31ae7fd45f2c7df69aa474aaebf34b3945d1defa1deced0514f155206904f7065c5beeaaaaaf9fe27baa71852c6905f31ba57e4a080381655a
7
+ data.tar.gz: 162454bcaede7008c631d391204e86b48a36064e3eac4ebb5d31c3a4cb93497c9951b46929ad56cb33ce8a15352895409651b798be6dc175c2450cc9043faf5a
data/README.md CHANGED
@@ -4,11 +4,6 @@ Use a sequence of results as an Enumerable object.
4
4
 
5
5
  ## Installation
6
6
 
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.
11
-
12
7
  Add this line to your application's Gemfile:
13
8
 
14
9
  gem 'mecab-light'
@@ -23,6 +18,11 @@ Or install it yourself as:
23
18
 
24
19
  ## Usage
25
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.
25
+
26
26
  ```ruby
27
27
  require 'mecab/light'
28
28
 
data/ext/extconf.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ if have_header('mecab.h') && have_library('mecab')
4
+ create_makefile('mecab_light_binding')
5
+ else
6
+ puts 'Install MeCab and give it another try.'
7
+ end
@@ -0,0 +1,53 @@
1
+ #include <ruby.h>
2
+ #include <ruby/encoding.h>
3
+ #include <mecab.h>
4
+
5
+ struct binding {
6
+ mecab_t* mecab;
7
+ };
8
+
9
+ static VALUE
10
+ binding_alloc(VALUE klass)
11
+ {
12
+ struct binding* ptr = ALLOC(struct binding);
13
+ return Data_Wrap_Struct(klass, 0, -1, ptr);
14
+ }
15
+
16
+ static VALUE
17
+ rb_mecab_light_binding_initialize(VALUE self, VALUE arg)
18
+ {
19
+ struct binding* ptr;
20
+
21
+ Data_Get_Struct(self, struct binding, ptr);
22
+ ptr->mecab = mecab_new2(RSTRING_PTR(arg));
23
+ return Qnil;
24
+ }
25
+
26
+ static VALUE
27
+ rb_mecab_light_binding_parse_to_s(VALUE self, VALUE str)
28
+ {
29
+ struct binding* ptr;
30
+ const char* result;
31
+ rb_encoding* enc;
32
+
33
+ Data_Get_Struct(self, struct binding, ptr);
34
+ enc = rb_enc_get(str);
35
+ result = mecab_sparse_tostr(ptr->mecab, RSTRING_PTR(str));
36
+ return rb_enc_associate(rb_str_new2(result), enc);
37
+ }
38
+
39
+ void
40
+ Init_mecab_light_binding()
41
+ {
42
+ VALUE rb_mMeCab, rb_mMeCab_Light, rb_cMeCab_Light_Binding;
43
+
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);
53
+ }
@@ -2,7 +2,7 @@ module MeCab
2
2
  module Light
3
3
  class Tagger
4
4
  def initialize
5
- @mecab = Binding.mecab_new2('')
5
+ @mecab = Binding.new('')
6
6
  end
7
7
 
8
8
  def parse(string)
@@ -11,12 +11,7 @@ module MeCab
11
11
 
12
12
  private
13
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)
14
+ @mecab.parse_to_s(string).sub(/EOS\n$/, '').each_line
20
15
  end
21
16
  end
22
17
  end
@@ -1,5 +1,5 @@
1
1
  module MeCab
2
2
  module Light
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/lib/mecab/light.rb CHANGED
@@ -1,6 +1,5 @@
1
- require 'ffi'
2
1
  require 'mecab/light/version'
3
2
  require 'mecab/light/morpheme'
4
3
  require 'mecab/light/result'
5
4
  require 'mecab/light/tagger'
6
- require 'mecab/light/binding'
5
+ require 'mecab_light_binding'
data/mecab-light.gemspec CHANGED
@@ -17,8 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
  gem.required_ruby_version = '>= 1.9'
20
-
21
- gem.add_runtime_dependency 'ffi'
20
+ gem.extensions << 'ext/extconf.rb'
22
21
 
23
22
  gem.add_development_dependency 'rake'
24
23
  gem.add_development_dependency 'rspec'
data/spec/mecab_spec.rb CHANGED
@@ -10,14 +10,12 @@ end
10
10
 
11
11
  module MeCab
12
12
  module Light
13
- module Binding
14
- def self.mecab_new2(arg)
15
- :dummy_mecab
13
+ class Binding
14
+ def initialize(option)
16
15
  end
17
16
 
18
- def self.mecab_sparse_tostr(mecab, string)
19
- result = "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
20
- result.force_encoding('ASCII-8BIT')
17
+ def parse_to_s(string)
18
+ "見る\t動詞,自立,*,*,一段,基本形,見る,ミル,ミル\nEOS\n"
21
19
  end
22
20
  end
23
21
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mecab-light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-26 00:00:00.000000000 Z
11
+ date: 2013-04-02 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'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +42,8 @@ description: Use a sequence of results as an Enumerable object.
56
42
  email:
57
43
  - hajime.wakahara@gmail.com
58
44
  executables: []
59
- extensions: []
45
+ extensions:
46
+ - ext/extconf.rb
60
47
  extra_rdoc_files: []
61
48
  files:
62
49
  - .gitignore
@@ -64,6 +51,8 @@ files:
64
51
  - LICENSE.txt
65
52
  - README.md
66
53
  - Rakefile
54
+ - ext/extconf.rb
55
+ - ext/mecab_light_binding.c
67
56
  - lib/mecab/light.rb
68
57
  - lib/mecab/light/binding.rb
69
58
  - lib/mecab/light/morpheme.rb
@@ -91,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
80
  version: '0'
92
81
  requirements: []
93
82
  rubyforge_project:
94
- rubygems_version: 2.0.3
83
+ rubygems_version: 2.0.0
95
84
  signing_key:
96
85
  specification_version: 4
97
86
  summary: A Thin Wrapper for mecab-ruby