Class: AsyncGrammar

AsyncGrammar

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 / terminate the WebWorker for async grammar execution NOTE: can be re-initialized using mmir.grammar.AsyncGrammar#init
Name Type Description
force Boolean 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
langCode String the grammar's ID
listener function the callback that is triggered when the grammar has been initialized:
listener(initializationResult)
phrase String 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)
grammarCode String 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, will eval() the grammarCode within the WebWorker The grammarCode corrsponds to field mmir.grammar.GrammarConverter.js_grammar_definition, after grammar was compiled.
NOTE this argument is positional! If no phrase should be use, it needs to be specified as undefined, e.g.
asyncGrammar.init('myGrammar', onInitCallback, void(0), compiledGrammarCode)
Returns:
Type Description
Boolean true if initialization has started, if false initialization could not be started, due to errors or missing/invalid arguments
check, if async-grammar worker has been destroyed
See:
Returns:
Type Description
Boolean true, if async-grammar worker has been destroyed, otherwise false
check, if grammar has been (or currently is in the process of beeing) intialized for async execution
Name Type Description
grammarId String the grammar ID to check
See:
Returns:
Type Description
Boolean true, if grammar has been initialized for async-execution