wapiti 0.0.5 → 0.1.0

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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.simplecov +3 -0
  3. data/Gemfile +25 -2
  4. data/HISTORY.md +5 -1
  5. data/LICENSE +14 -13
  6. data/README.md +9 -16
  7. data/Rakefile +38 -8
  8. data/ext/wapiti/bcd.c +126 -124
  9. data/ext/wapiti/decoder.c +203 -124
  10. data/ext/wapiti/decoder.h +6 -4
  11. data/ext/wapiti/extconf.rb +2 -2
  12. data/ext/wapiti/gradient.c +491 -320
  13. data/ext/wapiti/gradient.h +52 -34
  14. data/ext/wapiti/lbfgs.c +74 -33
  15. data/ext/wapiti/model.c +47 -37
  16. data/ext/wapiti/model.h +22 -20
  17. data/ext/wapiti/native.c +850 -839
  18. data/ext/wapiti/native.h +1 -1
  19. data/ext/wapiti/options.c +52 -20
  20. data/ext/wapiti/options.h +37 -30
  21. data/ext/wapiti/pattern.c +35 -33
  22. data/ext/wapiti/pattern.h +12 -11
  23. data/ext/wapiti/progress.c +14 -13
  24. data/ext/wapiti/progress.h +3 -2
  25. data/ext/wapiti/quark.c +14 -16
  26. data/ext/wapiti/quark.h +6 -5
  27. data/ext/wapiti/reader.c +83 -69
  28. data/ext/wapiti/reader.h +11 -9
  29. data/ext/wapiti/rprop.c +84 -43
  30. data/ext/wapiti/sequence.h +18 -16
  31. data/ext/wapiti/sgdl1.c +45 -43
  32. data/ext/wapiti/thread.c +19 -17
  33. data/ext/wapiti/thread.h +5 -4
  34. data/ext/wapiti/tools.c +7 -7
  35. data/ext/wapiti/tools.h +3 -4
  36. data/ext/wapiti/trainers.h +1 -1
  37. data/ext/wapiti/vmath.c +40 -38
  38. data/ext/wapiti/vmath.h +12 -11
  39. data/ext/wapiti/wapiti.c +159 -37
  40. data/ext/wapiti/wapiti.h +18 -4
  41. data/lib/wapiti.rb +15 -15
  42. data/lib/wapiti/errors.rb +15 -15
  43. data/lib/wapiti/model.rb +92 -84
  44. data/lib/wapiti/options.rb +123 -124
  45. data/lib/wapiti/utility.rb +14 -14
  46. data/lib/wapiti/version.rb +2 -2
  47. data/spec/spec_helper.rb +29 -9
  48. data/spec/wapiti/model_spec.rb +230 -194
  49. data/spec/wapiti/native_spec.rb +7 -8
  50. data/spec/wapiti/options_spec.rb +184 -174
  51. data/wapiti.gemspec +22 -8
  52. metadata +38 -42
  53. data/.gitignore +0 -5
@@ -1,12 +1,11 @@
1
1
  module Wapiti
2
2
  describe 'Native Extension Module' do
3
-
3
+
4
4
  it 'should define the wapiti version string' do
5
- Native::VERSION.should match /^[\d\.]+$/
5
+ Native::VERSION.should match(/^[\d\.]+$/)
6
6
  end
7
-
8
- it { Native.should respond_to(:wapiti) }
9
- it { Native.should respond_to(:label) }
10
-
11
- end
12
- end
7
+
8
+ it { Native.should respond_to(:label) }
9
+
10
+ end
11
+ end
@@ -1,175 +1,185 @@
1
1
  module Wapiti
2
- describe 'Options' do
3
-
4
- let(:options) { Options.new }
5
-
6
- it { Options.should be_an_instance_of(Class) }
7
-
8
- it { options.should_not be nil }
9
-
10
- describe '.defaults' do
11
- it 'returns a hash with the default options' do
12
- Options.defaults.keys.map(&:to_s).sort.should == Options.attribute_names.map(&:to_s)
13
- end
14
- end
15
-
16
- describe '#initialize' do
17
-
18
- it 'should fail if called with more than one parameter' do
19
- expect { Options.new(1,2) }.to raise_error
20
- end
21
-
22
- it 'should fail if called with a parameter that is no hash' do
23
- expect { Options.new([]) }.to raise_error
24
- end
25
-
26
- it 'should set defaults according to the supplied hash' do
27
- Options.new(:compact => true).should be_compact
28
- end
29
-
30
- it 'should accept and execute a self-yielding block' do
31
- opt = Options.new(:compact => true) { |o| o.sparse = true }
32
- opt.should be_compact
33
- opt.should be_sparse
34
- end
35
-
36
- end
37
-
38
- describe '#update' do
39
- it 'sets all option values according to the given hash' do
40
- lambda { options.update( :threads => 2 ) }.should change { options.threads }.from(1).to(2)
41
- end
42
- end
43
-
44
- describe '#threads' do
45
- it 'returns 1 by default' do
46
- options.threads.should == 1
47
- end
48
- end
49
-
50
- describe '#threads=' do
51
- it 'sets threads to the given value' do
52
- lambda { options.threads = 2 }.should change { options.threads }.from(1).to(2)
53
- end
54
- end
55
-
56
- describe '#jobsize' do
57
- it 'returns 64 by default' do
58
- options.jobsize.should == 64
59
- end
60
- end
61
-
62
- describe '#jobsize=' do
63
- it 'sets jobsize to the given value' do
64
- lambda { options.jobsize = 128 }.should change { options.jobsize }.by(64)
65
- end
66
- end
67
-
68
- describe '#maxiter' do
69
- it 'returns a large number by default' do
70
- options.maxiter.should > 0
71
- end
72
- end
73
-
74
- describe '#maxiter=' do
75
- it 'sets maxiter to the given value' do
76
- lambda { options.maxiter = 20 }.should change { options.maxiter }.to(20)
77
- end
78
- end
79
-
80
- describe '#stop_window' do
81
- it 'returns 5 by default' do
82
- options.stop_window.should == 5
83
- end
84
- end
85
-
86
- describe '#stop_window=' do
87
- it 'sets stop_window to the given value' do
88
- lambda { options.stop_window = 20 }.should change { options.stop_window }.by(15)
89
- end
90
- end
91
-
92
- describe '#convergence_window' do
93
- it 'returns 5 by default' do
94
- options.convergence_window.should == 5
95
- end
96
- end
97
-
98
- describe '#convergence_window=' do
99
- it 'sets convergence_window to the given value' do
100
- lambda { options.convergence_window = 20 }.should change { options.convergence_window }.by(15)
101
- end
102
- end
103
-
104
-
105
- describe '#stop_epsilon' do
106
- it 'returns 0.02 by default' do
107
- options.stop_epsilon.should == 0.02
108
- end
109
- end
110
-
111
- describe '#stop_epsilon=' do
112
- it 'sets stop_epsilon to the given value' do
113
- lambda { options.stop_epsilon = 0.35 }.should change { options.stop_epsilon }
114
- end
115
- end
116
-
117
- describe '#rho1' do
118
- it 'returns 0.5 by default' do
119
- options.rho1.should == 0.5
120
- end
121
- end
122
-
123
- describe '#rho1=' do
124
- it 'sets rho1 to the given value' do
125
- lambda { options.rho1 = 2.5 }.should change { options.rho1 }.by(2)
126
- end
127
- end
128
-
129
- describe '#rho2' do
130
- it 'returns 0.0001 by default' do
131
- options.rho2.should == 0.0001
132
- end
133
- end
134
-
135
- describe '#rho2=' do
136
- it 'sets rho2 to the given value' do
137
- lambda { options.rho2 = 0.0002 }.should change { options.rho2 }.by(0.0001)
138
- end
139
- end
140
-
141
-
142
- %w{ maxent compact sparse skip_tokens check score posterior }.each do |m|
143
- describe "##{m}" do
144
- it 'returns false by default' do
145
- options.send(m).should be false
146
- end
147
- end
148
-
149
- describe "##{m}=" do
150
- it "sets #{m} to the given value" do
151
- lambda { options.send("#{m}=", true) }.should change { options.send(m) }.from(false).to(true)
152
- lambda { options.send("#{m}=", false) }.should change { options.send(m) }.from(true).to(false)
153
- lambda { options.send("#{m}=", 123) }.should change { options.send(m) }.from(false).to(true)
154
- lambda { options.send("#{m}=", nil) }.should change { options.send(m) }.from(true).to(false)
155
- end
156
- end
157
- end
158
-
159
- %w{ pattern model algorithm devel }.each do |m|
160
- describe "##{m}" do
161
- it 'returns an empty string by default' do
162
- options.send(m).should be_a(String)
163
- end
164
- end
165
-
166
- describe "##{m}=" do
167
- it 'sets the input string to the given value' do
168
- lambda { options.send("#{m}=", 'foo') }.should change { options.send(m) }.to('foo')
169
- end
170
- end
171
- end
172
-
173
- end
174
-
175
- end
2
+ describe 'Options' do
3
+
4
+ let(:options) { Options.new }
5
+
6
+ it { Options.should be_an_instance_of(Class) }
7
+
8
+ it { options.should_not be nil }
9
+
10
+ describe '.defaults' do
11
+ it 'returns a hash with the default options' do
12
+ Options.defaults.keys.map(&:to_s).sort.should == Options.attribute_names.map(&:to_s)
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+
18
+ it 'should fail if called with more than one parameter' do
19
+ expect { Options.new(1,2) }.to raise_error
20
+ end
21
+
22
+ it 'should fail if called with a parameter that is no hash' do
23
+ expect { Options.new([]) }.to raise_error
24
+ end
25
+
26
+ it 'should set defaults according to the supplied hash' do
27
+ Options.new(:compact => true).should be_compact
28
+ end
29
+
30
+ it 'should accept and execute a self-yielding block' do
31
+ opt = Options.new(:compact => true) { |o| o.sparse = true }
32
+ opt.should be_compact
33
+ opt.should be_sparse
34
+ end
35
+
36
+ end
37
+
38
+ describe 'array accessors' do
39
+ it 'are supported' do
40
+ lambda { options[:threads] = 2 }.should change { options[:threads] }.from(1).to(2)
41
+ end
42
+
43
+ it 'fail for unknown attribute names' do
44
+ lambda { options[:unknown] = 2 }.should raise_error(ArgumentError)
45
+ end
46
+ end
47
+
48
+ describe '#update' do
49
+ it 'sets all option values according to the given hash' do
50
+ lambda { options.update( :threads => 2 ) }.should change { options.threads }.from(1).to(2)
51
+ end
52
+ end
53
+
54
+ describe '#threads' do
55
+ it 'returns 1 by default' do
56
+ options.threads.should == 1
57
+ end
58
+ end
59
+
60
+ describe '#threads=' do
61
+ it 'sets threads to the given value' do
62
+ lambda { options.threads = 2 }.should change { options.threads }.from(1).to(2)
63
+ end
64
+ end
65
+
66
+ describe '#jobsize' do
67
+ it 'returns 64 by default' do
68
+ options.jobsize.should == 64
69
+ end
70
+ end
71
+
72
+ describe '#jobsize=' do
73
+ it 'sets jobsize to the given value' do
74
+ lambda { options.jobsize = 128 }.should change { options.jobsize }.by(64)
75
+ end
76
+ end
77
+
78
+ describe '#maxiter' do
79
+ it 'returns a large number by default' do
80
+ options.maxiter.should > 0
81
+ end
82
+ end
83
+
84
+ describe '#maxiter=' do
85
+ it 'sets maxiter to the given value' do
86
+ lambda { options.maxiter = 20 }.should change { options.maxiter }.to(20)
87
+ end
88
+ end
89
+
90
+ describe '#stop_window' do
91
+ it 'returns 5 by default' do
92
+ options.stop_window.should == 5
93
+ end
94
+ end
95
+
96
+ describe '#stop_window=' do
97
+ it 'sets stop_window to the given value' do
98
+ lambda { options.stop_window = 20 }.should change { options.stop_window }.by(15)
99
+ end
100
+ end
101
+
102
+ describe '#convergence_window' do
103
+ it 'returns 5 by default' do
104
+ options.convergence_window.should == 5
105
+ end
106
+ end
107
+
108
+ describe '#convergence_window=' do
109
+ it 'sets convergence_window to the given value' do
110
+ lambda { options.convergence_window = 20 }.should change { options.convergence_window }.by(15)
111
+ end
112
+ end
113
+
114
+
115
+ describe '#stop_epsilon' do
116
+ it 'returns 0.02 by default' do
117
+ options.stop_epsilon.should == 0.02
118
+ end
119
+ end
120
+
121
+ describe '#stop_epsilon=' do
122
+ it 'sets stop_epsilon to the given value' do
123
+ lambda { options.stop_epsilon = 0.35 }.should change { options.stop_epsilon }
124
+ end
125
+ end
126
+
127
+ describe '#rho1' do
128
+ it 'returns 0.5 by default' do
129
+ options.rho1.should == 0.5
130
+ end
131
+ end
132
+
133
+ describe '#rho1=' do
134
+ it 'sets rho1 to the given value' do
135
+ lambda { options.rho1 = 2.5 }.should change { options.rho1 }.by(2)
136
+ end
137
+ end
138
+
139
+ describe '#rho2' do
140
+ it 'returns 0.0001 by default' do
141
+ options.rho2.should == 0.0001
142
+ end
143
+ end
144
+
145
+ describe '#rho2=' do
146
+ it 'sets rho2 to the given value' do
147
+ lambda { options.rho2 = 0.0002 }.should change { options.rho2 }.by(0.0001)
148
+ end
149
+ end
150
+
151
+
152
+ %w{ maxent compact sparse skip_tokens check score posterior }.each do |m|
153
+ describe "##{m}" do
154
+ it 'returns false by default' do
155
+ options.send(m).should be false
156
+ end
157
+ end
158
+
159
+ describe "##{m}=" do
160
+ it "sets #{m} to the given value" do
161
+ lambda { options.send("#{m}=", true) }.should change { options.send(m) }.from(false).to(true)
162
+ lambda { options.send("#{m}=", false) }.should change { options.send(m) }.from(true).to(false)
163
+ lambda { options.send("#{m}=", 123) }.should change { options.send(m) }.from(false).to(true)
164
+ lambda { options.send("#{m}=", nil) }.should change { options.send(m) }.from(true).to(false)
165
+ end
166
+ end
167
+ end
168
+
169
+ %w{ pattern model algorithm devel }.each do |m|
170
+ describe "##{m}" do
171
+ it 'returns an empty string by default' do
172
+ options.send(m).should be_a(String)
173
+ end
174
+ end
175
+
176
+ describe "##{m}=" do
177
+ it 'sets the input string to the given value' do
178
+ lambda { options.send("#{m}=", 'foo') }.should change { options.send(m) }.to('foo')
179
+ end
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+ end
@@ -8,28 +8,42 @@ Gem::Specification.new do |s|
8
8
  s.name = 'wapiti'
9
9
  s.version = Wapiti::VERSION.dup
10
10
  s.platform = Gem::Platform::RUBY
11
+
11
12
  s.authors = ['Sylvester Keil']
12
13
  s.email = ['http://sylvester.keil.or.at']
14
+
13
15
  s.homepage = 'https://github.com/inukshuk/wapiti-ruby'
14
16
  s.summary = 'Wicked fast Conditional Random Fields for Ruby.'
15
- s.description = 'This gem provides a Ruby API for Conditional Random Fields (CRF). It is implemented as a C exstension and based on the wicked fast "wapiti" package.'
17
+ s.description =
18
+ """
19
+ This gem provides a Ruby API for Conditional Random Fields (CRF).
20
+ """
21
+
16
22
  s.license = 'FreeBSD'
23
+ s.date = Time.now.strftime('%Y-%m-%d')
17
24
 
18
- s.add_development_dependency('rake', '~>0.9')
25
+ s.add_development_dependency('rake', '~>10.0')
19
26
  s.add_development_dependency('rake-compiler', '~>0.7')
20
- s.add_development_dependency('ZenTest', '~>4.6')
21
- s.add_development_dependency('rspec', '~>2.6')
27
+ s.add_development_dependency('rspec', '~>2.6')
28
+
29
+ s.files = `git ls-files`.split("\n") - %w{
30
+ vendor/wapiti
31
+ .coveralls.yml
32
+ .travis.yml
33
+ .gitmodules
34
+ .gitignore
35
+ }
22
36
 
23
- s.files = `git ls-files`.split("\n")
24
37
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
38
+
25
39
  s.executables = []
26
40
  s.require_path = 'lib'
27
-
41
+
28
42
  s.extensions << 'ext/wapiti/extconf.rb'
29
43
 
30
44
  s.rdoc_options = %w{--line-numbers --inline-source --title "Wapiti-Ruby" --main README.md --webcvs=http://github.com/inukshuk/wapiti-ruby/tree/master/}
31
45
  s.extra_rdoc_files = %w{README.md LICENSE}
32
-
46
+
33
47
  end
34
48
 
35
- # vim: syntax=ruby
49
+ # vim: syntax=ruby
metadata CHANGED
@@ -1,62 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wapiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sylvester Keil
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-09-06 00:00:00.000000000Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- requirement: &2156563060 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0.9'
19
+ version: '10.0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *2156563060
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rake-compiler
27
- requirement: &2156559320 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0.7'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *2156559320
36
- - !ruby/object:Gem::Dependency
37
- name: ZenTest
38
- requirement: &2156553240 !ruby/object:Gem::Requirement
39
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ~>
38
+ - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '4.6'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *2156553240
40
+ version: '0.7'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rspec
49
- requirement: &2156552400 !ruby/object:Gem::Requirement
50
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
51
44
  requirements:
52
- - - ~>
45
+ - - "~>"
53
46
  - !ruby/object:Gem::Version
54
47
  version: '2.6'
55
48
  type: :development
56
49
  prerelease: false
57
- version_requirements: *2156552400
58
- description: This gem provides a Ruby API for Conditional Random Fields (CRF). It
59
- is implemented as a C exstension and based on the wicked fast "wapiti" package.
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ description: "\n This gem provides a Ruby API for Conditional Random Fields (CRF).\n
56
+ \ "
60
57
  email:
61
58
  - http://sylvester.keil.or.at
62
59
  executables: []
@@ -66,9 +63,9 @@ extra_rdoc_files:
66
63
  - README.md
67
64
  - LICENSE
68
65
  files:
69
- - .autotest
70
- - .gitignore
71
- - .rspec
66
+ - ".autotest"
67
+ - ".rspec"
68
+ - ".simplecov"
72
69
  - Gemfile
73
70
  - HISTORY.md
74
71
  - LICENSE
@@ -132,34 +129,33 @@ files:
132
129
  homepage: https://github.com/inukshuk/wapiti-ruby
133
130
  licenses:
134
131
  - FreeBSD
132
+ metadata: {}
135
133
  post_install_message:
136
134
  rdoc_options:
137
- - --line-numbers
138
- - --inline-source
139
- - --title
140
- - ! '"Wapiti-Ruby"'
141
- - --main
135
+ - "--line-numbers"
136
+ - "--inline-source"
137
+ - "--title"
138
+ - "\"Wapiti-Ruby\""
139
+ - "--main"
142
140
  - README.md
143
- - --webcvs=http://github.com/inukshuk/wapiti-ruby/tree/master/
141
+ - "--webcvs=http://github.com/inukshuk/wapiti-ruby/tree/master/"
144
142
  require_paths:
145
143
  - lib
146
144
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
145
  requirements:
149
- - - ! '>='
146
+ - - ">="
150
147
  - !ruby/object:Gem::Version
151
148
  version: '0'
152
149
  required_rubygems_version: !ruby/object:Gem::Requirement
153
- none: false
154
150
  requirements:
155
- - - ! '>='
151
+ - - ">="
156
152
  - !ruby/object:Gem::Version
157
153
  version: '0'
158
154
  requirements: []
159
155
  rubyforge_project:
160
- rubygems_version: 1.8.10
156
+ rubygems_version: 2.2.2
161
157
  signing_key:
162
- specification_version: 3
158
+ specification_version: 4
163
159
  summary: Wicked fast Conditional Random Fields for Ruby.
164
160
  test_files:
165
161
  - spec/fixtures/ch.mod