Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed support for initialization parameters per #862 (#863)
  • Loading branch information
Balearica committed Dec 24, 2023
1 parent 52bf2e0 commit 5271ae6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/worker-script/index.js
Expand Up @@ -249,9 +249,9 @@ const initialize = async ({
let configStr;
// config argument may either be config file text, or object with key/value pairs
// In the latter case we convert to config file text here
if (typeof config === 'object') {
if (config && typeof config === 'object' && Object.keys(config).length > 0) {
configStr = JSON.stringify(config).replace(/,/g, '\n').replace(/:/g, ' ').replace(/["'{}]/g, '');
} else {
} else if (config && typeof config === 'string') {
configStr = config;
}
if (typeof configStr === 'string') {
Expand All @@ -260,7 +260,7 @@ const initialize = async ({
}

api = new TessModule.TessBaseAPI();
let status = api.Init(null, langs, oem);
let status = api.Init(null, langs, oem, configFile);
if (status === -1) {
// Cache is deleted if initialization fails to avoid keeping bad data in cache
// This assumes that initialization failing only occurs due to bad .traineddata,
Expand Down Expand Up @@ -289,7 +289,7 @@ const initialize = async ({
log('Data from cache missing requested OEM model. Attempting to refresh cache with new language data.');
// In this case, language data is re-loaded
await loadLanguage({ workerId, payload: { langs: loadLanguageLangsWorker, options: loadLanguageOptionsWorker } }); // eslint-disable-line max-len
status = api.Init(null, langs, oem);
status = api.Init(null, langs, oem, configFile);
if (status === -1) {
log('Language data refresh failed.');
const delCachePromise2 = langsArr.map((lang) => adapter.deleteCache(`${loadLanguageOptionsWorker.cachePath || '.'}/${lang}.traineddata`));
Expand Down

0 comments on commit 5271ae6

Please sign in to comment.