Skip to content

Commit

Permalink
Added warning message when trying to set init-only params per #808 (#816
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Balearica authored Aug 28, 2023
1 parent 79cacaa commit bb973ea
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/worker-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ res) => {
};

const setParameters = async ({ payload: { params: _params } }, res) => {
// A small number of parameters can only be set at initialization.
// These can only be set using (1) the `oem` argument of `initialize` (for setting the oem)
// or (2) the `config` argument of `initialize` (for all other settings).
// Attempting to set these using this function will have no impact so a warning is printed.
// This list is generated by searching the Tesseract codebase for parameters
// defined with `[type]_INIT_MEMBER` rather than `[type]_MEMBER`.
const initParamNames = ['ambigs_debug_level', 'user_words_suffix', 'user_patterns_suffix', 'user_patterns_suffix',
'load_system_dawg', 'load_freq_dawg', 'load_unambig_dawg', 'load_punc_dawg', 'load_number_dawg', 'load_bigram_dawg',
'tessedit_ocr_engine_mode', 'tessedit_init_config_only', 'language_model_ngram_on', 'language_model_use_sigmoidal_certainty'];

const initParamStr = Object.keys(_params)
.filter((k) => initParamNames.includes(k))
.join(', ');

if (initParamStr.length > 0) console.log(`Attempted to set parameters that can only be set during initialization: ${initParamStr}`);

Object.keys(_params)
.filter((k) => !k.startsWith('tessjs_'))
.forEach((key) => {
Expand Down

0 comments on commit bb973ea

Please sign in to comment.