hal4r 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ describe Hal4R::Vector do
2
+
3
+ vector = GSL::Vector::Int[0..4]
4
+
5
+ subject { described_class.new(vector) }
6
+
7
+ example do
8
+ expect(subject.each).to be_an_instance_of(Enumerator)
9
+ end
10
+
11
+ example do
12
+ expect{|b|subject.each(&b)}.to yield_successive_args(*vector)
13
+ end
14
+
15
+ end
@@ -0,0 +1,282 @@
1
+ describe Hal4R do
2
+
3
+ delta = Float::EPSILON
4
+
5
+ describe 'empty' do
6
+
7
+ window_size = 42
8
+
9
+ subject { described_class.new([], window_size) }
10
+
11
+ example do
12
+ expect(subject).to be_empty
13
+ end
14
+
15
+ example do
16
+ expect(subject.to_a).to be_empty
17
+ end
18
+
19
+ example do
20
+ expect(subject.window_size).to eq(window_size)
21
+ end
22
+
23
+ example do
24
+ subject.reset
25
+ expect(subject.window_size).to eq(window_size)
26
+ end
27
+
28
+ example do
29
+ expect(subject.each_distance.to_a).to eq([])
30
+ end
31
+
32
+ example do
33
+ expect{|b|subject.each_distance(&b)}.not_to yield_control
34
+ end
35
+
36
+ end
37
+
38
+ describe 'one' do
39
+
40
+ terms = %w[one]
41
+
42
+ subject { described_class.new(terms) }
43
+
44
+ example do
45
+ expect(subject).not_to be_empty
46
+ end
47
+
48
+ example do
49
+ expect(subject.to_a(false)).to eq([[0, 0]])
50
+ end
51
+
52
+ example do
53
+ expect(subject.to_s).to eq(<<-EOT)
54
+
55
+ one
56
+ EOT
57
+ end
58
+
59
+ example do
60
+ expect(subject.euclidean('one', 'one')).to be_nan
61
+ end
62
+
63
+ example do
64
+ expect(subject.manhattan('one', 'one')).to be_nan
65
+ end
66
+
67
+ example do
68
+ expect(subject.related('one')).to eq([])
69
+ end
70
+
71
+ example do
72
+ expect{subject.related('foo')}.to raise_error(KeyError)
73
+ end
74
+
75
+ example do
76
+ expect(subject.each_distance.to_a).to eq([])
77
+ end
78
+
79
+ example do
80
+ expect{|b|subject.each_distance(&b)}.not_to yield_control
81
+ end
82
+
83
+ end
84
+
85
+ describe 'two' do
86
+
87
+ terms = %w[one two]
88
+
89
+ subject { described_class.new(terms) }
90
+
91
+ example do
92
+ expect(subject).not_to be_empty
93
+ end
94
+
95
+ example do
96
+ expect(subject.to_a(false)).to eq([[0, 0, 0, 10], [10, 0, 0, 0]])
97
+ end
98
+
99
+ example do
100
+ expect(subject.to_s).to eq(<<-EOT)
101
+ one
102
+ one 0
103
+ two 10
104
+ EOT
105
+ end
106
+
107
+ example do
108
+ expect(subject.euclidean('one', 'one')).to be_zero
109
+ end
110
+
111
+ example do
112
+ expect(subject.manhattan('one', 'two')).to eq(2.0)
113
+ end
114
+
115
+ example do
116
+ expect{subject.manhattan('one', 'foo')}.to raise_error(KeyError)
117
+ end
118
+
119
+ example do
120
+ expect(subject.related('one')).to eq(%w[two])
121
+ end
122
+
123
+ example do
124
+ expect{subject.related('foo')}.to raise_error(KeyError)
125
+ end
126
+
127
+ ary1 = [[*terms, Math.sqrt(2)]]
128
+ ary2 = [[*terms, Math.sqrt(2) * 10]]
129
+ ary3 = [[*terms, 2.0]]
130
+
131
+ example do
132
+ expect(subject.each_distance.to_a).to eq(ary1)
133
+ end
134
+
135
+ example do
136
+ expect{|b|subject.each_distance(&b)}.to yield_successive_args(*ary1)
137
+ end
138
+
139
+ example do
140
+ expect(subject.each_distance(false).to_a).to eq(ary2)
141
+ end
142
+
143
+ example do
144
+ expect{|b|subject.each_distance(false, &b)}.to yield_successive_args(*ary2)
145
+ end
146
+
147
+ example do
148
+ expect(subject.each_distance(true, 1).to_a).to eq(ary3)
149
+ end
150
+
151
+ example do
152
+ expect{|b|subject.each_distance(true, 1, &b)}.to yield_successive_args(*ary3)
153
+ end
154
+
155
+ end
156
+
157
+ describe 'Lund/Burgess 1996' do
158
+
159
+ terms = %w[the horse raced past the barn fell .]
160
+
161
+ subject { described_class.new(terms, 5) }
162
+
163
+ example do
164
+ expect(subject).not_to be_empty
165
+ end
166
+
167
+ example do
168
+ expect(subject.to_a(false)).to eq([
169
+ [2, 3, 4, 5, 0, 0, 0, 2, 5, 4, 3, 6, 4, 3],
170
+ [5, 0, 0, 0, 0, 0, 0, 3, 0, 5, 4, 2, 1, 0],
171
+ [4, 5, 0, 0, 0, 0, 0, 4, 0, 0, 5, 3, 2, 1],
172
+ [3, 4, 5, 0, 0, 0, 0, 5, 0, 0, 0, 4, 3, 2],
173
+ [6, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4],
174
+ [4, 1, 2, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5],
175
+ [3, 0, 1, 2, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0]
176
+ ])
177
+ end
178
+
179
+ example do
180
+ expect(subject.to_s).to eq(<<-EOT)
181
+ the horse raced past barn fell
182
+ the 2 3 4 5 0 0
183
+ horse 5 0 0 0 0 0
184
+ raced 4 5 0 0 0 0
185
+ past 3 4 5 0 0 0
186
+ barn 6 2 3 4 0 0
187
+ fell 4 1 2 3 5 0
188
+ . 3 0 1 2 4 5
189
+ EOT
190
+ end
191
+
192
+ example do
193
+ expect(subject.euclidean('horse', 'horse')).to be_zero
194
+ end
195
+
196
+ example do
197
+ expect(subject.manhattan('horse', 'horse')).to be_zero
198
+ end
199
+
200
+ example do
201
+ expect(subject.euclidean('horse', 'barn')).to be_within(delta).of(1.1134848787319154)
202
+ end
203
+
204
+ example do
205
+ expect(subject.manhattan('horse', 'barn')).to be_within(delta).of(3.2255132606573502)
206
+ end
207
+
208
+ example do
209
+ expect{subject.euclidean('horse', 'foo')}.to raise_error(KeyError)
210
+ end
211
+
212
+ example do
213
+ expect{subject.euclidean('foo', 'barn')}.to raise_error(KeyError)
214
+ end
215
+
216
+ example do
217
+ expect(subject.related('horse')).to eq(%w[raced the past barn fell])
218
+ end
219
+
220
+ example do
221
+ expect(subject.related('horse', 2)).to eq(%w[raced the])
222
+ end
223
+
224
+ example do
225
+ expect(subject.related('horse', 3, 1)).to eq(%w[raced past the])
226
+ end
227
+
228
+ example do
229
+ expect{subject.related('foo')}.to raise_error(KeyError)
230
+ end
231
+
232
+ ary = [
233
+ ['horse', 'the', Float],
234
+ ['raced', 'the', Float],
235
+ ['past', 'the', Float],
236
+ ['barn', 'the', Float],
237
+ ['fell', 'the', Float],
238
+ ['.', 'the', Float],
239
+ ['horse', 'raced', Float],
240
+ ['horse', 'past', Float],
241
+ ['barn', 'horse', Float],
242
+ ['fell', 'horse', Float],
243
+ ['.', 'horse', Float],
244
+ ['past', 'raced', Float],
245
+ ['barn', 'raced', Float],
246
+ ['fell', 'raced', Float],
247
+ ['.', 'raced', Float],
248
+ ['barn', 'past', Float],
249
+ ['fell', 'past', Float],
250
+ ['.', 'past', Float],
251
+ ['barn', 'fell', Float],
252
+ ['.', 'barn', Float],
253
+ ['.', 'fell', Float]
254
+ ]
255
+
256
+ example do
257
+ expect(subject.each_distance.to_a).to match(ary)
258
+ end
259
+
260
+ example do
261
+ expect{|b|subject.each_distance(&b)}.to yield_successive_args(*ary)
262
+ end
263
+
264
+ example do
265
+ expect(subject.each_distance(false).to_a).to match(ary)
266
+ end
267
+
268
+ example do
269
+ expect{|b|subject.each_distance(false, &b)}.to yield_successive_args(*ary)
270
+ end
271
+
272
+ example do
273
+ expect(subject.each_distance(true, 1).to_a).to match(ary)
274
+ end
275
+
276
+ example do
277
+ expect{|b|subject.each_distance(true, 1, &b)}.to yield_successive_args(*ary)
278
+ end
279
+
280
+ end
281
+
282
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift('lib') unless $:.first == 'lib'
2
+
3
+ require 'hal4r'
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hal4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jens Wille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rb-gsl
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
+ - !ruby/object:Gem::Dependency
28
+ name: hen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.8.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.8.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: HAL processing for Ruby.
76
+ email: jens.wille@gmail.com
77
+ executables:
78
+ - hal4r
79
+ extensions: []
80
+ extra_rdoc_files:
81
+ - README
82
+ - COPYING
83
+ - ChangeLog
84
+ files:
85
+ - COPYING
86
+ - ChangeLog
87
+ - README
88
+ - Rakefile
89
+ - bin/hal4r
90
+ - lib/hal4r.rb
91
+ - lib/hal4r/matrix.rb
92
+ - lib/hal4r/vector.rb
93
+ - lib/hal4r/version.rb
94
+ - spec/hal4r/matrix_spec.rb
95
+ - spec/hal4r/vector_spec.rb
96
+ - spec/hal4r_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: http://github.com/blackwinter/hal4r
99
+ licenses:
100
+ - AGPL-3.0
101
+ metadata: {}
102
+ post_install_message: |2+
103
+
104
+ hal4r-0.0.1 [2015-07-23]:
105
+
106
+ * First release.
107
+
108
+ rdoc_options:
109
+ - "--title"
110
+ - hal4r Application documentation (v0.0.1)
111
+ - "--charset"
112
+ - UTF-8
113
+ - "--line-numbers"
114
+ - "--all"
115
+ - "--main"
116
+ - README
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 1.9.3
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.8
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Hyperspace analogue to language for Ruby.
135
+ test_files: []