rtesseract 3.0.0 → 3.1.0
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/.gitignore +1 -0
- data/.hound.yml +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +4 -3
- data/CHANGELOG.md +12 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +26 -29
- data/README.md +32 -33
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/rtesseract/base.rb +15 -0
- data/lib/rtesseract/box.rb +32 -21
- data/lib/rtesseract/check.rb +4 -3
- data/lib/rtesseract/command.rb +34 -19
- data/lib/rtesseract/configuration.rb +10 -4
- data/lib/rtesseract/pdf.rb +6 -9
- data/lib/rtesseract/text.rb +5 -3
- data/lib/rtesseract/tsv.rb +6 -9
- data/lib/rtesseract/version.rb +3 -1
- data/lib/rtesseract.rb +17 -13
- data/rtesseract.gemspec +17 -19
- metadata +12 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 43dd931b6649c05a5cb484f3fc0548075d088e5682bbbea46d7ac3202a9b607c
|
|
4
|
+
data.tar.gz: 1b300fa5a83f458c986dabde158b3ff31dfeed6e7c7c3c98a17812fdf62c4bbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 955b9c159f1a89d681e5add1151d79ad2f0f29fbcd65d5558cb08b4a856f5442b6dfd4ae157b57f5bad869dbf9690a13bd1784bb23a7068a7c8402c8abba2468
|
|
7
|
+
data.tar.gz: daa3a7aa5ba7549c30f0bb85019c6197acec22854122887a8fd5693b52828f8c1b1210806c6d307f1109ddb784f13f090192884f8ae820941b444055df79de7e
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
Layout/LineLength:
|
|
3
|
+
Max: 150
|
|
4
|
+
|
|
5
|
+
Metrics/BlockLength:
|
|
6
|
+
Max: 50
|
|
7
|
+
|
|
8
|
+
Metrics/AbcSize:
|
|
9
|
+
Max: 30
|
|
10
|
+
|
|
11
|
+
Style/Documentation:
|
|
12
|
+
Enabled: false
|
|
13
|
+
Style/HashEachMethods:
|
|
14
|
+
Enabled: true
|
|
15
|
+
|
|
16
|
+
Style/HashTransformKeys:
|
|
17
|
+
Enabled: true
|
|
18
|
+
|
|
19
|
+
Style/HashTransformValues:
|
|
20
|
+
Enabled: true
|
data/.travis.yml
CHANGED
|
@@ -9,8 +9,9 @@ before_install:
|
|
|
9
9
|
- sudo add-apt-repository ppa:alex-p/tesseract-ocr -y
|
|
10
10
|
- sudo apt-get update -q
|
|
11
11
|
- sudo apt-get install tesseract-ocr tesseract-ocr-eng ghostscript -y
|
|
12
|
-
- gem install bundler
|
|
12
|
+
- gem install bundler
|
|
13
13
|
|
|
14
14
|
rvm:
|
|
15
|
-
- 2.
|
|
16
|
-
- 2.5
|
|
15
|
+
- 2.5.5
|
|
16
|
+
- 2.6.5
|
|
17
|
+
- 2.7.0
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
4
6
|
|
|
5
7
|
# Specify your gem's dependencies in rtesseract.gemspec
|
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rtesseract (3.
|
|
5
|
-
nokogiri
|
|
4
|
+
rtesseract (3.1.0)
|
|
6
5
|
|
|
7
6
|
GEM
|
|
8
7
|
remote: https://rubygems.org/
|
|
9
8
|
specs:
|
|
10
|
-
coveralls (0.8.
|
|
9
|
+
coveralls (0.8.23)
|
|
11
10
|
json (>= 1.8, < 3)
|
|
12
11
|
simplecov (~> 0.16.1)
|
|
13
12
|
term-ansicolor (~> 1.3)
|
|
14
|
-
thor (
|
|
13
|
+
thor (>= 0.19.4, < 2.0)
|
|
15
14
|
tins (~> 1.6)
|
|
16
15
|
diff-lcs (1.3)
|
|
17
|
-
docile (1.3.
|
|
18
|
-
json (2.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
rspec-
|
|
26
|
-
|
|
27
|
-
rspec-core (3.8.0)
|
|
28
|
-
rspec-support (~> 3.8.0)
|
|
29
|
-
rspec-expectations (3.8.2)
|
|
16
|
+
docile (1.3.2)
|
|
17
|
+
json (2.3.0)
|
|
18
|
+
rake (13.0.1)
|
|
19
|
+
rspec (3.9.0)
|
|
20
|
+
rspec-core (~> 3.9.0)
|
|
21
|
+
rspec-expectations (~> 3.9.0)
|
|
22
|
+
rspec-mocks (~> 3.9.0)
|
|
23
|
+
rspec-core (3.9.1)
|
|
24
|
+
rspec-support (~> 3.9.1)
|
|
25
|
+
rspec-expectations (3.9.1)
|
|
30
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
-
rspec-support (~> 3.
|
|
32
|
-
rspec-mocks (3.
|
|
27
|
+
rspec-support (~> 3.9.0)
|
|
28
|
+
rspec-mocks (3.9.1)
|
|
33
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
-
rspec-support (~> 3.
|
|
35
|
-
rspec-support (3.
|
|
30
|
+
rspec-support (~> 3.9.0)
|
|
31
|
+
rspec-support (3.9.2)
|
|
36
32
|
simplecov (0.16.1)
|
|
37
33
|
docile (~> 1.1)
|
|
38
34
|
json (>= 1.8, < 3)
|
|
39
35
|
simplecov-html (~> 0.10.0)
|
|
40
36
|
simplecov-html (0.10.2)
|
|
41
|
-
|
|
37
|
+
sync (0.5.0)
|
|
38
|
+
term-ansicolor (1.7.1)
|
|
42
39
|
tins (~> 1.0)
|
|
43
|
-
thor (0.
|
|
44
|
-
tins (1.
|
|
40
|
+
thor (1.0.1)
|
|
41
|
+
tins (1.24.1)
|
|
42
|
+
sync
|
|
45
43
|
|
|
46
44
|
PLATFORMS
|
|
47
45
|
ruby
|
|
48
46
|
|
|
49
47
|
DEPENDENCIES
|
|
50
|
-
bundler (~>
|
|
48
|
+
bundler (~> 2)
|
|
51
49
|
coveralls
|
|
52
|
-
rake
|
|
53
|
-
rspec
|
|
50
|
+
rake
|
|
51
|
+
rspec
|
|
54
52
|
rtesseract!
|
|
55
|
-
simplecov
|
|
56
53
|
|
|
57
54
|
BUNDLED WITH
|
|
58
|
-
1.
|
|
55
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -57,7 +57,7 @@ It's very simple to use rtesseract.
|
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
59
|
image = RTesseract.new("my_image.jpg")
|
|
60
|
-
image.to_tsv # Getting open file of
|
|
60
|
+
image.to_tsv # Getting open file of tsv
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
This will preserve the image colors, pictures and structure in the generated pdf.
|
|
@@ -66,22 +66,22 @@ This will preserve the image colors, pictures and structure in the generated pdf
|
|
|
66
66
|
|
|
67
67
|
### Language
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
```ruby
|
|
70
|
+
RTesseract.new('test.jpg', lang: 'deu')
|
|
71
|
+
```
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
* eng - English
|
|
74
|
+
* deu - German
|
|
75
|
+
* deu-f - German fraktur
|
|
76
|
+
* fra - French
|
|
77
|
+
* ita - Italian
|
|
78
|
+
* nld - Dutch
|
|
79
|
+
* por - Portuguese
|
|
80
|
+
* spa - Spanish
|
|
81
|
+
* vie - Vietnamese
|
|
82
|
+
* or any other supported by tesseract.
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Note: Make sure you have installed the language to tesseract
|
|
85
85
|
|
|
86
86
|
### Other options
|
|
87
87
|
|
|
@@ -96,28 +96,27 @@ This will preserve the image colors, pictures and structure in the generated pdf
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
### BOUNDING BOX: TO GET WORDS WITH THEIR POSITIONS
|
|
99
|
+
|
|
99
100
|
```ruby
|
|
100
101
|
RTesseract.new('test_words.png').to_box
|
|
102
|
+
=> [
|
|
103
|
+
{:word => 'If', :x_start=>52, :y_start=>13, :x_end=>63, :y_end=>27},
|
|
104
|
+
{:word => 'you', :x_start=>69, :y_start=>17, :x_end=>100, :y_end=>31},
|
|
105
|
+
{:word => 'are', :x_start=>108, :y_start=>17, :x_end=>136, :y_end=>27},
|
|
106
|
+
{:word => 'a', :x_start=>143, :y_start=>17, :x_end=>151, :y_end=>27},
|
|
107
|
+
{:word => 'friend,', :x_start=>158, :y_start=>13, :x_end=>214, :y_end=>29},
|
|
108
|
+
{:word => 'you', :x_start=>51, :y_start=>39, :x_end=>82, :y_end=>53},
|
|
109
|
+
{:word => 'speak', :x_start=>90, :y_start=>35, :x_end=>140, :y_end=>53},
|
|
110
|
+
{:word => 'the', :x_start=>146, :y_start=>35, :x_end=>174, :y_end=>49},
|
|
111
|
+
{:word => 'password,', :x_start=>182, :y_start=>35, :x_end=>267, :y_end=>53},
|
|
112
|
+
{:word => 'and', :x_start=>51, :y_start=>57, :x_end=>81, :y_end=>71},
|
|
113
|
+
{:word => 'the', :x_start=>89, :y_start=>57, :x_end=>117, :y_end=>71},
|
|
114
|
+
{:word => 'doors', :x_start=>124, :y_start=>57, :x_end=>172, :y_end=>71},
|
|
115
|
+
{:word => 'will', :x_start=>180, :y_start=>57, :x_end=>208, :y_end=>71},
|
|
116
|
+
{:word => 'open.', :x_start=>216, :y_start=>61, :x_end=>263, :y_end=>75}
|
|
117
|
+
]
|
|
101
118
|
```
|
|
102
119
|
|
|
103
|
-
# => [
|
|
104
|
-
# {:word => 'If', :x_start=>52, :y_start=>13, :x_end=>63, :y_end=>27},
|
|
105
|
-
# {:word => 'you', :x_start=>69, :y_start=>17, :x_end=>100, :y_end=>31},
|
|
106
|
-
# {:word => 'are', :x_start=>108, :y_start=>17, :x_end=>136, :y_end=>27},
|
|
107
|
-
# {:word => 'a', :x_start=>143, :y_start=>17, :x_end=>151, :y_end=>27},
|
|
108
|
-
# {:word => 'friend,', :x_start=>158, :y_start=>13, :x_end=>214, :y_end=>29},
|
|
109
|
-
# {:word => 'you', :x_start=>51, :y_start=>39, :x_end=>82, :y_end=>53},
|
|
110
|
-
# {:word => 'speak', :x_start=>90, :y_start=>35, :x_end=>140, :y_end=>53},
|
|
111
|
-
# {:word => 'the', :x_start=>146, :y_start=>35, :x_end=>174, :y_end=>49},
|
|
112
|
-
# {:word => 'password,', :x_start=>182, :y_start=>35, :x_end=>267, :y_end=>53},
|
|
113
|
-
# {:word => 'and', :x_start=>51, :y_start=>57, :x_end=>81, :y_end=>71},
|
|
114
|
-
# {:word => 'the', :x_start=>89, :y_start=>57, :x_end=>117, :y_end=>71},
|
|
115
|
-
# {:word => 'doors', :x_start=>124, :y_start=>57, :x_end=>172, :y_end=>71},
|
|
116
|
-
# {:word => 'will', :x_start=>180, :y_start=>57, :x_end=>208, :y_end=>71},
|
|
117
|
-
# {:word => 'open.', :x_start=>216, :y_start=>61, :x_end=>263, :y_end=>75}
|
|
118
|
-
# ]
|
|
119
|
-
|
|
120
|
-
|
|
121
120
|
## Development
|
|
122
121
|
|
|
123
122
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'rtesseract'
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +11,5 @@ require "rtesseract"
|
|
|
10
11
|
# require "pry"
|
|
11
12
|
# Pry.start
|
|
12
13
|
|
|
13
|
-
require
|
|
14
|
+
require 'irb'
|
|
14
15
|
IRB.start(__FILE__)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require 'securerandom'
|
|
5
|
+
require 'pathname'
|
|
6
|
+
|
|
7
|
+
class RTesseract
|
|
8
|
+
module Base
|
|
9
|
+
def temp_file(ext = '')
|
|
10
|
+
@rand_file ||= "rtesseract_#{SecureRandom.uuid}"
|
|
11
|
+
|
|
12
|
+
Pathname.new(Dir.tmpdir).join("#{@rand_file}#{ext}").to_s
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/rtesseract/box.rb
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
require 'tmpdir'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
3
|
class RTesseract
|
|
5
4
|
module Box
|
|
6
|
-
|
|
7
|
-
@file_path = Pathname.new(Dir.tmpdir)
|
|
8
|
-
end
|
|
5
|
+
extend RTesseract::Base
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
class << self
|
|
8
|
+
def run(source, errors, options)
|
|
9
|
+
options.tessedit_create_hocr = 1
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
RTesseract::Command.new(source, temp_file, errors, options).run
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
parse(File.read(temp_file('.hocr')))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def parse(content)
|
|
17
|
+
content.lines.map { |line| parse_line(line) }.compact
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def parse_line(line)
|
|
21
|
+
return unless line.match?(/oc(rx|r)_word/)
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
html = Nokogiri::HTML(content)
|
|
21
|
-
html.css('span.ocrx_word, span.ocr_word').map do |word|
|
|
22
|
-
@attributes = word.attributes['title'].value.to_s.gsub(';', '').split(' ')
|
|
23
|
+
word = line.match(/(?<=>)(.*?)(?=<)/).to_s
|
|
23
24
|
|
|
25
|
+
return if word.strip == ''
|
|
26
|
+
|
|
27
|
+
word_info(word, parse_position(line))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def word_info(word, positions)
|
|
24
31
|
{
|
|
25
|
-
word: word
|
|
26
|
-
x_start:
|
|
27
|
-
y_start:
|
|
28
|
-
x_end:
|
|
29
|
-
y_end:
|
|
32
|
+
word: word,
|
|
33
|
+
x_start: positions[1].to_i,
|
|
34
|
+
y_start: positions[2].to_i,
|
|
35
|
+
x_end: positions[3].to_i,
|
|
36
|
+
y_end: positions[4].to_i
|
|
30
37
|
}
|
|
31
38
|
end
|
|
39
|
+
|
|
40
|
+
def parse_position(line)
|
|
41
|
+
line.match(/(?<=title)(.*?)(?=;)/).to_s.split(' ')
|
|
42
|
+
end
|
|
32
43
|
end
|
|
33
44
|
end
|
|
34
|
-
end
|
|
45
|
+
end
|
data/lib/rtesseract/check.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
3
|
class RTesseract
|
|
3
4
|
class << self
|
|
4
5
|
def tesseract_version
|
|
5
|
-
Open3.capture2e(RTesseract.config.command,
|
|
6
|
+
Open3.capture2e(RTesseract.config.command, '--version').first.to_s.match(/\d+.\d+/)[0].to_f
|
|
6
7
|
rescue Errno::ENOENT
|
|
7
8
|
0
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def check_version!
|
|
11
|
-
raise RTesseract::Error
|
|
12
|
+
raise RTesseract::Error, 'Tesseract OCR 3.5 or later not installed' if RTesseract.tesseract_version < 3.05
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
|
-
end
|
|
15
|
+
end
|
data/lib/rtesseract/command.rb
CHANGED
|
@@ -1,41 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class RTesseract
|
|
4
4
|
class Command
|
|
5
|
-
FIXED = [
|
|
5
|
+
FIXED = %i[command psm oem lang tessdata_dir user_words user_patterns config_file].freeze
|
|
6
6
|
|
|
7
7
|
attr_reader :options
|
|
8
8
|
|
|
9
|
-
def initialize(source, output, options)
|
|
9
|
+
def initialize(source, output, errors, options)
|
|
10
10
|
@source = source
|
|
11
11
|
@output = output
|
|
12
12
|
@options = options
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def configs
|
|
16
|
-
@options.to_h.map { |key, value| ['-c', "#{key}=#{value}"] unless FIXED.include?(key) }.compact
|
|
13
|
+
@errors = errors
|
|
14
|
+
@full_command = [options.command, @source, @output]
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
def full_command
|
|
20
|
-
|
|
18
|
+
add_option('--psm', options.psm)
|
|
19
|
+
add_option('--oem', options.oem)
|
|
20
|
+
add_option('-l', options.lang)
|
|
21
|
+
add_option('--tessdata-dir', options.tessdata_dir)
|
|
22
|
+
add_option('--user-words', options.user_words)
|
|
23
|
+
add_option('--user-patterns', options.user_patterns)
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
command << ['--oem', options.oem.to_s] if options.oem
|
|
24
|
-
command << ['-l', options.lang] if options.lang
|
|
25
|
+
other_configs
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
command << ['--user_words', options.user_words] if options.user_words
|
|
28
|
-
command << ['--user_patterns', options.user_patterns] if options.user_patterns
|
|
27
|
+
add_option(options.config_file)
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
@full_command
|
|
30
|
+
end
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
def add_option(*args)
|
|
33
|
+
return unless args.last
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
@full_command << args.map(&:to_s)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def other_configs
|
|
39
|
+
@options.to_h.map do |key, value|
|
|
40
|
+
next if FIXED.include?(key)
|
|
41
|
+
|
|
42
|
+
add_option('-c', "#{key}=#{value}")
|
|
43
|
+
end
|
|
35
44
|
end
|
|
36
45
|
|
|
37
46
|
def run
|
|
38
|
-
Open3.
|
|
47
|
+
output, error, status = Open3.capture3(*full_command.flatten)
|
|
48
|
+
|
|
49
|
+
@errors.push(error)
|
|
50
|
+
|
|
51
|
+
return output if status.success?
|
|
52
|
+
|
|
53
|
+
raise RTesseract::Error, error
|
|
39
54
|
end
|
|
40
55
|
end
|
|
41
|
-
end
|
|
56
|
+
end
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'ostruct'
|
|
2
4
|
|
|
3
5
|
class RTesseract
|
|
4
6
|
class Configuration < OpenStruct
|
|
5
7
|
def merge(options)
|
|
6
|
-
RTesseract::Configuration.new(
|
|
8
|
+
RTesseract::Configuration.new(to_h.merge(options))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def command
|
|
12
|
+
@table[:command]
|
|
7
13
|
end
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
class << self
|
|
11
17
|
def config
|
|
12
18
|
@config ||= RTesseract::Configuration.new(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
command: 'tesseract',
|
|
20
|
+
debug_file: '/dev/null'
|
|
21
|
+
)
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
def configure
|
data/lib/rtesseract/pdf.rb
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class RTesseract
|
|
4
4
|
module Pdf
|
|
5
|
-
|
|
6
|
-
@file_path = Pathname.new(Dir.tmpdir)
|
|
7
|
-
end
|
|
5
|
+
extend Base
|
|
8
6
|
|
|
9
|
-
def self.run(source, options)
|
|
10
|
-
name = "rtesseract_#{SecureRandom.uuid}"
|
|
7
|
+
def self.run(source, errors, options)
|
|
11
8
|
options.tessedit_create_pdf = 1
|
|
12
9
|
|
|
13
|
-
RTesseract::Command.new(source,
|
|
10
|
+
RTesseract::Command.new(source, temp_file, errors, options).run
|
|
14
11
|
|
|
15
|
-
File.open(
|
|
12
|
+
File.open(temp_file('.pdf'), 'r')
|
|
16
13
|
end
|
|
17
14
|
end
|
|
18
|
-
end
|
|
15
|
+
end
|
data/lib/rtesseract/text.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'open3'
|
|
2
4
|
|
|
3
5
|
class RTesseract
|
|
4
6
|
module Text
|
|
5
|
-
def self.run(source, options)
|
|
6
|
-
RTesseract::Command.new(source, 'stdout', options).run
|
|
7
|
+
def self.run(source, errors, options)
|
|
8
|
+
RTesseract::Command.new(source, 'stdout', errors, options).run
|
|
7
9
|
end
|
|
8
10
|
end
|
|
9
|
-
end
|
|
11
|
+
end
|
data/lib/rtesseract/tsv.rb
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class RTesseract
|
|
4
4
|
module Tsv
|
|
5
|
-
|
|
6
|
-
@file_path = Pathname.new(Dir.tmpdir)
|
|
7
|
-
end
|
|
5
|
+
extend Base
|
|
8
6
|
|
|
9
|
-
def self.run(source, options)
|
|
10
|
-
name = "rtesseract_#{SecureRandom.uuid}"
|
|
7
|
+
def self.run(source, errors, options)
|
|
11
8
|
options.tessedit_create_tsv = 1
|
|
12
9
|
|
|
13
|
-
RTesseract::Command.new(source,
|
|
10
|
+
RTesseract::Command.new(source, temp_file, errors, options).run
|
|
14
11
|
|
|
15
|
-
File.open(
|
|
12
|
+
File.open(temp_file('.tsv'), 'r')
|
|
16
13
|
end
|
|
17
14
|
end
|
|
18
|
-
end
|
|
15
|
+
end
|
data/lib/rtesseract/version.rb
CHANGED
data/lib/rtesseract.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rtesseract/check'
|
|
4
|
+
require 'rtesseract/configuration'
|
|
5
|
+
require 'rtesseract/command'
|
|
6
|
+
require 'rtesseract/base'
|
|
7
|
+
require 'rtesseract/text'
|
|
8
|
+
require 'rtesseract/pdf'
|
|
9
|
+
require 'rtesseract/box'
|
|
10
|
+
require 'rtesseract/tsv'
|
|
8
11
|
|
|
9
12
|
class RTesseract
|
|
10
13
|
class Error < StandardError; end
|
|
11
14
|
|
|
12
|
-
check_version!
|
|
13
|
-
|
|
14
15
|
attr_reader :config, :source
|
|
15
16
|
|
|
16
17
|
def initialize(src = '', options = {})
|
|
17
18
|
@source = src
|
|
18
19
|
@config = RTesseract.config.merge(options)
|
|
20
|
+
@errors = []
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def to_box
|
|
22
|
-
Box.run(@source, config)
|
|
24
|
+
Box.run(@source, @errors, config)
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def words
|
|
@@ -27,20 +29,22 @@ class RTesseract
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def to_pdf
|
|
30
|
-
Pdf.run(@source, config)
|
|
32
|
+
Pdf.run(@source, @errors, config)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def to_tsv
|
|
34
|
-
Tsv.run(@source, config)
|
|
36
|
+
Tsv.run(@source, @errors, config)
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
# Output value
|
|
38
40
|
def to_s
|
|
39
|
-
Text.run(@source, config)
|
|
41
|
+
Text.run(@source, @errors, config)
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
# Remove spaces and break-lines
|
|
43
45
|
def to_s_without_spaces
|
|
44
46
|
to_s.gsub(/\s/, '')
|
|
45
47
|
end
|
|
48
|
+
|
|
49
|
+
attr_reader :errors
|
|
46
50
|
end
|
data/rtesseract.gemspec
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
|
-
lib = File.expand_path(
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
5
|
+
require 'rtesseract/version'
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
8
|
+
spec.name = 'rtesseract'
|
|
8
9
|
spec.version = RTesseract::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
10
|
+
spec.authors = ['Danilo Jeremias da Silva']
|
|
11
|
+
spec.email = ['dannnylo@gmail.com']
|
|
11
12
|
|
|
12
|
-
spec.summary =
|
|
13
|
-
spec.description =
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.license =
|
|
13
|
+
spec.summary = 'Ruby library for working with the Tesseract OCR.'
|
|
14
|
+
spec.description = 'Ruby library for working with the Tesseract OCR.'
|
|
15
|
+
spec.homepage = 'http://github.com/dannnylo/rtesseract'
|
|
16
|
+
spec.license = 'MIT'
|
|
16
17
|
|
|
17
18
|
# Specify which files should be added to the gem when it is released.
|
|
18
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
|
-
spec.files = Dir.chdir(File.expand_path(
|
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
20
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
22
|
end
|
|
22
|
-
spec.bindir =
|
|
23
|
+
spec.bindir = 'exe'
|
|
23
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
-
spec.require_paths = [
|
|
25
|
+
spec.require_paths = ['lib']
|
|
25
26
|
|
|
26
|
-
spec.add_development_dependency
|
|
27
|
-
spec.add_development_dependency
|
|
28
|
-
spec.add_development_dependency
|
|
29
|
-
spec.add_development_dependency
|
|
30
|
-
spec.add_development_dependency "coveralls"
|
|
31
|
-
|
|
32
|
-
spec.add_dependency "nokogiri"
|
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
|
28
|
+
spec.add_development_dependency 'coveralls'
|
|
29
|
+
spec.add_development_dependency 'rake'
|
|
30
|
+
spec.add_development_dependency 'rspec'
|
|
33
31
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rtesseract
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danilo Jeremias da Silva
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,44 +16,16 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '10.0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '10.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rspec
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '3.0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '3.0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: simplecov
|
|
28
|
+
name: coveralls
|
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
|
58
30
|
requirements:
|
|
59
31
|
- - ">="
|
|
@@ -67,7 +39,7 @@ dependencies:
|
|
|
67
39
|
- !ruby/object:Gem::Version
|
|
68
40
|
version: '0'
|
|
69
41
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
42
|
+
name: rake
|
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
|
72
44
|
requirements:
|
|
73
45
|
- - ">="
|
|
@@ -81,13 +53,13 @@ dependencies:
|
|
|
81
53
|
- !ruby/object:Gem::Version
|
|
82
54
|
version: '0'
|
|
83
55
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
56
|
+
name: rspec
|
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
|
86
58
|
requirements:
|
|
87
59
|
- - ">="
|
|
88
60
|
- !ruby/object:Gem::Version
|
|
89
61
|
version: '0'
|
|
90
|
-
type: :
|
|
62
|
+
type: :development
|
|
91
63
|
prerelease: false
|
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
65
|
requirements:
|
|
@@ -103,7 +75,9 @@ extra_rdoc_files: []
|
|
|
103
75
|
files:
|
|
104
76
|
- ".document"
|
|
105
77
|
- ".gitignore"
|
|
78
|
+
- ".hound.yml"
|
|
106
79
|
- ".rspec"
|
|
80
|
+
- ".rubocop.yml"
|
|
107
81
|
- ".travis.yml"
|
|
108
82
|
- CHANGELOG.md
|
|
109
83
|
- CODE_OF_CONDUCT.md
|
|
@@ -115,6 +89,7 @@ files:
|
|
|
115
89
|
- bin/console
|
|
116
90
|
- bin/setup
|
|
117
91
|
- lib/rtesseract.rb
|
|
92
|
+
- lib/rtesseract/base.rb
|
|
118
93
|
- lib/rtesseract/box.rb
|
|
119
94
|
- lib/rtesseract/check.rb
|
|
120
95
|
- lib/rtesseract/command.rb
|
|
@@ -143,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
143
118
|
- !ruby/object:Gem::Version
|
|
144
119
|
version: '0'
|
|
145
120
|
requirements: []
|
|
146
|
-
|
|
147
|
-
rubygems_version: 2.7.6
|
|
121
|
+
rubygems_version: 3.0.6
|
|
148
122
|
signing_key:
|
|
149
123
|
specification_version: 4
|
|
150
124
|
summary: Ruby library for working with the Tesseract OCR.
|