mmir.grammar.AsyncGrammar
loads the default grammar asynchronously using a WebWorker
NOTE usage of the grammar is also async:
calls on
interpret(text, callback) are re-directed to the WebWorker
Methods
-
destroy(force)
-
destroy / terminate the WebWorker for async grammar execution NOTE: can be re-initialized using
mmir.grammar.AsyncGrammar#initName Type Description forceBoolean optional OPTIONAL if true, will force termination of WebWorker, otherwise waits for pending commands to finish. -
init(langCode, listener, phrase, grammarCode){Boolean}
-
Initialize a grammar to be loaded & executed asynchronously
Name Type Description langCodeString the grammar's ID listenerfunction the callback that is triggered when the grammar has been initialized: listener(initializationResult)
phraseString optional a phrase that should be immediately interpreted, after grammar has been loaded (for large grammars, this may reduce delays for subsequent calls, by fully initializing the grammar) grammarCodeString optional for injecting JavaScript grammar code into the WebWorker: instead of loading the compiled grammar (for large grammars, this may reduce delays for subsequent calls, by fully initializing the grammar) for langCode, willeval()thegrammarCodewithin the WebWorker ThegrammarCodecorrsponds to fieldmmir.grammar.GrammarConverter.js_grammar_definition, after grammar was compiled.
NOTE this argument is positional! If nophraseshould be use, it needs to be specified asundefined, e.g.asyncGrammar.init('myGrammar', onInitCallback, void(0), compiledGrammarCode)Returns:
Type Description Boolean trueif initialization has started, iffalseinitialization could not be started, due to errors or missing/invalid arguments -
isDestroyed(){Boolean}
-
check, if async-grammar worker has been destroyed
Returns:
Type Description Boolean true, if async-grammar worker has been destroyed, otherwise false -
isInit(grammarId){Boolean}
-
check, if grammar has been (or currently is in the process of beeing) intialized for async execution
Name Type Description grammarIdString the grammar ID to check - See:
Returns:
Type Description Boolean true, if grammar has been initialized for async-execution