Partilhar via


Manipulating Elements in Rule Editor

  Microsoft Speech Technologies Homepage

Rule Editor is the canvas on which grammar authors design grammar logic. Drag the elements from the Grammar Toolbox onto Rule Editor to represent their corresponding grammar XML markup elements.

  • Adding Elements
  • Adding Child Elements
  • Adding Sibling Elements
  • Manipulating Groups and Lists
  • Manipulating Rules

Adding Elements

Add elements to a rule on Rule Editor using the following procedures. When adding elements by dragging from the Toolbox, the mouse pointer displays a boxed plus sign (+) at the locations on the Rule Editor where it is possible to insert the element.

To add an element to a rule using the Grammar Toolbox

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. From the Visual Studio .NET 2003 Toolbox, click the Grammar tab to display the Grammar Toolbox.
  3. From the Grammar Toolbox, select an element, and drag it onto Rule Editor.

To add an element to a rule using the shortcut menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.

  2. Right-click Rule Editor, on the shortcut menu point to Set Insertion Element Type, and then click the type of element to insert.

  3. Right-click the element relative to which the new element is to be inserted, and on the shortcut menu, click Append Sibling Element, Insert Sibling Element, Add Child Element, or Insert Child Element to insert the new element.

    Note  Add Child Element and Insert Child Element are available only when adding child elements to Group or List elements.

To add an element to a rule using the keyboard

  1. Press ALT+F6 until Grammar Explorer has the focus, press the UP or DOWN arrow keys until the desired rule is selected, and then press ENTER a rule to open Rule Editor.

  2. Press ALT+F6 until Rule Editor has the focus.

  3. Press the appropriate keyboard shortcut to specify the type of element to insert.

  4. Press the appropriate keyboard shortcut to insert the new element.

    Note  Add Child Element and Insert Child Element are available only when adding child elements to Group or List elements.

To add an element to a rule using the Grammar menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.

  2. On the Grammar menu, point to Set Insertion Element Type, and then click the type of element to insert.

  3. On the Grammar menu, click Append Sibling Element, Insert Sibling Element, Add Child Element, or Insert Child Element to insert the new element.

    Note  Add Child Element and Insert Child Element are available only when adding child elements to Group or List elements.

Adding Child Elements

Parent Group or List elements contain child elements. There are no limitations on which element types can be child elements. Typically, Phrase elements are used for child elements; however, Group or List elements can also be used for child elements.

To add child elements using the Grammar Toolbox

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. From the Visual Studio .NET 2003 Toolbox, click the Grammar tab to display the Grammar Toolbox.
  3. From the Grammar Toolbox, select an element, drag it onto Rule Editor, and place it below the parent element.

To add child elements using the shortcut menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. Right-click Rule Editor, on the shortcut menu point to Set Insertion Element Type, and then click the type of child element to insert.
  3. Right-click the element to add the new child element to, and on the shortcut menu, do one of the following.
    • Click Add Child Element to insert a child element below the most recently inserted element.
    • Click Insert Child Element to insert a child element before the most recently inserted element.

To add child elements using the Grammar menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. On Rule Editor, click the element to add the new child element to.
  3. On the Grammar menu, point to Set Insertion Element Type, and then click the type of child element to insert.
  4. On the Grammar menu, do one of the following.
    • Click Add Child Element to insert a child element below the most recently inserted element.
    • Click Insert Child Element to insert a child element before the most recently inserted element.

Adding Sibling Elements

Insert sibling elements before or after another element at the same level in the display hierarchy.

To add sibling elements using the Grammar Toolbox

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. From the Visual Studio .NET 2003 Toolbox, click the Grammar tab to display the Grammar Toolbox.
  3. From the Grammar Toolbox, select an element, drag it onto Rule Editor, and place it before (to the left of) or after (to the right of) another element.

To add sibling elements using the shortcut menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. Right-click Rule Editor, on the shortcut menu point to Set Insertion Element Type, and then click the type of sibling element to insert.
  3. Right-click the element to add the new sibling element to, and on the shortcut menu, do one of the following.
    • Click Append Sibling Element to insert a sibling element after (to the right of) the most recently inserted element.
    • Click Insert Sibling Element to insert a sibling element before (to the left of) the most recently inserted element.

To add sibling elements using the Grammar menu

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. On Rule Editor, click the element to add the new sibling element to.
  3. On the Grammar menu, point to Set Insertion Element Type, and then click the type of sibling element to insert.
  4. On the Grammar menu, do one of the following.
    • Click Append Sibling Element to insert a sibling element after (to the right of) the most recently inserted element.
    • Click Insert Sibling Element to insert a sibling element before (to the left of) the most recently inserted element.

Manipulating Groups and Lists

Elements are commonly grouped together when they contain related information, when they consist of alternative choices a user picks from, or when parent elements should pass property values to child elements. Use the Group element to pass properties from parent elements to child elements and to group together elements that contain related information. Use the List element to create a list of alternative choices a user picks from. Cities, flavors, or investment options are examples of categories that might be included in a list.

Many operations on multiple selections of elements, whether selected by Control-clicking or by clicking and dragging, are valid only when the selected elements are parents and children, or when they are siblings. Otherwise some entries are not available on the context menu. For instance, it is not possible to select two Phrase elements from two separate Lists and then delete them.

Note  To save vertical screen space when designing grammars in Speech Grammar Editor, expand and collapse the plus (+) and minus (-) signs on the Group and List elements.

Grouping Elements

Multiple elements can be grouped together when the properties of a parent element should be passed down to the child elements. For example, consider that a grammar contains a list of four cities a user can choose from, and that the textual value of each city in the list is the name of the city. A single Phrase element typically represents each city on Rule Editor, and a List element encloses all of the individual Phrase elements. A Group element could enclose the List element, and specify a property whose value reflects the value of the chosen city. When a user chooses a city, the application receives the property value of the chosen city.

To group elements using the Rule Editor toolbar

  1. On Rule Editor, select the elements to be grouped by either pressing the CTRL key and clicking the appropriate elements, or by clicking and dragging on Rule Editor to highlight the appropriate elements.
  2. On the Rule Editor toolbar, click Group.

To group elements using the shortcut menu

  1. On Rule Editor, select the elements to be grouped by either pressing the CTRL key and clicking the appropriate elements, or by clicking and dragging on Rule Editor to highlight the appropriate elements.
  2. Right-click the selected elements, and on the shortcut menu, click Group.

To group elements using the keyboard

  1. On Rule Editor, select the elements to be grouped by either pressing the CTRL key and clicking the appropriate elements, or by clicking and dragging on Rule Editor to highlight the appropriate elements.
  2. On the keyboard, press SHIFT+ALT+T.

To group elements using the Grammar menu

  1. On Rule Editor, select the elements to be grouped by either pressing the CTRL key and clicking the appropriate elements, or by clicking and dragging on Rule Editor to highlight the appropriate elements.
  2. On the Grammar menu, click Group.

Ungrouping Elements

Any of the four following procedures ungroups all elements that are contained in a Group, and removes the Group.

To ungroup elements using the Rule Editor toolbar

  • On Rule Editor, click a Group element, and then on the Rule Editor toolbar, click Ungroup.

To ungroup elements using the shortcut menu

  • On Rule Editor, right-click a Group element, and then on the shortcut menu, click Ungroup.

To ungroup elements using the keyboard

  1. On Rule Editor, select a Group element
  2. On the keyboard, press SHIFT+ALT+U.

To ungroup elements using the Grammar menu

  1. On Rule Editor, click a Group element.
  2. On the Grammar menu, click Ungroup.

Converting Elements

Any of the four following procedures creates a new parent List element, and converts the selected element to a child of the List element.

To convert an element to a list using the Rule Editor toolbar

  • On Rule Editor, click the appropriate element, and then on the Rule Editor toolbar, click Convert to List.

To convert an element to a list using the shortcut menu

  • On Rule Editor, right-click the appropriate element, and then on the shortcut menu, click Convert to List.

To convert an element to a list using the keyboard

  1. On Rule Editor, click the appropriate element.
  2. On the keyboard, press SHIFT+ALT+I.

To convert an element to a list using the Grammar menu

  1. On Rule Editor, click the appropriate element.
  2. On the Grammar menu, click Convert to List.

Promoting Elements

Any of the four following procedures moves a selected List element up one level in the hierarchy.

Note  This feature is available only when a List element that is nested under another List element is selected.

To promote a list within a list using the Rule Editor toolbar

  • On Rule Editor, click the appropriate List element, and then on the Rule Editor toolbar, click Promote.

To promote a list within a list using the shortcut menu

  • On Rule Editor, right-click the appropriate List element, and then on the shortcut menu, click Promote.

To promote a list within a list using the keyboard

  1. On Rule Editor, select the appropriate List element.
  2. On the keyboard, press SHIFT+ALT+O.

To promote a list within a list using the Grammar menu

  1. On Rule Editor, select the appropriate List element.
  2. On the Grammar menu, click Promote.

Manipulating Rules

Grammar rules contain the sequence of words or phrases that a user can say to an application. A grammar file must contain at least one rule, and can contain any number of rules. Each rule within a grammar file must have an identifier that is unique within the scope of the grammar that contains it. Specify the identifier by populating the name attribute in the Properties window of a rule.

A grammar file contains a single rule that is loaded upon activation of a control, such as a Speech QA (QA) control. This rule defines the top-level syntax of spoken input. The single rule that is loaded upon activation of a control is designated as either an active rule or a root rule.

The root rule is used as the starting point for recognition when a RuleRef element points to a grammar file that does not contain a rule name identifier.

The root rule is specified using the root attribute on the grammar XML markup element.

Moving Rule Elements

Move rule elements within the same rule by dragging elements from one location to another, or to and from other rules by cutting or copying elements from one rule and pasting them into another.

To move elements within the same rule

  • Click the element to be moved, and drag it to a new location. Drop the element to the new location if the icon changes to indicate that this is a valid location.

To move elements between rules

  1. Open two or more rules in Rule Editor.
  2. Optionally, on the Window menu, select either New Horizontal Tab Group or New Vertical Tab Group. This selection displays Rule Editor windows for each of the rules.
  3. Right-click the element to be moved, and on the shortcut menu, click either Cut or Copy.
  4. On the other Rule Editor window, right-click the target element, and then on the shortcut menu, click Paste.

The element that was moved inserts into the canvas after the target element.

Referencing Rules

A grammar rule can reference other rules that are either contained in the same grammar file or in other grammar files. Use the RuleRef element, which represents a ruleref XML markup element, to specify a reference to another rule.

To reference a rule in the current grammar file

  1. In Grammar Explorer, double-click a rule to open Rule Editor.
  2. On Rule Editor, right-click the element that will make the reference, on the shortcut menu click Insert Element, and then click RuleRef. A RuleRef element appears on Rule Editor.
  3. Right-click the RuleRef element, on the shortcut menu point to Set Target Rule, and then on the top part of the shortcut sub-menu, click one of the rule names. If the grammar file contains more than 10 rules, click Other to display the full list of rules that can be referenced.

To reference a rule in a separate grammar file

  1. In Grammar Explorer, double-click a rule to open Rule Editor.

  2. On Rule Editor, right-click the element that will make the reference, on the shortcut menu point to Set Insertion Element Type, and then on the shortcut sub-menu, click RuleRef.

  3. Right-click the element that will make the reference, and on the shortcut menu, click Append Sibling Element.

  4. Right-click the new RuleRef element, on the shortcut menu point to Set Target Rule, and then on the bottom part of the shortcut sub-menu, click Browse.

  5. Use the file browser to select either a .grxml, .xml, or .cfg file, and then click Open. The Rule Browser window opens.

    The Rule Browser displays the list of the rules with Public scope in its left pane, and the description of the rule in the right pane.

  6. On the Rule Browser window, click the name of the rule to be referenced, and then click Set Target Rule.

Note  The Rule Browser window only displays rules that have the scope attribute set to Public.

See Also

Enabling Speech Recognition | Creating Grammars | Grammar Design