Dragonfly grammars are built up out of a small set of fundamental building blocks. These building blocks are implemented by the following element classes:
- ElementBase – the base class from which all other element classes are derived
- Sequence – sequence of child elements which must all match in the order given
- Alternative – list of possibilities of which only one will be matched
- Optional – wrapper around a child element which makes the child element optional
- Repetition – repetition of a child element
- Literal – literal word which must be said exactly by the speaker as given
- RuleRef – reference to a dragonfly.all.Rule object; this element allows a rule to include (i.e. reference) another rule
- ListRef – reference to a dragonfly.all.List object
The following element classes are built up out of the fundamental classes listed above:
- Dictation – free-form dictation; this element matches any words the speaker says, and includes facilities for formatting the spoken words with correct spacing and capitalization
- DictListRef – reference to a dragonfly.all.DictList object; this element is similar to the dragonfly.all.ListRef element, except that it returns the value associated with the spoken words instead of the spoken words themselves
Element class representing several child elements of which only one will match.
For a recognition to match, at least one of the child elements must match the recognition. The first matching child is used. Child elements are searched in the order they are given in the children constructor argument.
Base class for all other element classes.
Returns an iterable containing the dependencies of this element and of this element’s children.
The dependencies are the objects that are necessary for this element. These include lists and other rules.
Returns a formatted grammar string of the contents of this element and its children.
The grammar string is of a format similar to that used by Natlink to define its grammars.
Determine the semantic value of this element given the recognition results stored in the node.
The default behavior of this method is to return an iterable containing the recognized words matched by this element (i.e. node.words()).
Element class representing an optional child element.
Recognitions always match this element. If the child element does match the recognition, then that result is used. Otherwise, this element itself does match but the child is not processed.
Element class representing a repetition of one child element.
For a recognition to match, at least one of the child elements must match the recognition. The first matching child is used. Child elements are searched in the order they are given in the children constructor argument.
Returns a list containing the nodes associated with each repetition of this element’s child element.
The value of a Repetition is a list containing the values of its child.
The length of this list is equal to the number of times that the child element was recognized.
Element class representing a sequence of child elements which must all match a recognition in the correct order.
For a recognition to match, all child elements must match the recognition in the order that they were given in the children constructor argument.