|
JSAPI 2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectRuleComponent
RuleAlternatives
public class RuleAlternatives
Represents a RuleComponent
composed of a set of alternative
RuleComponent
s.
RuleAlternatives
are used to construct RuleGrammar
objects.
A RuleAlternatives
object is spoken by saying one,
and only one, of its alternative RuleComponent
s.
A RuleAlternatives
object contains a set of zero or more
RuleComponent
objects.
A set of zero alternatives is equivalent to VOID
(no matches).
This accommodates the case where a Rule
might contain "call"
followed by a list of names, but the list of names is empty.
With no valid alternatives following "call", the Rule
as a whole
will not match.
Weights may be (optionally) assigned to each alternative
RuleComponent
.
The weights indicate the relative chance of each RuleComponent
being spoken.
If no weights are defined, then all alternatives are considered
equally likely.
Traditional floating point weights may be converted to integer weights
as follows:
multiply by NORM_WEIGHT
and then apply a ceiling of
MAX_WEIGHT
.
VOID
,
NORM_WEIGHT
,
MAX_WEIGHT
Field Summary | |
---|---|
static int |
MAX_WEIGHT
The maximum weight for a RuleComponent . |
static int |
MIN_WEIGHT
A value for the weight corresponding to 0.0. |
static int |
NORM_WEIGHT
A value for the weight corresponding to 1.0. |
Constructor Summary | |
---|---|
RuleAlternatives(RuleComponent[] ruleComponents)
Constructs a RuleAlternatives object from an array of
alternative RuleComponent s. |
|
RuleAlternatives(RuleComponent[] ruleComponents,
int[] weights)
Constructs a RuleAlternatives object with an array of
alternative ruleComponents and a corresponding array
of weights . |
|
RuleAlternatives(String[] tokens)
Constructs a phrase list from an array of String objects. |
Method Summary | |
---|---|
RuleComponent[] |
getRuleComponents()
Returns the array of alternative RuleComponent s. |
int[] |
getWeights()
Returns weights for the corresponding alternative RuleComponent s. |
String |
toString()
Returns a String representing this RuleComponent
as grammar text. |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAX_WEIGHT
RuleComponent
.
RuleAlternatives(RuleComponent[], int[])
,
Constant Field Valuespublic static final int MIN_WEIGHT
RuleAlternatives(RuleComponent[], int[])
,
Constant Field Valuespublic static final int NORM_WEIGHT
RuleAlternatives(RuleComponent[], int[])
,
Constant Field ValuesConstructor Detail |
---|
public RuleAlternatives(String[] tokens)
String
objects.
Each String
is used to create a single RuleToken
object
as an alternative.
A String
containing multiple words (e.g. "San Francisco")
is treated as a single token in a RuleToken
.
If appropriate, an application should parse a phrase alternative
into separate RuleToken
s to create a corresponding
RuleSequence
alternative.
All alternatives have equal weight.
A zero-length tokens
list
results in a zero-length array of alternative RuleComponent
s
that is equivalent to VOID
(no matches).
tokens
- a set of alternative tokens
IllegalArgumentException
- if null
tokens
RuleToken
,
RuleSequence
,
VOID
,
getRuleComponents
,
getWeights
public RuleAlternatives(RuleComponent[] ruleComponents) throws IllegalArgumentException
RuleAlternatives
object from an array of
alternative RuleComponent
s.
All alternative have equal weight.
A zero-length set of alternatives is equivalent to
VOID
(no matches).
ruleComponents
- the set of alternative RuleComponent
s
IllegalArgumentException
- if null
ruleComponents
VOID
,
getRuleComponents
,
getWeights
public RuleAlternatives(RuleComponent[] ruleComponents, int[] weights) throws IllegalArgumentException
RuleAlternatives
object with an array of
alternative ruleComponents
and a corresponding array
of weights
.
The ruleComponents
array must not be null
.
A zero-length set of alternatives is equivalent to
VOID
(no matches).
If the weights
array is non-null
,
it must have identical length to the ruleComponents
array.
If the weights
array is null
,
all alternative ruleComponents
have equal weight.
Weights specified must all be greater than or equal to MIN_WEIGHT
and less than or equal to MAX_WEIGHT
.
At least one must be non-zero.
ruleComponents
- the set of alternative RuleComponent
sweights
- the weight of each RuleComponent
or null
IllegalArgumentException
- if null
ruleComponents
,
mismatched array lengths, or bad weight valuesMIN_WEIGHT
,
NORM_WEIGHT
,
MAX_WEIGHT
,
VOID
,
getRuleComponents
,
getWeights
Method Detail |
---|
public RuleComponent[] getRuleComponents()
RuleComponent
s.
A zero-length array is treated the same as VOID
(no matches).
RuleComponent
s.getWeights
,
VOID
public int[] getWeights()
RuleComponent
s.
A null
value is returned if the weights were not
originally specified.
This represents alternatives with equal weight.
Otherwise, the length of the weights array is
guaranteed to be the same length as the array of RuleComponent
s.
null
if not specifiedgetRuleComponents
public String toString()
String
representing this RuleComponent
as grammar text.
The String
represents a portion of a grammar that could appear
on the right hand side of a Rule
definition.
Note that an empty alternative list is represented as VOID
.
toString
in class RuleComponent
String
representing grammar text.VOID
,
RuleComponent
,
Rule
|
JSAPI 2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaTM Speech API 2.0,
Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.