Overview | Package | Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
RuleGrammar
. A finalized result is one that is in
either the ACCEPTED
or REJECTED
state
(tested by the getResultState
method of the
Result
interface).
This interface provides the following information for
a finalized result for a RuleGrammar
(in addition
to the information provided through the Result
and
FinalResult
interfaces):
Every Result
object provided by a Recognizer
implements the FinalRuleResult
and the
FinalDictationResult
interfaces (and by inheritence the
FinalResult
and Result
interfaces).
However, the methods of FinalRuleResult
should only be called if the Result.getGrammar
method returns a RuleGrammar
and once the
Result
has been finalized with either an
RESULT_ACCEPTED
or RESULT_REJECTED
event.
Inappropriate calls will cause a ResultStateError
.
Method Summary | |
ResultToken[] | getAlternativeTokens(int nBest)
Get the N-best token sequence for this result. |
int | getNumberGuesses()
Return the number of guesses for this result. |
RuleGrammar | getRuleGrammar(int nBest)
Return the RuleGrammar matched by the nth guess.
|
String | getRuleName(int nBest)
Return the RuleName matched by the nth guess.
|
String[] | getTags()
Return the list of tags matched by the best-guess token sequence. |
Method Detail |
public int getNumberGuesses() throws ResultStateError
getBestTokens
method of the Result
interface.
If only the best guess is available (no alternatives) the return
value is 1. If the result is was rejected (REJECTED
state), the return value may be 0 if no tokens are available.
If a best guess plus alternatives are available, the return value
is greater than 1.
The integer parameter to the getAlternativeTokens
,
getRuleGrammar
and getRuleName
methods
are indexed from 0
to (getNumberGuesses()-1)
.
public ResultToken[] getAlternativeTokens(int nBest) throws ResultStateError
nBest
value should be in the range of 0
to
(getNumberGuesses()-1)
inclusive. For out-of-range
values, the method returns null
.
If nBest==0
, the method returns the best-guess sequence
of tokens - identical to the token sequence returned by the
getBestTokens
method of the Result
interface
for the same object.
If nBest==1
(or 2, 3...) the method returns the 1st (2nd, 3rd...)
alternative to the best guess.
The number of tokens for the best guess and the alternatives do not need to be the same.
The getRuleGrammar(int)
and getRuleName(int)
methods indicate which RuleGrammar
and ruleName
are matched by each alternative result sequence.
If the Result
is in the ACCEPTED
state (not rejected),
then the best guess and all the alternatives are accepted. Moreover,
each alternative set of tokens must be a legal match of the
RuleGrammar
and RuleName
returned by
the getRuleGrammar
and getRuleName
methods.
If the Result
is in the REJECTED
state (not accepted),
the recognizer is not confident that the best guess or any of the
alternatives are what the user said. Rejected guesses do not need
to match the corresponding RuleGrammar
and rule name.
Example
Say we have two simple grammars loaded and active for recognition.
The first is grammar.numbers
with a public rule
digits
that matches spoken digit sequences
(e.g. "1 2 3 4"). The grammar is grammar.food
with the rule whoAteWhat
which matches statements about eating (e.g. "he ate mine").
[Yes, this is artificial!]
The user says "two eight nine" and the recognizer correctly recognizes the speech, but also provides 2 alternatives. The
FinalRuleResult result = ...; result.getNumberGuesses() -> 3 result.getAlternativeTokens(0) -> two eight nine // array of tokens result.getRuleGrammar(0) -> [reference togrammar.numbers
] result.getRuleName(0) -> "digits" result.getAlternativeTokens(1) -> you ate mine result.getRuleGrammar(1) -> [reference togrammar.food
] result.getRuleName(1) -> "whoAteWhat" result.getAlternativeTokens(2) -> two eight five result.getRuleGrammar(2) -> [reference togrammar.numbers
] result.getRuleName(2) -> "digits"
public RuleGrammar getRuleGrammar(int nBest) throws ResultStateError
RuleGrammar
matched by the nth guess.
Return null
if nBest
is out-of-range.
getRuleName
returns the rule matched in the
RuleGrammar
. See the documentation for
getAlternativeTokens
for a description of how
tokens, grammars and rules correspond.
An application can use the parse method of the matched grammar to analyse a result. e.g.
int nBest = 2; FinalRuleResult res; RuleParse parse = res.getRuleGrammar(nbest).parse( res.getAlternativeTokens(nBest), res.getRuleName(nBest));
public String getRuleName(int nBest) throws ResultStateError
RuleName
matched by the nth guess.
Return null
if nBest
is out-of-range.
Typically used in combination with getAlternativeTokens
and getRuleGrammar
which return the corresponding
tokens and grammar.
The documentation for getAlternativeTokens
shows
and example result with alternatives.
public String[] getTags() throws ResultStateError
For example, if the following simple Java Speech Grammar Format (JSGF) rule is active:
publicand the user says "close it now", then getTags returns an array containing= (open {ACT_OPEN} | close {ACT_CLOSE}) [(it{WHAT} now) {NOW}];
{"ACT_CLOSE", "WHAT", "NOW"}
.
Note how both the {WHAT}
and {NOW}
tags
are attached starting from the word "it" but that {TAG}
appears first in the array. In effect, when tags start at the
same token, they are listed "bottom-up".
getTags
does not indicate which tokens are matched by
which tags. To obtain this information use the parse
method of the RuleGrammar
. Also, getTags
only provides tags for the best guess. To get tags for the
alternative guesses using parsing through the RuleGrammar
.
The string array returned by the getTags
method of the
RuleParse
object returned by parsing the best-guess
token sequence will be the same as returned by this method.
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