-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove nokogiri dependency * Update Gemfile and bump version * Update methods * Update rubocop version on hound and a little refactoring.
- Loading branch information
Showing
23 changed files
with
111 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rubocop: | ||
config_file: .rubocop.yml | ||
version: 0.80.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
Documentation: | ||
Enabled: false | ||
|
||
Metrics/LineLength: | ||
Layout/LineLength: | ||
Max: 150 | ||
|
||
Metrics/BlockLength: | ||
Max: 50 | ||
|
||
Metrics/AbcSize: | ||
Max: 30 | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
Style/HashEachMethods: | ||
Enabled: true | ||
|
||
Style/HashTransformKeys: | ||
Enabled: true | ||
|
||
Style/HashTransformValues: | ||
Enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'rtesseract' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'tmpdir' | ||
require 'securerandom' | ||
require 'pathname' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
require 'nokogiri' | ||
# frozen_string_literal: true | ||
|
||
class RTesseract | ||
module Box | ||
extend RTesseract::Base | ||
|
||
def self.run(source, errors, options) | ||
options.tessedit_create_hocr = 1 | ||
class << self | ||
def run(source, errors, options) | ||
options.tessedit_create_hocr = 1 | ||
|
||
RTesseract::Command.new(source, temp_file, errors, options).run | ||
RTesseract::Command.new(source, temp_file, errors, options).run | ||
|
||
parse(File.read(temp_file('.hocr'))) | ||
end | ||
parse(File.read(temp_file('.hocr'))) | ||
end | ||
|
||
def self.parse(content) | ||
html = Nokogiri::HTML(content) | ||
html.css('span.ocrx_word, span.ocr_word').map do |word| | ||
attributes = word.attributes['title'].value.to_s.delete(';').split(' ') | ||
word_info(word, attributes) | ||
def parse(content) | ||
content.lines.map { |line| parse_line(line) }.compact | ||
end | ||
end | ||
|
||
def self.word_info(word, data) | ||
{ | ||
word: word.text, | ||
x_start: data[1].to_i, | ||
y_start: data[2].to_i, | ||
x_end: data[3].to_i, | ||
y_end: data[4].to_i | ||
} | ||
def parse_line(line) | ||
return unless line.match?(/oc(rx|r)_word/) | ||
|
||
word = line.match(/(?<=>)(.*?)(?=<)/).to_s | ||
|
||
return if word.strip == '' | ||
|
||
word_info(word, parse_position(line)) | ||
end | ||
|
||
def word_info(word, positions) | ||
{ | ||
word: word, | ||
x_start: positions[1].to_i, | ||
y_start: positions[2].to_i, | ||
x_end: positions[3].to_i, | ||
y_end: positions[4].to_i | ||
} | ||
end | ||
|
||
def parse_position(line) | ||
line.match(/(?<=title)(.*?)(?=;)/).to_s.split(' ') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class RTesseract | ||
class << self | ||
def tesseract_version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ostruct' | ||
|
||
class RTesseract | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class RTesseract | ||
module Pdf | ||
extend Base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'open3' | ||
|
||
class RTesseract | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class RTesseract | ||
module Tsv | ||
extend Base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class RTesseract | ||
VERSION = '3.0.5'.freeze | ||
VERSION = '3.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
lib = File.expand_path('lib', __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'rtesseract/version' | ||
|
@@ -8,9 +10,9 @@ Gem::Specification.new do |spec| | |
spec.authors = ['Danilo Jeremias da Silva'] | ||
spec.email = ['[email protected]'] | ||
|
||
spec.summary = 'Ruby library for working with the Tesseract OCR.'.freeze | ||
spec.description = 'Ruby library for working with the Tesseract OCR.'.freeze | ||
spec.homepage = 'http://github.com/dannnylo/rtesseract'.freeze | ||
spec.summary = 'Ruby library for working with the Tesseract OCR.' | ||
spec.description = 'Ruby library for working with the Tesseract OCR.' | ||
spec.homepage = 'http://github.com/dannnylo/rtesseract' | ||
spec.license = 'MIT' | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
|
@@ -26,7 +28,4 @@ Gem::Specification.new do |spec| | |
spec.add_development_dependency 'coveralls' | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rspec' | ||
spec.add_development_dependency 'simplecov' | ||
|
||
spec.add_dependency 'nokogiri' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'csv' | ||
|
||
RSpec.describe RTesseract::Tsv do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'coveralls' | ||
require 'simplecov' | ||
|