我已经为语义识别创建了 srgs 文件,现在我想更新 myGrammar 文件,现在如何更新 my_Grammar.xml 文件并从文本框中的项目标签中添加更多城市。关于这方面的帮助材料将不胜感激并提前致谢。
<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();