Added warning message when trying to set init-only params per #808 (#816)

master
Balearica 1 year ago committed by GitHub
parent 79cacaab95
commit bb973ea2b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      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) => {

Loading…
Cancel
Save