Skip to content

Commit 990ef5c

Browse files
committed
Rename option & rework invocation.
1 parent 989e439 commit 990ef5c

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

lib/docsplit/command_line.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def usage
7171
# Use the OptionParser library to parse out all supported options. Return
7272
# options formatted for the Ruby API.
7373
def parse_options
74-
@options = {:ocr => :default, :clean => true}
74+
@options = {:ocr => :default, :clean => true, :detect_orientation => true}
7575
@option_parser = OptionParser.new do |opts|
7676
opts.on('-o', '--output [DIR]', 'set the directory for all output') do |d|
7777
@options[:output] = d
@@ -98,8 +98,8 @@ def parse_options
9898
@options[:language] = l
9999
@options[:clean] = false
100100
end
101-
opts.on('-n', '--no-orientation-detection', 'turn off automatic orientation detection in tesseract') do |n|
102-
@options[:nod] = true
101+
opts.on('--no-orientation-detection', 'turn off automatic orientation detection in tesseract') do |n|
102+
@options[:detect_orientation] = false
103103
end
104104
opts.on('-r', '--rolling', 'generate images from each previous image') do |r|
105105
@options[:rolling] = true

lib/docsplit/text_extractor.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ def extract_from_ocr(pdf, pages)
7474
tiff = "#{tempdir}/#{@pdf_name}.tif"
7575
escaped_tiff = ESCAPE[tiff]
7676
run "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert -despeckle #{MEMORY_ARGS} #{OCR_FLAGS} #{escaped_pdf} #{escaped_tiff} 2>&1"
77-
psm = "-psm 1"
78-
if @nod || !DEPENDENCIES[:osd] #if the user says don't do orientation detection or the plugin is not installed, set psm to 0
79-
psm = ""
80-
end
77+
#if the user says don't do orientation detection or the plugin is not installed, set psm to 0
78+
psm = "-psm 1" if @detect_orientation and DEPENDENCIES[:osd]
79+
psm ||= ""
8180
run "tesseract #{escaped_tiff} #{base_path} -l #{@language} #{psm} 2>&1"
8281
clean_text(base_path + '.txt') if @clean_ocr
8382
end
@@ -121,15 +120,15 @@ def extract_page(pdf, page)
121120
end
122121

123122
def extract_options(options)
124-
@output = options[:output] || '.'
125-
@pages = options[:pages]
126-
@force_ocr = options[:ocr] == true
127-
@forbid_ocr = options[:ocr] == false
128-
@clean_ocr = !(options[:clean] == false)
129-
@language = options[:language] || 'eng'
130-
@nod = options[:nod] == true
123+
@output = options[:output] || '.'
124+
@pages = options[:pages]
125+
@force_ocr = options[:ocr] == true
126+
@forbid_ocr = options[:ocr] == false
127+
@clean_ocr = !(options[:clean] == false)
128+
@language = options[:language] || 'eng'
129+
@detect_orientation = options[:detect_orientation] == true
131130
end
132131

133132
end
134133

135-
end
134+
end

0 commit comments

Comments
 (0)