none
System.Speech.Recognition with strongly typed grammars RRS feed

  • Question

  • Hi

    The msdn documentation of IsStg hints at strongly typed grammars. So I am guessing that I create an Grammar derived from Grammar, with extra properties, and pass that to the recognizer My grammar takes the path to the srgs xml file.

    recognizer.LoadGrammer(new MyGrammar("PathToSrgsFile"));

    Now in the srgs example it makes use of xml tags with stuff like <tag> out.Card = rules.PlayCard; </tag>.

    Is this the mechanism that will set property values of strongly type grammars. If so is there any documentation on the syntax used as the contents of tag.

    If this is not it, how do you create strongly typed grammars.

    thanks


    • Edited by hypodyne1 Saturday, December 10, 2016 5:19 AM typo
    Saturday, December 10, 2016 5:17 AM

Answers

  • Hello hypodyne1

    >>Is this the mechanism that will set property values of strongly type grammars. If so is there any documentation on the syntax used as the contents of tag.

    Here is a XML example shows a use of string literals in the tag element. The tag element assigns a string value to the Rule Variable of the rule "destAirport". When "Heathrow" is recognized, the string "Destination" is returned as a semantic result.

    <?xml version="1.0" encoding="utf-8"?>

    <grammar version="1.0" xml:lang="en-US" root="destAirport"

     xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0-literals">

      <rule id="destAirport">

        <item> Heathrow <tag> Destination </tag> </item>

      </rule>

    </grammar>

    From above sample, the contents of tag is a string.

    Here is the reference.

    >>Now in the srgs example it makes use of xml tags with stuff like <tag> out.Card = rules.PlayCard; </tag>.

    From your message, we use out.PropName (where PropName is the name of the property) to identify properties of the GRN Rule Variable. 

    <rule id="airport">

      Heathrow

        <tag> out.code= "LHR"; </tag>

        <tag> out.location= "England"; </tag>

    </rule>

                                                                                                                    

    But when you create Grandchild Properties, ECMAScript is not a strongly typed language, meaning that when a property is initialized, it is not predefined as a specific type. Instead, assigning a value to the property sets the property type to the same type as the assigned value. In the preceding example, because the location property is assigned a string value, the property type is string.

    The way that type is set in ECMAScript has implications for creating grandchild properties. Before grandchild properties can be created, script writers must first initialize a child property of the type object to contain the grandchild properties. Initialize an object using a new Object() expression as shown in the following example.

    <rule id="airport">

      Heathrow

        <tag> out.location= new Object(); </tag>

        <tag> out.location.country= "England"; </tag>

        <tag> out.location.city= "London"; </tag>

        <tag> out.location.elevation= "80 ft. MSL"; </tag>

    </rule>

    That's why Grammar.IsStg Property exists. For more information, please refer to https://msdn.microsoft.com/en-us/library/hh362856.aspx?f=255&MSPPError=-2147217396

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    • Edited by Kristin Xie Monday, December 12, 2016 6:36 AM
    • Marked as answer by hypodyne1 Tuesday, December 13, 2016 7:17 AM
    Monday, December 12, 2016 6:34 AM