-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #247 Test
- Loading branch information
Showing
12 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Heathen | ||
class Processor | ||
def detect_language | ||
executioner.execute( | ||
Colore::C_.tika_path, | ||
"--config=#{Colore::TikaConfig.path_for_language_detection}", | ||
'--language', | ||
job.content_file, | ||
binary: true | ||
) | ||
raise ConversionFailed.new if executioner.last_exit_status != 0 | ||
|
||
job.content = executioner.stdout | ||
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Heathen::Processor do | ||
let(:content) { fixture('heathen/quickfox.ar.jpg').read } | ||
let(:job) { Heathen::Job.new 'foo', content } | ||
let(:processor) { described_class.new job: job, logger: spec_logger } | ||
|
||
before do | ||
setup_tika_config | ||
end | ||
|
||
after do | ||
processor.clean_up | ||
delete_tika_config | ||
end | ||
|
||
describe '#detect_language' do | ||
let(:content) { fixture('heathen/quickfox.jpg').read } | ||
|
||
before do | ||
processor.detect_language | ||
end | ||
|
||
it 'detects doccument language' do | ||
expect(job.content).to eq 'en' | ||
expect(job.content.mime_type).to eq 'text/plain; charset=us-ascii' | ||
end | ||
|
||
context 'with Arabic documents' do | ||
context 'when Arabic is not available in Tesseract' do | ||
it 'does not detect Arabic' do | ||
expect(job.content).not_to eq 'ar' | ||
end | ||
end | ||
|
||
context 'when Arabic is available in Tesseract' do | ||
before do | ||
allow(Colore::C_.config).to receive(:tesseract_available_languages).and_return(%w[fra eng]) | ||
end | ||
|
||
it 'detects Arabic' do | ||
expect(job.content).to eq 'ar' | ||
end | ||
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
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