edu.cmu.sphinx.tools.tags
Class ActionTagsUtilities

java.lang.Object
  extended byedu.cmu.sphinx.tools.tags.ActionTagsUtilities

public class ActionTagsUtilities
extends java.lang.Object

Utilities for handling ECMAScript embedded in JSGF RuleGrammar tags. These utilities are not dependent upon any particular ECMAScript implementation; they merely provide convenience methods for generating ECMAScript scripts to pass to an ECMAScript implementation.

See Also:
ActionTagsParser

Constructor Summary
ActionTagsUtilities()
           
 
Method Summary
static java.lang.String getClassDefinitions()
          Generate an ECMAScript script that defines the classes and functions referenced by the String returned from the getScript method.
static java.lang.String getParseTree(RuleParse ruleParse)
          A debug utility to determine the flattened parse tree of a RuleParse instance.
static java.lang.String getScript(RuleParse ruleParse)
          Given a RuleParse, generate an executable ECMAScript script based upon the RuleTags in the RuleParse.
static boolean isDebugging()
          Is debug turned on?
static void setDebugging(boolean newDebug)
          Turn debugging on or off.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionTagsUtilities

public ActionTagsUtilities()
Method Detail

setDebugging

public static void setDebugging(boolean newDebug)
Turn debugging on or off. If debugging is turned on, the debug method of the action tags parser will be called each time an action tag is to be evaluated.

See Also:
isDebugging()

isDebugging

public static boolean isDebugging()
Is debug turned on?

See Also:
setDebugging(boolean)

getClassDefinitions

public static java.lang.String getClassDefinitions()
Generate an ECMAScript script that defines the classes and functions referenced by the String returned from the getScript method. This script should be evaluated by the ActionTags parser before evaluating scripts returned from the getScript method. It is a separate method to allow more flexibility in ActionTags parser implementations. For example, some parsers may wish to maintain an ECMAScript context that is persistent between parses of RuleParse instances. In these cases, the parser needs to evaluate the script returned by this method only once. Other parsers may want to generate a new context for each parse of a RuleParse instance. In those cases, the parser will need to evaluate ths script returned by this method each time it handles a new RuleParse instance.

Note that this does not evaluate the script. It is up to the ActionTags parser to do that.

Returns:
a String containing ECMAScript global class and function definitions
See Also:
getScript(javax.speech.recognition.RuleParse)

getScript

public static java.lang.String getScript(RuleParse ruleParse)
Given a RuleParse, generate an executable ECMAScript script based upon the RuleTags in the RuleParse. The ECMAScript script returned uses the definitions from the getClassDefinitions method. As a result, it is important that the script returned from the getClassDefinitions method is evaluated by the action tags parser prior to evaluating the script returned from this method.

Note that this does not evaluate the script. It is up to the action tags parser to do that.

Parameters:
ruleParse - the RuleParse containing RuleTags with embedded ECMAScript
Returns:
a String containing ECMAScript script based upon the RuleTags in ruleParse
See Also:
getClassDefinitions()

getParseTree

public static java.lang.String getParseTree(RuleParse ruleParse)
A debug utility to determine the flattened parse tree of a RuleParse instance. This can be useful for debugging ECMAScript tags in a grammar.

Parameters:
ruleParse - the RuleParse containing RuleTags with embedded ECMAScript
Returns:
a printable String containing the flattened parse tree of a RuleParse instance.