Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class javax.speech.recognition.RuleAlternatives

java.lang.Object
  |
  +--javax.speech.recognition.Rule
        |
        +--javax.speech.recognition.RuleAlternatives

public class RuleAlternatives
extends Rule
RuleAlternatives represents a Rule composed of a set of alternative sub-rules. RuleAlternatives are used to construct RuleGrammar objects. A RuleAlternatives object is spoken by saying one, and only one, of of its sub-rules.

A RuleAlternatives object contains a set of zero or more Rule objects. A set of zero alternatives is equivalent to <VOID> (it is unspeakable).

Weights may be (optionally) assigned to each alternative rule. The weights indicate the chance of each Rule being spoken. The setWeights method defines the constraints upon weights. If no weights are defined, then all alternatives are considered equally likely.

See Also:
Rule, RuleCount, RuleGrammar, RuleName, RuleParse, RuleSequence, RuleTag, RuleToken, VOID, Serialized Form

Field Summary
Rule[] rules
          Set of alternative Rule objects.
float[] weights
          Array of weights for each alternative Rule or null if the rules are equally likely.
 
Constructor Summary
RuleAlternatives(Rule[] rules, float[] weights)
          Construct a RuleAlternatives object with an array of sub-rules and an array of weights.
RuleAlternatives(Rule[] rules)
          Construct a RuleAlternatives object with an array of sub-rules.
RuleAlternatives(Rule rule)
          Construct a RuleAlternatives object containing a single sub-rule.
RuleAlternatives()
          Empty constructor creates zero-length list of alternatives.
RuleAlternatives(String[] tokens)
          Constructor for RuleAlternatives that produces a phrase list from an array of String objects.
 
Method Summary
void append(Rule rule)
          Append a single rule to the set of alternatives.
Rule copy()
          Return a deep copy of this rule.
Rule[] getRules()
          Return the array of alternative sub-rules.
float[] getWeights()
          Return the array of weights.
void setRules(Rule[] rules)
          Set the array of alternative sub-rules.
void setWeights(float[] weights)
          Set the array of weights for the rules.
String toString()
          Return a String representing this object as partial Java Speech Grammar Format.
 
Methods inherited from class javax.speech.recognition.Rule
copy, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

rules

protected Rule[] rules
Set of alternative Rule objects.

weights

protected float[] weights
Array of weights for each alternative Rule or null if the rules are equally likely. If non-null, the weights array must have an identical length to the rules array.
Constructor Detail

RuleAlternatives

public RuleAlternatives(Rule[] rules,
                        float[] weights)
                 throws IllegalArgumentException
Construct a RuleAlternatives object with an array of sub-rules and an array of weights. The rules array and weights array may be null. If the weights array is non-null, it must have identical length to the rules array.
Parameters:
rules - the set of alternative sub-rules
set - of weights for each rule or null
Throws:
IllegalArgumentException - Error in length of array, or the weight values (see setWeights).
See Also:
setWeights

RuleAlternatives

public RuleAlternatives(Rule[] rules)
Construct a RuleAlternatives object with an array of sub-rules. The weights are set to null.

Parameters:
rules - the set of alternative sub-rules

RuleAlternatives

public RuleAlternatives(Rule rule)
Construct a RuleAlternatives object containing a single sub-rule. The weights array is set to null.

RuleAlternatives

public RuleAlternatives()
Empty constructor creates zero-length list of alternatives. Use the setRules method or append method to add alternatives.

A zero-length set of alternatives is equivalent to <VOID> (i.e. unspeakable).


RuleAlternatives

public RuleAlternatives(String[] tokens)
Constructor for RuleAlternatives that produces a phrase list from an array of String objects. Each string is used to create a single RuleToken object.

A string containing multiple words (e.g. "san francisco") is treated as a single token. If appropriate, an application should parse such strings to produce separate tokens.

The phrase list may be zero-length or null. This will produce an empty set of alternatives which is equivalent to <VOID> (i.e. unspeakable).

Parameters:
tokens - a set of alternative tokens
See Also:
VOID
Method Detail

getRules

public Rule[] getRules()
Return the array of alternative sub-rules.

setRules

public void setRules(Rule[] rules)
Set the array of alternative sub-rules.

If the weights are non-null and the number of rules is not equal to the number of weights, the weights are set to null. To change the number of rules and weights, call setRules before setWeights.

See Also:
setWeights

append

public void append(Rule rule)
Append a single rule to the set of alternatives. The weights are set to null.

getWeights

public float[] getWeights()
Return the array of weights. May return null. If non-null, the length of the weights array is guaranteed to be the same length as the array of rules.

setWeights

public void setWeights(float[] weights)
               throws IllegalArgumentException
Set the array of weights for the rules. The weights array may be null. If the weights are null, then all alternatives are assumed to be equally likely.

The length of the weights array must be the same length as the array of rules. The weights must all be greater than or equal to 0.0 and at least one must be non-zero.

To change the number of rules and weights, first call setRules.

Throws:
IllegalArgumentException - Error in length of array or value of weights
See Also:
setRules

copy

public Rule copy()
Return a deep copy of this rule. See the Rule.copy documentation for an explanation of deep copy.
Overrides:
copy in class Rule

toString

public String toString()
Return a String representing this object as partial Java Speech Grammar Format. The string is a legal right hand side of a rule definition.
Overrides:
toString in class Rule

Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

JavaTM Speech API
Copyright 1997-1998 Sun Microsystems, Inc. All rights reserved
Send comments to javaspeech-comments@sun.com