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.RuleParse

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

public class RuleParse
extends Rule
Represents the output of a parse of a 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.

[Note: the 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.)

See Also:
Rule, RuleAlternatives, RuleCount, RuleGrammar, parse, RuleName, RuleSequence, RuleTag, RuleToken, Serialized Form

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

ruleName

protected RuleName ruleName
The RuleName matched by the parse structure.

See Also:
getRuleName

rule

protected Rule rule
The Rule structure matching the RuleName.

See Also:
getRule
Constructor Detail

RuleParse

public RuleParse(RuleName ruleName,
                 Rule rule)
Construct a 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.

RuleParse

public RuleParse()
Empty constructor for RuleParse object with rulename and rule set to null.
Method Detail

getRuleName

public RuleName getRuleName()
Return the matched RuleName. Should be a fully-qualified rulename.

setRuleName

public void setRuleName(RuleName ruleName)
Set the matched RuleName. Should be a fully-qualified rulename.

getRule

public Rule getRule()
Return the Rule matched by the RuleName.

setRule

public void setRule(Rule rule)
Set the Rule object matched to the RuleName.

getTags

public String[] getTags()
List the tags matched in this parse structure. Tags are listed in the order of tokens (from start to end) and from the lowest to highest attachment. (See the FinalRuleResult.getTags method for an example.)

See Also:
getTags

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()
Convert a RuleParse to a string with a similar style to the Java Speech Grammar Format. For example,
     "(<command> = (<verb> = open) this)"
 
Notes:
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