sqed 0.3.2 → 0.4.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.
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Sqed::BoundaryFinder::CrossFinder do
4
4
  let(:image) { ImageHelpers.of_size(800, 600) }
5
- let(:b) {Sqed::BoundaryFinder::CrossFinder.new(target_image: image)}
5
+ let(:b) {Sqed::BoundaryFinder::CrossFinder.new(image: image)}
6
6
  let(:c) {b.boundaries}
7
7
 
8
8
  specify '#boundaries returns a Sqed::Boundaries instance' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sqed::BoundaryFinder::StageFinder do
4
- let(:b) {Sqed::BoundaryFinder::StageFinder.new(target_image: ImageHelpers.cross_green )}
4
+ let(:b) {Sqed::BoundaryFinder::StageFinder.new(image: ImageHelpers.cross_green )}
5
5
 
6
6
  specify '#is border contains a proc' do
7
7
  expect(b.is_border.class).to eq(Proc)
@@ -7,7 +7,7 @@ describe Sqed::BoundaryFinder do
7
7
  end
8
8
 
9
9
  context 'when initiated with an image' do
10
- let(:b) {Sqed::BoundaryFinder.new(target_image: ImageHelpers.cross_green, target_layout: :vertical_offset_cross)}
10
+ let(:b) {Sqed::BoundaryFinder.new(image: ImageHelpers.cross_green, layout: :vertical_offset_cross)}
11
11
 
12
12
  context 'attributes' do
13
13
  specify '#image' do
@@ -20,16 +20,16 @@ describe Sqed::BoundaryFinder do
20
20
  end
21
21
  end
22
22
 
23
- context '.color_boundary_finder(target_image: image)' do
23
+ context '.color_boundary_finder(image: image)' do
24
24
  context 'with sample_subdivision_size: 10' do
25
25
  specify 'finds the vertical dividing line in a standard cross, with border still present' do
26
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.cross_green, sample_subdivision_size: 10 )[1]
26
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.cross_green, sample_subdivision_size: 10 )[1]
27
27
  expect(center).to be > 492
28
28
  expect(center).to be < 504
29
29
  end
30
30
 
31
31
  specify 'finds the vertical dividing line in a right t green cross, with border still present' do
32
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.right_t_green, sample_subdivision_size: 10)[1]
32
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.right_t_green, sample_subdivision_size: 10)[1]
33
33
  expect(center).to be > 695
34
34
  expect(center).to be < 705
35
35
  end
@@ -37,59 +37,59 @@ describe Sqed::BoundaryFinder do
37
37
 
38
38
  context 'with sample_subdivision_size auto set' do
39
39
  specify 'finds the vertical dividing line in a standard cross, with border still present, when more precise' do
40
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.cross_green, sample_cutoff_factor: 0.7)[1]
40
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.cross_green, sample_cutoff_factor: 0.7)[1]
41
41
  expect(center).to be > 492
42
42
  expect(center).to be < 504
43
43
  end
44
44
 
45
45
  specify 'finds the vertical dividing line a real image, with border still present' do
46
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.crossy_green_line_specimen)[1]
46
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen)[1]
47
47
  expect(center).to be > 2452
48
48
  expect(center).to be < 2495
49
49
  end
50
50
 
51
51
  specify 'finds the vertical dividing line a real image, with border still present, with 10x fewer subsamples' do
52
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 100 )[1]
52
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 100 )[1]
53
53
  expect(center).to be > 2452
54
54
  expect(center).to be < 2495
55
55
  end
56
56
 
57
57
  specify 'finds the vertical dividing line a real image, with border still present, with 50x fewer subsamples' do
58
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 500 )[1]
58
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 500 )[1]
59
59
  expect(center).to be > 2452
60
60
  expect(center).to be < 2495
61
61
  end
62
62
 
63
63
  specify 'FAILS to find the vertical dividing line a real image, with border still present, with 200x fewer subsamples' do
64
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
64
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
65
65
  expect(center).to be nil
66
66
  end
67
67
 
68
68
  specify 'finds the vertical dividing line another real image, with border still present' do
69
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.greenline_image)[1]
69
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image)[1]
70
70
  expect(center).to be > 2445
71
71
  expect(center).to be < 2495
72
72
  end
73
73
 
74
74
  specify 'finds the vertical dividing line another real image, with border still present, and 20x fewer subsamples' do
75
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.greenline_image, sample_subdivision_size: 200)[1]
75
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 200)[1]
76
76
  expect(center).to be > 2445
77
77
  expect(center).to be < 2495
78
78
  end
79
79
 
80
80
  specify 'finds the vertical dividing line another real image, with border still present, and 50x fewer subsamples' do
81
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.greenline_image, sample_subdivision_size: 500)[1]
81
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 500)[1]
82
82
  expect(center).to be > 2445
83
83
  expect(center).to be < 2495
84
84
  end
85
85
 
86
86
  specify 'FAILS to find the vertical dividing line in a standard cross, with border still present, when even more precise' do
87
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.cross_green, sample_cutoff_factor: 1)
87
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.cross_green, sample_cutoff_factor: 1)
88
88
  expect(center).to be nil
89
89
  end
90
90
 
91
91
  specify 'finds the horizontal dividing line another real image, with border still present' do
92
- center = Sqed::BoundaryFinder.color_boundary_finder(target_image: ImageHelpers.greenline_image, scan: :columns)[1]
92
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, scan: :columns)[1]
93
93
  expect(center).to be > 1282
94
94
  expect(center).to be < 1332
95
95
  end
@@ -104,33 +104,42 @@ describe Sqed::BoundaryFinder do
104
104
  end
105
105
 
106
106
  specify 'returns estimated borders if only one hit greater than samples taken' do
107
- expect( Sqed::BoundaryFinder.frequency_stats(i, 15)).to eq([2,3,4])
107
+ expect( Sqed::BoundaryFinder.frequency_stats(i, 15)).to eq([2, 3, 4])
108
108
  end
109
109
 
110
110
  specify 'returns nil if no count is greater than samples taken' do
111
111
  expect( Sqed::BoundaryFinder.frequency_stats(i, 20)).to eq(nil)
112
112
  end
113
-
114
113
 
115
114
  end
116
115
 
117
116
  context 'offset boundaries from crossy_black_line_specimen image ' do
118
- before(:all) {
119
- @s = Sqed.new(target_image: ImageHelpers.crossy_black_line_specimen, target_pattern: :vertical_offset_cross, boundary_color: :black)
117
+ before(:all) do
118
+ @s = Sqed.new(image: ImageHelpers.crossy_black_line_specimen, pattern: :vertical_offset_cross, boundary_color: :black)
120
119
  @s.crop_image
121
120
  @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
122
121
  true
123
- }
122
+ end
123
+
124
+ specify 'boundaries are complete' do
125
+ expect(@s.boundaries.complete).to be(true)
126
+ end
127
+
128
+ specify 'stage_boundaries are complete' do
129
+ expect(@offset_boundaries.complete).to be(true)
130
+ end
131
+
132
+ specify 'four co-ordinates are returned' do
133
+ expect(@s.boundaries.coordinates.length).to eq(4)
134
+ end
124
135
 
125
- ##**** actually fails (?!)
126
- specify "offset and size should match internal found areas " do
136
+ ## **** actually fails (?!)
137
+ specify 'offset and size should match internal found areas' do
127
138
  sbx = @s.stage_boundary.x_for(0)
128
139
  sby = @s.stage_boundary.y_for(0)
129
140
 
130
- sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
131
- expect(sl).to eq(4) #for offset cross pattern and valid image
132
- expect(@s.boundaries.complete).to be(true)
133
- expect(@offset_boundaries.complete).to be(true)
141
+ sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
142
+
134
143
  (0..sl - 1).each do |i|
135
144
  # check all the x/y
136
145
  expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
@@ -143,22 +152,31 @@ describe Sqed::BoundaryFinder do
143
152
  end
144
153
  end
145
154
 
146
- context 'offset boundaries from black_green_line_specimen image ' do
147
- before(:all) {
148
- @s = Sqed.new(target_image: ImageHelpers.black_stage_green_line_specimen, target_pattern: :vertical_offset_cross)
155
+ context 'offset boundaries from black_green_line_specimen image' do
156
+ before(:all) do
157
+ @s = Sqed.new(image: ImageHelpers.black_stage_green_line_specimen, pattern: :vertical_offset_cross)
149
158
  @s.crop_image
150
159
  @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
151
- true
152
- }
160
+ end
161
+
162
+ specify 'boundaries are complete' do
163
+ expect(@s.boundaries.complete).to be(true)
164
+ end
153
165
 
154
- specify "offset and size should match internal found areas " do
166
+ specify 'stage_boundaries are complete' do
167
+ expect(@offset_boundaries.complete).to be(true)
168
+ end
169
+
170
+ specify 'three co-ordinates are returned' do
171
+ expect(@s.boundaries.coordinates.length).to eq(4) # for offset cross pattern and valid image
172
+ end
173
+
174
+ specify 'offset and size should match internal found areas' do
155
175
  sbx = @s.stage_boundary.x_for(0)
156
176
  sby = @s.stage_boundary.y_for(0)
157
177
 
158
178
  sl = @s.boundaries.coordinates.count # may be convenient to clone this model for other than 4 boundaries found
159
- expect(sl).to eq(4) #for offset cross pattern and valid image
160
- expect(@s.boundaries.complete).to be(true)
161
- expect(@offset_boundaries.complete).to be(true)
179
+
162
180
  (0..sl - 1).each do |i|
163
181
  # check all the x/y
164
182
  expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
@@ -169,26 +187,36 @@ describe Sqed::BoundaryFinder do
169
187
  expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
170
188
  end
171
189
  end
172
- end
190
+ end
173
191
 
174
- context 'offset boundaries from original red_line image ' do
192
+ context 'offset boundaries from original red_line image' do
175
193
  before(:all) {
176
- @s = Sqed.new(target_image: ImageHelpers.vertical_offset_cross_red, target_pattern: :right_t, boundary_color: :red)
194
+ @s = Sqed.new(image: ImageHelpers.vertical_offset_cross_red, pattern: :right_t, boundary_color: :red)
177
195
  @s.crop_image
178
196
  @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
179
197
  }
180
198
 
181
- specify "offset and size should match internal found areas " do
182
- sbx = @s.stage_boundary.x_for(0) # only a single boundary
199
+ specify 'boundaries are complete' do
200
+ expect(@s.boundaries.complete).to be(true)
201
+ end
202
+
203
+ specify 'stage_boundaries are complete' do
204
+ expect(@offset_boundaries.complete).to be(true)
205
+ end
206
+
207
+ specify 'three co-ordinates are returned' do
208
+ expect(@s.boundaries.coordinates.length).to eq(3)
209
+ end
210
+
211
+ specify 'offset and size should match internal found areas' do
212
+ sbx = @s.stage_boundary.x_for(0) # only a single boundary
183
213
  sby = @s.stage_boundary.y_for(0)
184
214
  pct = 0.02
185
215
 
186
- sl = @s.boundaries.coordinates.count
187
- expect(sl).to eq(3)
188
- expect(@s.boundaries.complete).to be(true)
189
- expect(@offset_boundaries.complete).to be(true)
190
- expect(@s.stage_boundary.width_for(0)).to be_within(pct*800).of(800)
191
- expect(@s.stage_boundary.height_for(0)).to be_within(pct*600).of(600)
216
+ sl = @s.boundaries.coordinates.count
217
+
218
+ expect(@s.stage_boundary.width_for(0)).to be_within(pct * 800).of(800)
219
+ expect(@s.stage_boundary.height_for(0)).to be_within(pct * 600).of(600)
192
220
  (0..sl - 1).each do |i|
193
221
  # check all the x/y
194
222
  expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
@@ -9,15 +9,15 @@ describe Sqed::Extractor do
9
9
 
10
10
  let(:boundaries) {
11
11
  Sqed::BoundaryFinder::CrossFinder.new(
12
- target_image: image
12
+ image: image
13
13
  ).boundaries
14
14
  }
15
15
 
16
16
  let(:e) {
17
17
  Sqed::Extractor.new(
18
- target_boundaries: boundaries,
19
- target_image: image,
20
- target_metadata_map: metadata_map
18
+ boundaries: boundaries,
19
+ image: image,
20
+ metadata_map: metadata_map
21
21
  )
22
22
  }
23
23
 
@@ -9,8 +9,8 @@ describe Sqed::Parser::OcrParser do
9
9
  expect(p).to respond_to(:image)
10
10
  end
11
11
 
12
- specify '#text returns some text' do
13
- expect(p.text).to eq('README.md')
12
+ specify '#get_text returns some text' do
13
+ expect(p.get_text).to eq('README.md')
14
14
  end
15
15
 
16
16
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Sqed do
4
4
 
5
- let(:s) {Sqed.new}
5
+ let(:s) { Sqed.new }
6
6
 
7
7
  context 'attributes' do
8
8
 
@@ -30,13 +30,18 @@ describe Sqed do
30
30
  expect(s).to respond_to(:boundaries)
31
31
  end
32
32
 
33
- specify '#has_border' do
34
- expect(s).to respond_to(:has_border)
33
+ specify '#has_border defaults to `true`' do
34
+ expect(s.has_border).to eq(true)
35
35
  end
36
36
 
37
- specify '#boundary_color' do
38
- expect(s).to respond_to(:boundary_color)
37
+ specify '#boundary_color defaults to :green' do
38
+ expect(s.boundary_color).to eq(:green)
39
39
  end
40
+
41
+ specify '#use_thumbnail defaults to `true`' do
42
+ expect(s.use_thumbnail).to eq(true)
43
+ end
44
+
40
45
  end
41
46
 
42
47
  context 'initialization' do
@@ -51,10 +56,10 @@ describe Sqed do
51
56
  end
52
57
  end
53
58
 
54
- # test intent is to just test wrapping functionality, see
59
+ # Intent is to just test wrapping functionality, see
55
60
  # other tests for specifics on finders
56
- context '#crop_image (with bordered stage)' do
57
- specify 'finds a cropped image smaller than original' do
61
+ context '#crop_image (with bordered stage)' do
62
+ specify 'finds a cropped image smaller than original' do
58
63
  s.image = ImageHelpers.test3_image
59
64
  expect(s.crop_image).to be_truthy
60
65
  expect(s.stage_image.columns < s.image.columns).to be(true)
@@ -63,7 +68,7 @@ describe Sqed do
63
68
 
64
69
  specify 'properly sets stage boundaries ' do
65
70
  s.image = ImageHelpers.cross_green
66
- s.crop_image
71
+ s.crop_image
67
72
  # ~ (100,94, 800, 600)
68
73
  expect(s.stage_boundary.x_for(0)).to be_within(2).of 100
69
74
  expect(s.stage_boundary.y_for(0)).to be_within(2).of 94
@@ -74,81 +79,76 @@ describe Sqed do
74
79
 
75
80
  context 'all together, without border' do
76
81
  let(:image) { ImageHelpers.frost_stage }
77
- let(:pattern) { :vertical_offset_cross }
78
- let(:s) { Sqed.new(target_image: image, target_pattern: pattern, has_border: false) }
82
+ let(:s1) { Sqed.new(image: image, pattern: :vertical_offset_cross, has_border: false) }
79
83
 
80
84
  specify '#boundaries returns a Sqed::Boundaries instance' do
81
- expect(s.boundaries.class.name).to eq('Sqed::Boundaries')
85
+ expect(s1.boundaries.class.name).to eq('Sqed::Boundaries')
82
86
  end
83
87
 
84
88
  specify '#stage_image returns an Magick::Image' do
85
- expect(s.stage_image.class.name).to eq('Magick::Image')
89
+ expect(s1.stage_image.class.name).to eq('Magick::Image')
86
90
  end
87
91
 
88
92
  specify '#crop_image returns an Magick::Image' do
89
- expect(s.crop_image.class.name).to eq('Magick::Image')
93
+ expect(s1.crop_image.class.name).to eq('Magick::Image')
90
94
  end
91
95
 
92
96
  specify '#crop_image returns #stage_image' do
93
- expect(s.crop_image).to eq(s.stage_image)
97
+ expect(s1.crop_image).to eq(s1.stage_image)
94
98
  end
95
99
 
96
100
  context '#result' do
97
- let(:r) { s.result }
101
+ let(:rz) { s1.result }
98
102
 
99
103
  specify 'returns a Sqed::Result' do
100
- expect(r.class.name).to eq('Sqed::Result')
104
+ expect(rz.class.name).to eq('Sqed::Result')
101
105
  end
102
106
 
103
- context 'extracted data' do
104
- specify 'text for an :identifier section' do
105
- expect(r.text_for(:identifier)).to match('000041196')
106
- end
107
+ specify '#text_for an :identifier section' do
108
+ expect(rz.text_for(:identifier)).to match('000041196')
109
+ end
107
110
 
108
- # This originally worked, it now does not in the present settings
109
- # specify 'text for an annotated_specimen section' do
110
- # expect(r.text_for(:annotated_specimen)).to match('Saucier Creek')
111
- # end
111
+ specify '#text_for an :annotated_specimen section' do
112
+ expect(rz.text_for(:annotated_specimen)).to match('Saucier Creek')
113
+ end
112
114
 
113
- specify 'text for a curator_metadata section' do
114
- expect(r.text_for(:curator_metadata)).to match('Frost Entomological Museum')
115
- end
115
+ specify '#text_for a :curator_metadata section' do
116
+ expect(rz.text_for(:curator_metadata)).to match('Frost Entomological Museum')
116
117
  end
117
118
  end
118
119
  end
119
120
 
120
121
  context 'all together, with border' do
121
122
  let(:image) { ImageHelpers.greenline_image }
122
- let(:pattern) { :right_t }
123
- let(:s) { Sqed.new(target_image: image, target_pattern: pattern, has_border: true) }
123
+ let(:s2) { Sqed.new(image: image, pattern: :right_t, has_border: true) }
124
124
 
125
125
  specify '#boundaries returns a Sqed::Boundaries instance' do
126
- expect(s.boundaries.class.name).to eq('Sqed::Boundaries')
126
+ expect(s2.boundaries.class.name).to eq('Sqed::Boundaries')
127
127
  end
128
128
 
129
129
  specify '#stage_image returns an Magick::Image' do
130
- expect(s.stage_image.class.name).to eq('Magick::Image')
130
+ expect(s2.stage_image.class.name).to eq('Magick::Image')
131
131
  end
132
132
 
133
133
  specify '#crop_image returns an Magick::Image' do
134
- expect(s.crop_image.class.name).to eq('Magick::Image')
134
+ expect(s2.crop_image.class.name).to eq('Magick::Image')
135
135
  end
136
136
 
137
137
  specify '#crop_image returns #stage_image' do
138
- expect(s.crop_image).to eq(s.stage_image)
138
+ expect(s2.crop_image).to eq(s2.stage_image)
139
139
  end
140
140
 
141
141
  context '#result' do
142
- let(:r) { s.result }
142
+ let(:r) { s2.result }
143
143
  specify 'returns a Sqed::Result' do
144
144
  expect(r.class.name).to eq('Sqed::Result')
145
145
  end
146
146
 
147
147
  context 'extracted data' do
148
- # Default settings return nothing, though some combinations of this worked previosly
149
- # specify 'text for an :identifier section' do
150
- # expect(r.text_for(:identifier)).to match('000085067')
151
- # end
148
+ # Default settings return nothing, though some combinations of this worked previously
149
+ specify 'text for an :identifier section' do
150
+ expect(r.text_for(:identifier)).to match('000085067')
151
+ end
152
152
 
153
153
  specify 'text for a specimen section' do
154
154
  expect(r.text_for(:annotated_specimen)).to match('Aeshna')