JSAPI 2.0

javax.speech.recognition
Class Rule

Object
  extended by Rule

public class Rule
extends Object

Represents a Rule in a RuleGrammar. Each Rule in a RuleGrammar defines a named grammar rule in terms of RuleComponents.

In traditional grammar terminology, the name of the Rule represents the left-hand side (LHS) and the RuleComponent expansion represents the right-hand side (RHS). The RuleGrammar class defines how to create and use a Grammar with Rules.

At least one Rule within a RuleGrammar must have PUBLIC scope to allow external reference with a Rule name. Otherwise, a single root Rule must be defined in the associated RuleGrammar (see createRuleGrammar).

See Also:
Grammar, RuleGrammar, createRuleGrammar

Field Summary
static int PRIVATE
          A constant that specifies private scope for a Rule.
static int PUBLIC
          A constant that specifies public scope for a Rule.
 
Constructor Summary
Rule(String ruleName, RuleComponent ruleComponent)
          Constructs a Rule with a name and RuleComponent expansion.
Rule(String ruleName, RuleComponent ruleComponent, int scope)
          Constructs a Rule with a name, RuleComponent expansion, and scope.
 
Method Summary
 RuleComponent getRuleComponent()
          Gets the RuleComponent expansion of this Rule.
 String getRuleName()
          Gets the name of this Rule.
 int getScope()
          Gets the scope of this Rule.
 String toString()
          Returns a String representing this Rule as grammar text.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PUBLIC

public static final int PUBLIC
A constant that specifies public scope for a Rule.

See Also:
PRIVATE, getScope, Rule, Constant Field Values

PRIVATE

public static final int PRIVATE
A constant that specifies private scope for a Rule.

See Also:
PUBLIC, getScope, Rule, Constant Field Values
Constructor Detail

Rule

public Rule(String ruleName,
            RuleComponent ruleComponent)
     throws IllegalArgumentException
Constructs a Rule with a name and RuleComponent expansion. The Rule uses the default PRIVATE scope.

Parameters:
ruleName - the name of this Rule
ruleComponent - the expansion for this Rule
Throws:
IllegalArgumentException - if ruleName is not valid grammar text or ruleComponent is null
See Also:
getRuleName, getRuleComponent, getScope

Rule

public Rule(String ruleName,
            RuleComponent ruleComponent,
            int scope)
     throws IllegalArgumentException
Constructs a Rule with a name, RuleComponent expansion, and scope. The scope is either PUBLIC or PRIVATE.

PUBLIC scope Rules may be referenced by other Rules both locally within the same RuleGrammar and externally by other RuleGrammars. PRIVATE scope Rules may only be referenced locally by name within the RuleGrammar. Rules are referenced with RuleReferences.

Parameters:
ruleName - the name of this Rule
ruleComponent - the expansion for this Rule
scope - the scope of this Rule
Throws:
IllegalArgumentException - if ruleName is not valid grammar text, ruleComponent is null, or if scope is invalid
See Also:
getRuleName, getRuleComponent, getScope, RuleGrammar, RuleReference
Method Detail

getRuleName

public String getRuleName()
Gets the name of this Rule. The name is used to identify this Rule.

Returns:
the name of this Rule

getRuleComponent

public RuleComponent getRuleComponent()
Gets the RuleComponent expansion of this Rule. The expansion defines how this Rule matches speech.

Returns:
the RuleComponent expansion

getScope

public int getScope()
Gets the scope of this Rule. The scope is either PUBLIC or PRIVATE. It is specified in the Rule constructor.

Returns:
the scope value
See Also:
PUBLIC, PRIVATE, Rule(String, RuleComponent, int)

toString

public String toString()
Returns a String representing this Rule as grammar text. The String represents a portion of a RuleGrammar defined by a Rule name and associated RuleComponent expansion.

Overrides:
toString in class Object
Returns:
printable String representing grammar text.
See Also:
getRuleName, getRuleComponent

JSAPI 2.0

JavaTM Speech API 2.0, Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.

Free Web Hosting