From bb973ea2b8175c69e7ab4df587244f970dcbbb8a Mon Sep 17 00:00:00 2001 From: Balearica Date: Sun, 27 Aug 2023 20:45:32 -0700 Subject: [PATCH] Added warning message when trying to set init-only params per #808 (#816) --- src/worker-script/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/worker-script/index.js b/src/worker-script/index.js index c251cb390..d5c3c672a 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -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) => {