microsoft speech platform - how to update srgs grammar in C# -


i have created srgs file semantic recognition, want udate mygrammar file,now how update my_grammar.xml file , add more cities in item tag textbox. helping material regarding appreciated , in advance.

     <grammar version="1.0" xml:lang="en-us" mode="voice" root="destination"              xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">           <rule id="source">                <one-of>               <item> karachi </item>               <item> lahore </item>               <item> abbottabad </item>  <item> murree </item>             </one-of>           </rule>  <rule id="destination">                <one-of>               <item> karachi </item>               <item> lahore </item>               <item> islamabad </item>             </one-of>           </rule>  <rule id="article">                <one-of>               <item> to</item>              </one-of>           </rule>         </grammar>            srgsrule srcrule = new srgsrule("id_source");           srgsoneof srclist = new srgsoneof(new string[] { "lahore","karachi",abbottabad ,"murree"});           srcrule.add(srclist);            srgsrule articlerule = new srgsrule("id_article");           srgsoneof articlelist = new srgsoneof(new string[] { "to" });           articlerule.add(articlelist);            srgsrule desrule = new srgsrule("id_destination");           srgsoneof deslist = new srgsoneof(new string[] { "islamabad","lahore","karachi",abbottabad ,"murree"});           desrule.add(deslist);            srgsrule rootrule = new srgsrule("src_article_des");           rootrule.scope = srgsrulescope.public;            srgsruleref srcref = new srgsruleref(srcrule, "thesource");           rootrule.add(srcref);            srgsruleref articleref = new srgsruleref(articlerule, "thearticle");           rootrule.add(articleref);            srgsruleref desref = new srgsruleref(desrule, "thedestination");           rootrule.add(desref);            srgsdocument document = new srgsdocument();           document.rules.add(new srgsrule[] { rootrule, srcrule, articlerule, desrule });                   document.root = rootrule;           grammar g = new grammar(document, "src_article_des");           sr.loadgrammar(g);           system.xml.xmlwriter writer =             system.xml.xmlwriter.create("c:\\test\\mygrammar.xml");           document.writesrgs(writer);           writer.close(); 

try this. used xml linq, can same using straight xml.

using system; using system.collections.generic; using system.linq; using system.text; using system.xml; using system.xml.linq;  namespace consoleapplication32 {     class program     {         static void main(string[] args)         {             string input =                "<one-of>" +                   "<item>" +          //add item dynamically. // want add item here                   "</item>" +                   "<item> " +        //add new items.// want add item here                   "</item>" +               "</one-of>";              xdocument doc = xdocument.parse(input);              list<xelement> items = doc.descendants().where(x => x.name == "item").tolist();             foreach (xelement item in items)             {                 xelement newelement = new xelement("newitem", "i want add item here");                 item.add(newelement);             }         }     } } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -