The returned value (tag) of a grammar rule

14 Feb

The returned value (tag) of a grammar rule seems to be straightforward to understand, provided that the grammar is of simple form, for instance:

(a) (b)

Figure (a) dipicts a grammar rule named “Verb”, while the output value is defaulted to the recognized words. Note that their is no tag value returned, as indicated in Figure (a). To extract the tag value for other uses, a script tag must be explicted appended, as shown in Figure (b). In this case, all the words return the same tag value, i.e. “Create”.

Note I: A tag value is only avaiable when a script tag is explictly added.

Now consider a complicated rule like this:

In this example, what is the returned final tag? The answer is “Create”, even when the spoken words are “Sketch Circle”, “New Line” etc. The reason is the 2nd list “Circle … Polygon” does not have a tag associated. While a natural idea is to append a tag to the tail, like follows:

While this is wrong again. The finally appended tag (i.e. “$=$recognized.text”) denotes the entire tag, not the tag for the 2nd list “Circle … Polygon” !

Note II: A tag value denotes all the tag value accumulated till the point of interest, rather than a partial tag for the last section.

So in case, we want to speek “Sketch Circle”, “New Line”, “Add center line” and we can all get the tags of “Create Circle”, “Create line”, “Create center line”, how to accomplish this? The answer is to use rule reference.


As shown in Figure (c), a composite rule is proposed which refers to the rule “Verb” , and the the rule “Noun”, by adding a tag and explicitly edit the script:

“$._value = $Verb._value + ” ” + $Noun._value”,

it is possible to combine these two sub-rules into a composite one. The tag value of the rule “Verb” is shown in Figure (b), i.e. a constant string “Create”, but what is the tag of the rule “Noun”? It is apparently the recognized words. So, we can add a tag as shown in Figure (d). Now test it, oops, an error! Why? Because, in the script:

“$._value = $Verb._value + ” ” + $Noun._value “,

we have refered to the value $Noun._value, but in fact that is no such a value! Note in Figure (d), the output tag is not

$._value= $recognized.text,

but $ = $recognized.text !

See the tricks here? Finally the workround can be like this:

  • change the composite tag into $._value = $Verb._value + ” ” + $Noun or
  • Edit the Noun tag with script: $._value= $recognized.text, and the composite tag “$._value = $Verb._value + ” ” + $Noun._value” remains.

Both will do. Again note the difference of “$._value” and “$” and so comes the final note.

Note II: A rule value is different from the rule tag, the rule tag is only accessible or meaningful unless you explicitly define or add an tag (s.a. note I). A rule value is defaulted to the recognized text, while the rule tag value can be flexibly configured using scripts.

While all these are just my trial-and-error comments, it may not be fully correct, since there is no detailed descriptions or documents. However, better little than none!

Leave a comment

Posted by on February 14, 2008 in CAD


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: