sqed 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/lib/sqed.rb +53 -31
- data/lib/sqed/version.rb +1 -1
- data/spec/lib/sqed/extractor_spec.rb +2 -5
- data/spec/lib/sqed_spec.rb +8 -9
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bc7181ce86a616f52763dc679ac56b8a61757af2
         | 
| 4 | 
            +
              data.tar.gz: adad2a5e8268883aa92773ca9c9bb7e7388993b6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 48aad3560defbe2d110b108e137150bd00642fee93c7d3fdc230617395ee6e9c401d8bd1ed03164e509ff036fffad44cff4e46867d5e8125c8ccf88da7d2ab21
         | 
| 7 | 
            +
              data.tar.gz: f86ca07a14ffab425ce2dad714f3a4d8a3d0676b62ca2abcba6b7c7d199bec580b8dbcc4fe2b83894bb9031123b9c49d40eff99fe92d9076643cb7fe0be59760
         | 
    
        data/lib/sqed.rb
    CHANGED
    
    | @@ -44,21 +44,51 @@ class Sqed | |
| 44 44 | 
             
              # Boolean, whether to do the boundary detection (not stage detection at present) against a thumbnail version of the passed image (faster, less accurate, true be default) 
         | 
| 45 45 | 
             
              attr_accessor :use_thumbnail
         | 
| 46 46 |  | 
| 47 | 
            -
               | 
| 47 | 
            +
              # Provide a specific layout, overrides metadata taken from pattern
         | 
| 48 | 
            +
              attr_accessor :layout
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              # Provide a metadata map, overrides metadata taken from pattern
         | 
| 51 | 
            +
              attr_accessor :metadata_map
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              # Provide a boundary_finder, overrides metadata taken from pattern
         | 
| 54 | 
            +
              attr_accessor :boundary_finder 
         | 
| 55 | 
            +
               
         | 
| 56 | 
            +
              def initialize(image: image, pattern: pattern, has_border: true, boundary_color: :green, use_thumbnail: true, boundary_finder: nil, layout: nil, metadata_map: nil)
         | 
| 48 57 | 
             
                raise 'extraction pattern not defined' if pattern && !SqedConfig::EXTRACTION_PATTERNS.keys.include?(pattern) 
         | 
| 49 | 
            -
             | 
| 58 | 
            +
             | 
| 59 | 
            +
                # data, and stubs for results
         | 
| 50 60 | 
             
                @image = image
         | 
| 51 61 | 
             
                @boundaries = nil
         | 
| 52 62 | 
             
                @stage_boundary = Sqed::Boundaries.new(:internal_box) 
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                # extraction metadata
         | 
| 65 | 
            +
                @pattern = (pattern || :cross)
         | 
| 53 66 | 
             
                @has_border = has_border
         | 
| 54 | 
            -
                @ | 
| 55 | 
            -
                @ | 
| 67 | 
            +
                @boundary_finder = boundary_finder.constantize if boundary_finder
         | 
| 68 | 
            +
                @layout = layout
         | 
| 69 | 
            +
                @metadata_map = metadata_map
         | 
| 56 70 | 
             
                @boundary_color = boundary_color
         | 
| 57 71 | 
             
                @use_thumbnail = use_thumbnail
         | 
| 72 | 
            +
             | 
| 58 73 | 
             
                set_stage_boundary if @image
         | 
| 59 74 | 
             
              end
         | 
| 60 75 |  | 
| 61 | 
            -
              #  | 
| 76 | 
            +
              # @return [Hash]
         | 
| 77 | 
            +
              #   federate extraction options and apply user provided over-rides
         | 
| 78 | 
            +
              def extraction_metadata
         | 
| 79 | 
            +
                data = SqedConfig::EXTRACTION_PATTERNS[@pattern]
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                data.merge!(boundary_finder: @boundary_finder) if boundary_finder
         | 
| 82 | 
            +
                data.merge!(layout: layout) if layout 
         | 
| 83 | 
            +
                data.merge!(metadata_map: metadata_map) if metadata_map
         | 
| 84 | 
            +
                data.merge!(has_border: has_border) 
         | 
| 85 | 
            +
                data.merge!(use_thumbnail: use_thumbnail) 
         | 
| 86 | 
            +
                data.merge!(boundary_color: boundary_color) 
         | 
| 87 | 
            +
                data
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              # @return [ImageMagick::Image]
         | 
| 91 | 
            +
              #   set the image if it's not set during initialize(), not commonly used
         | 
| 62 92 | 
             
              def image=(value)
         | 
| 63 93 | 
             
                @image = value
         | 
| 64 94 | 
             
                set_stage_boundary 
         | 
| @@ -94,61 +124,53 @@ class Sqed | |
| 94 124 | 
             
              # return [Image]
         | 
| 95 125 | 
             
              #   crops the stage if not done, then sets/returns @stage_image
         | 
| 96 126 | 
             
              def crop_image
         | 
| 97 | 
            -
                if  | 
| 98 | 
            -
                  @stage_image =  | 
| 127 | 
            +
                if has_border 
         | 
| 128 | 
            +
                  @stage_image = image.crop(*stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true)
         | 
| 99 129 | 
             
                else
         | 
| 100 | 
            -
                  @stage_image =  | 
| 130 | 
            +
                  @stage_image = image 
         | 
| 101 131 | 
             
                end
         | 
| 102 132 | 
             
                @stage_image
         | 
| 103 133 | 
             
              end
         | 
| 104 134 |  | 
| 105 135 | 
             
              def result
         | 
| 106 | 
            -
                return false if  | 
| 136 | 
            +
                return false if image.nil? || pattern.nil? 
         | 
| 107 137 | 
             
                extractor = Sqed::Extractor.new(
         | 
| 108 138 | 
             
                  boundaries: boundaries,
         | 
| 109 | 
            -
                  metadata_map:  | 
| 139 | 
            +
                  metadata_map: extraction_metadata[:metadata_map],
         | 
| 110 140 | 
             
                  image: stage_image)
         | 
| 111 141 | 
             
                extractor.result
         | 
| 112 142 | 
             
              end
         | 
| 113 143 |  | 
| 114 | 
            -
              #  | 
| 144 | 
            +
              # @return [Hash]
         | 
| 145 | 
            +
              #   an overview of data/metadata, for debugging purposes only
         | 
| 115 146 | 
             
              def attributes
         | 
| 116 | 
            -
                {
         | 
| 117 | 
            -
                   | 
| 118 | 
            -
                   | 
| 119 | 
            -
             | 
| 120 | 
            -
                  has_border: @has_border,
         | 
| 121 | 
            -
                  pattern: @pattern,
         | 
| 122 | 
            -
                  boundary_color: @boundary_color, 
         | 
| 123 | 
            -
                  use_thumbnail: @use_thumbnail
         | 
| 124 | 
            -
                }
         | 
| 147 | 
            +
                { image: image,
         | 
| 148 | 
            +
                  boundaries: boundaries,
         | 
| 149 | 
            +
                  stage_boundary: stage_boundary
         | 
| 150 | 
            +
                }.merge!(extraction_metadata)
         | 
| 125 151 | 
             
              end
         | 
| 126 152 |  | 
| 127 153 | 
             
              protected
         | 
| 128 154 |  | 
| 129 155 | 
             
              def set_stage_boundary
         | 
| 130 | 
            -
                if  | 
| 131 | 
            -
                  boundary = Sqed::BoundaryFinder::StageFinder.new(image:  | 
| 156 | 
            +
                if has_border
         | 
| 157 | 
            +
                  boundary = Sqed::BoundaryFinder::StageFinder.new(image: image).boundaries
         | 
| 132 158 | 
             
                  if boundary.populated? 
         | 
| 133 | 
            -
                    @stage_boundary.set(0, boundary.for(0))  | 
| 159 | 
            +
                    @stage_boundary.set(0, boundary.for(0)) 
         | 
| 134 160 | 
             
                  else
         | 
| 135 161 | 
             
                    raise 'error detecting stage'
         | 
| 136 162 | 
             
                  end
         | 
| 137 163 | 
             
                else
         | 
| 138 | 
            -
                  @stage_boundary.set(0, [0, 0,  | 
| 164 | 
            +
                  @stage_boundary.set(0, [0, 0, image.columns, image.rows])
         | 
| 139 165 | 
             
                end
         | 
| 140 166 | 
             
              end
         | 
| 141 167 |  | 
| 142 | 
            -
              # TODO make this a setter
         | 
| 143 168 | 
             
              def get_section_boundaries
         | 
| 144 | 
            -
                boundary_finder_class = SqedConfig::EXTRACTION_PATTERNS[@pattern][:boundary_finder]
         | 
| 145 | 
            -
             | 
| 146 169 | 
             
                options = {image: stage_image, use_thumbnail: use_thumbnail}
         | 
| 147 | 
            -
                options.merge!( layout:  | 
| 148 | 
            -
                options.merge!( boundary_color:  | 
| 149 | 
            -
             | 
| 150 | 
            -
                boundary_finder_class.new(options).boundaries
         | 
| 170 | 
            +
                options.merge!( layout: extraction_metadata[:layout] ) unless extraction_metadata[:boundary_finder].name == 'Sqed::BoundaryFinder::CrossFinder'
         | 
| 171 | 
            +
                options.merge!( boundary_color: boundary_color) if extraction_metadata[:boundary_finder].name == 'Sqed::BoundaryFinder::ColorLineFinder'
         | 
| 151 172 |  | 
| 173 | 
            +
                extraction_metadata[:boundary_finder].new(options).boundaries
         | 
| 152 174 | 
             
              end
         | 
| 153 175 |  | 
| 154 176 | 
             
            end
         | 
    
        data/lib/sqed/version.rb
    CHANGED
    
    
| @@ -47,7 +47,8 @@ describe Sqed::Extractor do | |
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 49 | 
             
                specify '#result is populated with text' do
         | 
| 50 | 
            -
                  expect(r.text_for(:identifier)).to match(' | 
| 50 | 
            +
                  expect(r.text_for(:identifier)).to match('PSUC')
         | 
| 51 | 
            +
                  # expect(r.text_for(:identifier)).to match('000085067') # not catching this with default settings
         | 
| 51 52 | 
             
                end
         | 
| 52 53 |  | 
| 53 54 | 
             
                specify '#sections is populated with section_types' do
         | 
| @@ -62,10 +63,6 @@ describe Sqed::Extractor do | |
| 62 63 | 
             
                  end
         | 
| 63 64 | 
             
                end
         | 
| 64 65 |  | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 66 | 
             
              end
         | 
| 68 67 |  | 
| 69 68 | 
             
            end 
         | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
    
        data/spec/lib/sqed_spec.rb
    CHANGED
    
    | @@ -97,14 +97,13 @@ describe Sqed do | |
| 97 97 |  | 
| 98 98 | 
             
                  context 'extracted data' do
         | 
| 99 99 | 
             
                    specify 'text for an :identifier section' do
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                      r.identifier_image.write('41.jpg')
         | 
| 102 100 | 
             
                      expect(r.text_for(:identifier)).to match('000041196')
         | 
| 103 101 | 
             
                    end
         | 
| 104 102 |  | 
| 105 | 
            -
                     | 
| 106 | 
            -
             | 
| 107 | 
            -
                     | 
| 103 | 
            +
                    # This originally worked, it now does not in the present settings
         | 
| 104 | 
            +
                    # specify 'text for an annotated_specimen section' do
         | 
| 105 | 
            +
                    #   expect(r.text_for(:annotated_specimen)).to match('Saucier Creek')
         | 
| 106 | 
            +
                    # end
         | 
| 108 107 |  | 
| 109 108 | 
             
                    specify 'text for a curator_metadata section' do
         | 
| 110 109 | 
             
                      expect(r.text_for(:curator_metadata)).to match('Frost Entomological Museum')
         | 
| @@ -141,10 +140,10 @@ describe Sqed do | |
| 141 140 | 
             
                  end
         | 
| 142 141 |  | 
| 143 142 | 
             
                  context 'extracted data' do
         | 
| 144 | 
            -
                     | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
                    end
         | 
| 143 | 
            +
                    # Default settings return nothing, though some combinations of this worked previosly
         | 
| 144 | 
            +
                    # specify 'text for an :identifier section' do
         | 
| 145 | 
            +
                    #   expect(r.text_for(:identifier)).to match('000085067')
         | 
| 146 | 
            +
                    # end
         | 
| 148 147 |  | 
| 149 148 | 
             
                    specify 'text for a specimen section' do
         | 
| 150 149 | 
             
                      expect(r.text_for(:annotated_specimen)).to match('Aeshna')
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sqed
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matt Yoder
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015-09- | 
| 12 | 
            +
            date: 2015-09-17 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rake
         |