Class: SemanticInterpreter

mmir. SemanticInterpreter

new mmir.SemanticInterpreter()

Requires

  • module:require

Classes

setToCompatibilityModeExtension

Methods

createGrammar(rawGrammarSrc, id, callback){SemanticInterpreter.prototype}

Name Type Description
rawGrammarSrc String | JSONObject
id String
callback function optional

getFileVersion(){Number}

Returns:
current version number that this SemanticInterpreter instance supports, for the file format of compiled grammars.
Name Type Description
id String

getGrammarDefinitionText()

NOTE: the grammar must be compiled first, see getNewInstance(true) @public
Get the ID of the current grammar engine / compiler.
Default Value:
  • "jcss"
Returns:
ID of the current grammar engine

getGrammarParserText()

NOTE: the grammar must be compiled first, see getNewInstance(true) @public

interpret(phrase, langCode, callback){Object}

Name Type Description
phrase String the phrase that will be parsed
langCode String the language code (identifier) for the parser/grammar
callback function optional OPTIONAL a callback function that receives the return value (instead of receiving the result as return value from this function directly). The signature for the callback is: callback(result: Object) (i.e. the result that would be returned by this function itself is passed as argument into the callback function; see also documentation for returns). NOTE: in case, the grammar for the requested langCode is not compiled yet (i.e. not present as executable JavaScript), the corresponding JSON definition of the grammar needs to be compiled first, before processing the ASR's semantics is possible. In this case, a callback function MUST be supplied in order to receive a result (since compilation of the grammar may be asynchronous).
Returns:
parsing result (as processed by the parser / grammar; usually a JSON-like object). WARNING: if a callback function was provided, then there is no return object.

removeStopwords(thePhrase, lang)

Removes stopwords using the stopword-list from the parser/grammar for lang. NOTE: interpret automatically applies stopword-removal (i.e. there is no need to manually remove stopwords using this function when using interpret).
Name Type Description
thePhrase String the Phrase for which stopwords should be removed
lang String the language code (identifier) for the parser/grammar

setCurrentGrammar(id)

Sets the current grammar. If in invocations of interpret the grammar ID (e.g. language code) is missing, then this grammar that is set here is used. The id must reference either a grammar that was compiled (i.e. generated JavaScript file) for this id, or there must exists JSON-grammar file for which the language-dir matches the id parameter, e.g. config/languages/[id]/grammar.json.
Name Type Description
id String the ID for the grammar, e.g. an ISO language code

setEngineCompileMode(asyncCompileMode)

Set compile-mode (sychronous or asynchronous) for the grammar engine, i.e. if the compiler engine for the JSON grammar should run synchronously or asynchronously. NOTE: if there is no asynchronous implementation available for the grammar engine, the sync-impl. is used by default. NOTE: asynchronous compile mode requires WebWorkers
Name Type Description
asyncCompileMode Boolean sets the compile mode (sychronous or asynchronous) when generating new parsers with the grammar-engine.
Default Value:
  • false (i.e. synchronous compile mode)

setGrammarEngine(egnineId, asyncCompileMode)

Set the grammar engine, i.e. the compiler engine for the JSON grammar NOTE: implementations of the grammar engines are located at env/grammar/ The file-name for an implementation should follow the convention: ID+"Generator.js" and should be registered with requirejs with the module-ID: ID+"Gen"
Name Type Description
egnineId String the ID for the engine. Possible values: "jscc", "jison", "pegjs"
asyncCompileMode Boolean optional OPITIONAL sets the compile mode (sychronous or asynchronous) when generating new parsers with the grammar-engine. DEFAULT: VOID (i.e. leave current set compile-mode setting unchanged)