<commit_before>import async from 'async';
import log from 'winston';
import tesseract from 'node-tesseract';
import tesseractjs from 'tesseract.js';
import {httpClient} from './http-client.js';
import config from '../config.json';

class OCRExtractor {
    constructor(file) {
        this.file = file;
        this.extracts = {};
    }

    extract(next) {
        console.log('---------- OCR Extraction start');
        async.parallelLimit({
                tesseract: (callback) => {
                    this.tesseract(callback);
                },
                tesseractjs: (callback) => {
                    this.tesseractjs(callback);
                }
            },
            2,
            (err, results) => {
                if (err !== null) {
                    log.error(`[OCRExtractor.extract] ${err}`);
                } else {
                    log.info(results);
                }
                next(err, results);
            });
    }

    tesseract(next) {
        if (process.env.OS !== 'Windows_NT') {
            tesseract.process(this.file, function(error, text) {
                log.info('[OCR][tesseract] Result : ');
                if (error !== null) {
                    log.info('[OCR][tesseract] Error :');
                    log.info(error);
                } else {
                    text = text.trim();
                    log.info('[OCR][tesseract] Success :');
                    log.info(text);
                }
                next(null, {text, error});
            }, null, 6);
        } else {
            log.info('[OCR][tesseract] Skyped');
            next(null, {});
        }
    }

    tesseractjs(next) {
        log.info('[OCR][tesseractjs] Result : ');
        tesseractjs.recognize(this.file)
            .catch((err) => {
                log.info('[OCR][tesseractjs] Error :');
                log.error(err);
                next(err, {err});
            })
            .then(function(result) {
                let text = result.text.trim();
                log.info('[OCR][tesseractjs] Success :');
                log.info(text);
                next(null, {text});
            });
    }

    ocrapiservice(next) {
        let settings = config.ocrapiservice;
        settings.files = this.file;
        httpClient(settings, (err, res, body) => {
            console.log(body);
            next(err, body);
        });
    }
}<commit_msg>tesseract test<commit_after>import async from 'async';
import log from 'winston';
import tesseract from 'node-tesseract';
import tesseractjs from 'tesseract.js';
import {httpClient} from './http-client.js';
import config from '../config.json';

class OCRExtractor {
    constructor(file) {
        this.file = file;
        this.extracts = {};
    }

    extract(next) {
        console.log('---------- OCR Extraction start');
        async.parallelLimit({
                tesseract: (callback) => {
                    this.tesseract(callback);
                },
                tesseractjs: (callback) => {
                    this.tesseractjs(callback);
                },
                ocrapiservice: (callback) => {
                    this.ocrapiservice(callback);
                }
            },
            4,
            (err, results) => {
                if (err !== null) {
                    log.error(`[OCRExtractor.extract] ${err}`);
                } else {
                    log.info(results);
                }
                next(err, results);
            });
    }

    tesseract(next) {
        if (process.env.OS !== 'Windows_NT') {
            tesseract.process(this.file, function(error, text) {
                log.info('[OCR][tesseract] Result : ');
                if (error !== null) {
                    log.info('[OCR][tesseract] Error :');
                    log.info(error);
                } else {
                    text = text.trim();
                    log.info('[OCR][tesseract] Success :');
                    log.info(text);
                }
                next(null, {text, error});
            }, null, 6);
        } else {
            log.info('[OCR][tesseract] Skyped');
            next(null, {});
        }
    }

    tesseractjs(next) {
        log.info('[OCR][tesseractjs] Result : ');
        tesseractjs.recognize(this.file)
            .catch((err) => {
                log.info('[OCR][tesseractjs] Error :');
                log.error(err);
                next(err, {err});
            })
            .then(function(result) {
                let text = result.text.trim();
                log.info('[OCR][tesseractjs] Success :');
                log.info(text);
                next(null, {text});
            });
    }

    ocrapiservice(next) {
        log.info('[OCR][ocrapiservice] Result : ');
        let settings = config.ocrapiservice;
        settings.files = this.file;
        httpClient(settings, (err, res, body) => {
            if (err !== null) {
                log.info('[OCR][tesseract] Error :');
                log.info(err);
            } else {
                log.info('[OCR][tesseract] Success :');
                log.info(body);
            }
            console.log(body);
            next(err, body);
        });
    }
}
{'fraction_non_alphanumeric': 0.14834639648250814, 'fraction_numerical': 0.0007646721468170522, 'mean_word_length': 1.2797385620915032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1427693', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1501, 'n_words': 248}