Class: SqedToTaxonworks::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/sqed_to_taxonworks.rb

Constant Summary

SMALL_WIDTH =
100
LARGE_WIDTH =
400
TEXT_MAP =
{
  annotated_specimen: :buffered_collecting_event,
  collecting_event_labels: :buffered_collecting_event,
  curator_metadata: :buffered_other_labels,
  determination_labels: :buffered_determination_labels,
  identifier: :buffered_other_labels,
  image_registration: nil,
  other_labels: :buffered_other_labels,
  labels: :buffered_collecting_event,
  nothing: nil,
  specimen: nil,
  stage: :buffered_collecting_event,
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Result) initialize(depiction_id: nil, namespace_id: nil)

Returns a new instance of Result



38
39
40
41
# File 'lib/vendor/sqed_to_taxonworks.rb', line 38

def initialize(depiction_id: nil, namespace_id: nil)
  @depiction_id = depiction_id
  @namespace_id = namespace_id
end

Instance Attribute Details

- (Object) depiction

Returns the value of attribute depiction



22
23
24
# File 'lib/vendor/sqed_to_taxonworks.rb', line 22

def depiction
  @depiction
end

- (Object) depiction_id

Returns the value of attribute depiction_id



24
25
26
# File 'lib/vendor/sqed_to_taxonworks.rb', line 24

def depiction_id
  @depiction_id
end

- (Object) height_ratio

Returns the value of attribute height_ratio



36
37
38
# File 'lib/vendor/sqed_to_taxonworks.rb', line 36

def height_ratio
  @height_ratio
end

- (Object) namespace_id

Returns the value of attribute namespace_id



26
27
28
# File 'lib/vendor/sqed_to_taxonworks.rb', line 26

def namespace_id
  @namespace_id
end

- (Object) original_image

Returns the value of attribute original_image



34
35
36
# File 'lib/vendor/sqed_to_taxonworks.rb', line 34

def original_image
  @original_image
end

- (Object) sqed

Returns the value of attribute sqed



30
31
32
# File 'lib/vendor/sqed_to_taxonworks.rb', line 30

def sqed
  @sqed
end

- (Object) sqed_depiction

Returns the value of attribute sqed_depiction



28
29
30
# File 'lib/vendor/sqed_to_taxonworks.rb', line 28

def sqed_depiction
  @sqed_depiction
end

- (Object) sqed_result

Minimize use of this if possible, depend on the cached values when possible.



72
73
74
# File 'lib/vendor/sqed_to_taxonworks.rb', line 72

def sqed_result
  @sqed_result
end

- (Object) width_ratio

Returns the value of attribute width_ratio



36
37
38
# File 'lib/vendor/sqed_to_taxonworks.rb', line 36

def width_ratio
  @width_ratio
end

Instance Method Details

- (Boolean) boundaries_cached?

Returns:

  • (Boolean)


86
87
88
# File 'lib/vendor/sqed_to_taxonworks.rb', line 86

def boundaries_cached?
  !sqed_depiction.result_boundary_coordinates.nil? 
end

- (Object) cache_all



104
105
106
107
# File 'lib/vendor/sqed_to_taxonworks.rb', line 104

def cache_all
  cache_ocr
  cache_boundaries
end

- (Object) cache_boundaries



94
95
96
97
# File 'lib/vendor/sqed_to_taxonworks.rb', line 94

def cache_boundaries
  sqed_depiction.update_column(:result_boundary_coordinates, ActiveSupport::JSON.encode(sqed.boundaries.coordinates))
  sqed_depiction.reload # get the json version of the attribute back
end

- (Object) cache_ocr



99
100
101
102
# File 'lib/vendor/sqed_to_taxonworks.rb', line 99

def cache_ocr
  sqed_depiction.update_column(:result_ocr, ActiveSupport::JSON.encode(sqed_result.text))
  sqed_depiction.reload # get the json version of the attribute back
end

- (Object) coords_for(layout_section_type)



120
121
122
123
124
125
126
127
128
129
# File 'lib/vendor/sqed_to_taxonworks.rb', line 120

def coords_for(layout_section_type)
  index = sqed_depiction.[:metadata_map].key(layout_section_type)
  if boundaries_cached?
    sqed_depiction.result_boundary_coordinates[index.to_s].to_a # TODO- hmm, why the to_s needed here
  else # do not do the OCR if only coords asked for
    sqed_result 
    cache_boundaries
    sqed.boundaries.for(index)
  end
end

- (Object) image_path_for(layout_section_type)



131
132
133
134
# File 'lib/vendor/sqed_to_taxonworks.rb', line 131

def image_path_for(layout_section_type)
  c = coords_for(layout_section_type) 
  "/images/#{depiction.image.id}/extract/#{c[0]}/#{c[1]}/#{c[2]}/#{c[3]}"
end

- (Object) image_path_for_large_image(layout_section_type)



136
137
138
139
# File 'lib/vendor/sqed_to_taxonworks.rb', line 136

def image_path_for_large_image(layout_section_type)
  c = coords_for(layout_section_type) 
  "/images/#{depiction.image.id}/scale_to_box/#{c[0]}/#{c[1]}/#{c[2]}/#{c[3]}/400/400"
end

- (Object) image_path_for_small_image(layout_section_type)



141
142
143
144
# File 'lib/vendor/sqed_to_taxonworks.rb', line 141

def image_path_for_small_image(layout_section_type)
  c = coords_for(layout_section_type) 
  "/images/#{depiction.image.id}/scale_to_box/#{c[0]}/#{c[1]}/#{c[2]}/#{c[3]}/150/150"
end

- (Array) image_sections

Returns:

  • (Array)


152
153
154
# File 'lib/vendor/sqed_to_taxonworks.rb', line 152

def image_sections
  (sqed_depiction.[:metadata_map].values - [:image_registration, :specimen])
end

- (Object) large_dimensions_for(layout_section_type)



196
197
198
199
# File 'lib/vendor/sqed_to_taxonworks.rb', line 196

def large_dimensions_for(layout_section_type)
  c = coords_for(layout_section_type) 
  "0, 0, 400, #{ (c[3].to_f / (c[2].to_f / 400)).to_i }"
end

- (Object) large_height_for(layout_section_type)



191
192
193
194
# File 'lib/vendor/sqed_to_taxonworks.rb', line 191

def large_height_for(layout_section_type)
  c = coords_for(layout_section_type) 
 "#{(c[3].to_f / (c[2].to_f / LARGE_WIDTH)).to_i}"
end

- (Object) large_height_width(layout_section_type)



176
177
178
179
# File 'lib/vendor/sqed_to_taxonworks.rb', line 176

def large_height_width(layout_section_type)
  c = coords_for(layout_section_type) 
  "#{LARGE_WIDTH}, #{large_height_for(layout_section_type)}"
end

- (Object) larger_height_width(layout_section_type)



181
182
183
184
# File 'lib/vendor/sqed_to_taxonworks.rb', line 181

def larger_height_width(layout_section_type)
  c = coords_for(layout_section_type) 
  "#{LARGE_WIDTH + 100}, #{large_height_for(layout_section_type).to_i + 100}"
end

- (Boolean) namespace_locked?

instance methods

Returns:

  • (Boolean)


82
83
84
# File 'lib/vendor/sqed_to_taxonworks.rb', line 82

def namespace_locked?
  !namespace_id.nil?
end

- (Boolean) ocr_cached?

Returns:

  • (Boolean)


90
91
92
# File 'lib/vendor/sqed_to_taxonworks.rb', line 90

def ocr_cached?
  !sqed_depiction.result_ocr.nil? 
end

- (Object) ocr_for(layout_section_type)



109
110
111
112
113
114
115
116
117
118
# File 'lib/vendor/sqed_to_taxonworks.rb', line 109

def ocr_for(layout_section_type)
  index = sqed_depiction.[:metadata_map].key(layout_section_type)
  if ocr_cached?
    sqed_depiction.result_ocr[layout_section_type.to_s] &&sqed_depiction.result_ocr[layout_section_type.to_s]['text']
  else
    sqed_result 
    cache_all 
    sqed_result.text_for(layout_section_type.to_sym)
  end
end

- (Object) ocr_path_for(layout_section_type)



146
147
148
149
# File 'lib/vendor/sqed_to_taxonworks.rb', line 146

def ocr_path_for(layout_section_type)
  c = coords_for(layout_section_type) 
  "/images/#{depiction.image.id}/ocr/#{c[0]}/#{c[1]}/#{c[2]}/#{c[3]}"
end

- (Symbol) primary_image

Returns:

  • (Symbol)


157
158
159
# File 'lib/vendor/sqed_to_taxonworks.rb', line 157

def primary_image 
  (image_sections & [:labels, :collecting_event_labels, :annotated_specimen]).first
end

- (Array) secondary_sections

Returns:

  • (Array)


162
163
164
# File 'lib/vendor/sqed_to_taxonworks.rb', line 162

def secondary_sections
  image_sections - [primary_image] 
end

- (Object) small_dimensions_for(layout_section_type)



166
167
168
169
# File 'lib/vendor/sqed_to_taxonworks.rb', line 166

def small_dimensions_for(layout_section_type)
  c = coords_for(layout_section_type) 
  "0, 0, #{SMALL_WIDTH}, #{ (c[3].to_f / (c[2].to_f / SMALL_WIDTH)).to_i }"
end

- (Object) small_height_for(layout_section_type)



186
187
188
189
# File 'lib/vendor/sqed_to_taxonworks.rb', line 186

def small_height_for(layout_section_type)
  c = coords_for(layout_section_type) 
 "#{(c[3].to_f / (c[2].to_f / SMALL_WIDTH)).to_i}"
end

- (Object) small_height_width(layout_section_type)



171
172
173
174
# File 'lib/vendor/sqed_to_taxonworks.rb', line 171

def small_height_width(layout_section_type)
  c = coords_for(layout_section_type) 
  "#{SMALL_WIDTH}, #{small_height_for(layout_section_type)}"
end