Overview | Package | Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.speech.recognition.Rule | +--javax.speech.recognition.RuleParse
Result
or a string against a RuleGrammar
. The RuleParse
object indicates how the result or text matches to the rules of the
RuleGrammar
and the rules imported by that grammar.
The RuleParse
structure returned by parsing closely matches
the structure of the grammar it is parsed against: if the grammar
contains RuleTag
, RuleSequence
, RuleToken
objects and so on, the returned RuleParse
will contain paired objects.
The RuleParse
object itself represents the match of text to
a named rule or to any rule referenced within a rule. The rulename field
of the RuleParse
is the fully-qualified name of the
rule being matched. The Rule
field of the RuleParse
represents the parse structure (how that rulename is matched).
The expansion (or logical structure) of a RuleParse
matches
the structure of the definition of the rule being parsed. The following
indicates the mapping of an entity in the rule being parsed to the
paired object in the RuleParse
.
RuleAlternatives
:
maps to a RuleAlternatives
object containing a
single Rule
object for the one entity in the
set of alternatives that is matched.
RuleCount
: maps to a RuleSequence
containing a Rule
for each match of the rule
contained by RuleCount
. The sequence may contain
zero, one or multiple rule matches (for optional, zero-or-more
or one-or-more operators).
RuleName
: maps to a RuleParse
indicating how the referenced rule was matched. The rulename
field of the RuleParse
is the matched RuleName
.
The exception for NULL
is described below.
RuleSequence
: maps to a RuleSequence
with
a matching rule for each rule in the original sequence.
RuleTag
: maps to a matching RuleTag
(same tag) with a match of the contained rule.
RuleToken
: maps to an identical RuleToken
object.
RuleParse
object is never used in defining
a RuleGrammar
so it doesn't need to be matched.]
If a RuleName
object in a grammar is <NULL>
,
then the RuleParse
contains the <NULL>
object too.
Example
Consider a simple grammar:
public <command> = <action> <object> [<polite>] <action> = open {OP} | close {CL} | move {MV}; <object> = [<this_that_etc>] (window | door); <this_that_etc> = a | the | this | that | the current; <polite> = please | kindly;
We will analyze the parse of "close that door please"
against
<command>
rule which is returned by the parse
method of the RuleGrammar
against the <command>
rule:
ruleParse = ruleGrammar.parse("close that door please", "command");The call returns a
RuleParse
that is the match of
"close that door please" against <command>
.
Because <command>
is defined as a sequence of
3 entities (action, object and optional polite), the RuleParse
will contain a RuleSequence
with length 3.
The first two entities in <command>
are
RuleNames
, so the first two entities in the parse's
RuleSequence
will be RuleParse
objects with
rulenames of "action" and "object".
The third entity in <command>
is an optional
RuleName
(a RuleCount
containing
a RuleName
), so the third entity in the sequence is a
RuleSequence
containing a single RuleParse
indicating how the <polite>
rule is matched.
(Recall that a RuleCount
object maps to a RuleSequence
).
The RuleParse
for <polite>
will contain a
RuleAlternatives
object with the single entry which is a
RuleToken
set to "please". Skipping the rest of the structure,
the entire RuleParse
object has the following structure.
RuleParse(<command> = // Match <command> RuleSequence( // by a sequence of 3 entities RuleParse(<action> = // First match <action> RuleAlternatives( // One of a set of alternatives RuleTag( // matching the tagged RuleToken("close"), "CL"))) // token "close" RuleParse(<object> = // Now match <object> RuleSequence( // by a sequence of 2 entities RuleSequence( // RuleCount becomes RuleSequence RuleParse(<this_that_etc> = // Match <this_that_etc> RuleAlternatives( // One of a set of alternatives RuleToken("that")))) // is the token "that" RuleAlternatives( // Match "window | door" RuleToken("door")))) // as the token "door" RuleSequence( // RuleCount becomes RuleSequence RuleParse(<polite> = // Now match <polite> RuleAlternatives( // by 1 of 2 alternatives RuleToken("please")))) // The token "please" ) )(Parse structures are hard to read and understand but can be easily processed by recursive method calls.)
Field Summary | |
RuleName | ruleName
The RuleName matched by the parse structure.
|
Rule | rule
The Rule structure matching the RuleName .
|
Constructor Summary | |
RuleParse(RuleName ruleName,
Rule rule)
Construct a RuleParse object for a named rule and
a Rule object that represents the parse structure.
|
|
RuleParse()
Empty constructor for RuleParse object with
rulename and rule set to null . |
Method Summary | |
Rule | copy()
Return a deep copy of this rule. |
RuleName | getRuleName()
Return the matched RuleName .
|
Rule | getRule()
Return the Rule matched by the RuleName . |
String[] | getTags()
List the tags matched in this parse structure. |
void | setRuleName(RuleName ruleName)
Set the matched RuleName .
|
void | setRule(Rule rule)
Set the Rule object matched to the RuleName . |
String | toString()
Convert a RuleParse to a string with a similar style
to the 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 |
protected RuleName ruleName
RuleName
matched by the parse structure.
protected Rule rule
Rule
structure matching the RuleName
.
Constructor Detail |
public RuleParse(RuleName ruleName, Rule rule)
RuleParse
object for a named rule and
a Rule
object that represents the parse structure.
The structure of the rule object is described above.
The rulename should be a fully-qualified name.public RuleParse()
RuleParse
object with
rulename and rule set to null
.Method Detail |
public RuleName getRuleName()
RuleName
.
Should be a fully-qualified rulename.public void setRuleName(RuleName ruleName)
RuleName
.
Should be a fully-qualified rulename.public Rule getRule()
Rule
matched by the RuleName
.public void setRule(Rule rule)
Rule
object matched to the RuleName
.public String[] getTags()
FinalRuleResult.getTags
method for an example.)
public Rule copy()
Rule.copy
documentation for an explanation of deep copy.public String toString()
RuleParse
to a string with a similar style
to the Java Speech Grammar Format.
For example,
"(<command> = (<verb> = open) this)"Notes:
RuleCount
object. This is printed as <NULL>
.
RuleAlternatives
is parsed to a RuleAlternatives
containing only one entry. There is no explicit representation of this
form in JSGF so RuleAlternatives
structure is lost when printed.
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