Class: IiifPrint::TextExtractionDerivativeService

Inherits:
BaseDerivativeService show all
Defined in:
lib/iiif_print/text_extraction_derivative_service.rb

Instance Attribute Summary

Attributes inherited from BaseDerivativeService

#file_set, #master_format

Instance Method Summary collapse

Methods inherited from BaseDerivativeService

#convert_cmd, #derivative_path_factory, #identify, #im_convert, #jp2_convert, #jp2_to_intermediate, #load_destpath, #mime_type, #one_bit?, #prepare_path, #use_color?, #valid?

Constructor Details

#initialize(file_set) ⇒ TextExtractionDerivativeService

Returns a new instance of TextExtractionDerivativeService.



12
13
14
# File 'lib/iiif_print/text_extraction_derivative_service.rb', line 12

def initialize(file_set)
  super(file_set)
end

Instance Method Details

#cleanup_derivativesObject



41
42
43
44
45
# File 'lib/iiif_print/text_extraction_derivative_service.rb', line 41

def cleanup_derivatives(*)
  ocr_derivatives.keys do |extension|
    super(extension.to_s)
  end
end

#create_derivatives(src) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/iiif_print/text_extraction_derivative_service.rb', line 16

def create_derivatives(src)
  from_alto = alto_derivative_service_class.new(
    file_set
  )
  return from_alto.create_derivatives(src) unless from_alto.alto_path.nil?
  create_derivatives_from_ocr(src)
end

#create_derivatives_from_ocr(filename) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/iiif_print/text_extraction_derivative_service.rb', line 24

def create_derivatives_from_ocr(filename)
  # TODO: Do we need this source_path instance variable?
  @source_path = filename
  ocr = page_ocr_service_class.new(filename)

  ocr_derivatives.each do |extension, method_name|
    path = prepare_path(extension.to_s)
    write(content: ocr.public_send(method_name), path: path)
  end
end

#write(content:, path:) ⇒ Object



35
36
37
38
39
# File 'lib/iiif_print/text_extraction_derivative_service.rb', line 35

def write(content:, path:)
  File.open(path, 'w') do |outfile|
    outfile.write(content)
  end
end