Class: SqedToTaxonworks::Result

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

Overview

Stores and handles metadata linking a TW depiction to the Sqed library.

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,
}.freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of Result



40
41
42
43
# File 'lib/vendor/sqed_to_taxonworks.rb', line 40

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



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

def depiction
  @depiction
end

- (Object) depiction_id

Returns the value of attribute depiction_id



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

def depiction_id
  @depiction_id
end

- (Object) height_ratio

Returns the value of attribute height_ratio



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

def height_ratio
  @height_ratio
end

- (Object) namespace_id

Returns the value of attribute namespace_id



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

def namespace_id
  @namespace_id
end

- (Object) original_image

Returns the value of attribute original_image



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

def original_image
  @original_image
end

- (Object) sqed

Returns the value of attribute sqed



32
33
34
# File 'lib/vendor/sqed_to_taxonworks.rb', line 32

def sqed
  @sqed
end

- (Object) sqed_depiction

Returns the value of attribute sqed_depiction



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

def sqed_depiction
  @sqed_depiction
end

- (Object) sqed_result

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



74
75
76
# File 'lib/vendor/sqed_to_taxonworks.rb', line 74

def sqed_result
  @sqed_result
end

- (Object) width_ratio

Returns the value of attribute width_ratio



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

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



102
103
104
105
# File 'lib/vendor/sqed_to_taxonworks.rb', line 102

def cache_all
  cache_ocr
  cache_boundaries
end

- (Object) cache_boundaries



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

def cache_boundaries
  sqed_depiction.update_column(:result_boundary_coordinates, sqed.boundaries.coordinates)
end

- (Object) cache_ocr



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

def cache_ocr
  sqed_depiction.update_column(:result_ocr, sqed_result.text)
end

- (Object) coords_for(layout_section_type)



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

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)



129
130
131
132
# File 'lib/vendor/sqed_to_taxonworks.rb', line 129

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)



134
135
136
137
# File 'lib/vendor/sqed_to_taxonworks.rb', line 134

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)



139
140
141
142
# File 'lib/vendor/sqed_to_taxonworks.rb', line 139

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)


150
151
152
# File 'lib/vendor/sqed_to_taxonworks.rb', line 150

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

- (Object) large_dimensions_for(layout_section_type)



194
195
196
197
# File 'lib/vendor/sqed_to_taxonworks.rb', line 194

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)



189
190
191
192
# File 'lib/vendor/sqed_to_taxonworks.rb', line 189

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)



174
175
176
177
# File 'lib/vendor/sqed_to_taxonworks.rb', line 174

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)



179
180
181
182
# File 'lib/vendor/sqed_to_taxonworks.rb', line 179

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?

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)



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

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)



144
145
146
147
# File 'lib/vendor/sqed_to_taxonworks.rb', line 144

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)


155
156
157
# File 'lib/vendor/sqed_to_taxonworks.rb', line 155

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

- (Array) secondary_sections

Returns:

  • (Array)


160
161
162
# File 'lib/vendor/sqed_to_taxonworks.rb', line 160

def secondary_sections
  image_sections - [primary_image] 
end

- (Object) small_dimensions_for(layout_section_type)



164
165
166
167
# File 'lib/vendor/sqed_to_taxonworks.rb', line 164

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)



184
185
186
187
# File 'lib/vendor/sqed_to_taxonworks.rb', line 184

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)



169
170
171
172
# File 'lib/vendor/sqed_to_taxonworks.rb', line 169

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