Last reviewed: 3/23/2024 8:45:28 AM
<item>
An <item> element can surround any expansion (<item>, <one-of>, <ruleref>, <tag>, <token>) to permit a repeat attribute or language identifier to be attached. The weight attribute of item is ignored unless the element appears within a <one-of> element.
Syntax
<item repeat="n-m" weight="float" />
Attributes
repeat
Indicates the number of times the contained expansion may be repeated.
repeat-prob
Carries the repeat probability. Repeat probabilities are supported on any item element but are ignored if the repeat attribute is not also specified.
xml:lang
Indicates the primary language contained by the grammar and optionally indicates a country.
weight
A weight of 1.0 is equivalent to providing no weight at all. A weight greater than "1.0" positively biases the alternative and a weight less than "1.0" negatively biases the alternative.
Children
<one-of>, <ruleref>, <tag>, and <token>.
Parents
Variables
none
Remarks
Repeat operators are provided that define a legal rule expansion as being another sub-expansion that is optional, that is repeated zero or more times, that is repeated one or more times, or that is repeated some range of times.
Form | Description |
---|---|
repeat="n" repeat="6" | The contained expansion is repeated exactly "n" times. "n" must be "0" or a positive integer. |
repeat="m-n" repeat="4-6" | The contained expansion is repeated between "m" and "n" times (inclusive). "m" and "n" must both be "0" or a positive integer and "m" must be less than or equal to "n". |
repeat="m-" repeat="3-" | The contained expansion is repeated "m" times or more (inclusive). "m" must be "0" or a positive integer. For example, "3-" declares that the contained expansion can occur three, four, five or more times. |
repeat="0-1" | The contained expansion is optional. |
Example
The following example illustrates using item elements with repeat and weight attributes.
<!-- the token "very" is optional -->
<item repeat="0-1">very</item>
<!-- the rule reference to digit can occur zero, one or many times -->
<item repeat="0-"> <ruleref uri="#digit"/> </item>
<!-- the rule reference to digit can occur one or more times -->
<item repeat="1-"> <ruleref uri="#digit"/> </item>
<!-- the rule reference to digit can occur four, five or six times -->
<item repeat="4-6"> <ruleref uri="#digit"/> </item>
<!-- the rule reference to digit can occur ten or more times -->
<item repeat="10-"> <ruleref uri="#digit"/> </item>
<!-- Examples of the following expansion -->
<!-- "pizza" -->
<!-- "big pizza with pepperoni" -->
<!-- "very big pizza with cheese and pepperoni" -->
<item repeat="0-1">
<item repeat="0-1"> very </item>
big
</item>
pizza
<item repeat="0-">
<item repeat="0-1">
<one-of>
<item>with</item>
<item>and</item>
</one-of>
</item>
<ruleref uri="#topping"/>
</item>
<-- The token "very" is optional and is 60% likely to occur. -->
<-- Means 40% chance that "very" is absent in input -->
<item repeat="0-1" repeat-prob="0.6">very</item>
<-- The rule reference to digit must occur two to four times -->
<-- with 80% probability of recurrence. -->
<item repeat="2-4" repeat-prob=".8">
<ruleref uri="#digit"/>
</item>