SrgsRule.Scope 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置是否可以为识别激活一条规则,以及此规则何时可由其他规则引用。
public:
property System::Speech::Recognition::SrgsGrammar::SrgsRuleScope Scope { System::Speech::Recognition::SrgsGrammar::SrgsRuleScope get(); void set(System::Speech::Recognition::SrgsGrammar::SrgsRuleScope value); };
public System.Speech.Recognition.SrgsGrammar.SrgsRuleScope Scope { get; set; }
member this.Scope : System.Speech.Recognition.SrgsGrammar.SrgsRuleScope with get, set
Public Property Scope As SrgsRuleScope
属性值
设置规则范围的值。
示例
以下示例创建一个语法,该语法识别短语“赢得世界杯的国家是”,后跟赢得世界杯的国家的名称。 它创建名为 WorldCupWinner
的公共规则,并将该规则的范围设置为 Public。
// Create an SrgsDocument, create a new rule and set its scope to public.
SrgsDocument document = new SrgsDocument();
SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
winnerRule.Scope = SrgsRuleScope.Public;
// Add the introduction.
winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));
// Create the rule for the European nations.
SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));
// Create the rule for the South American nations.
SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));
// Add references to winnerRule for ruleEurope and ruleSAmerica.
winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem (new SrgsRuleRef(ruleEurope)), new SrgsItem(new SrgsRuleRef(ruleSAmerica)})));
// Add all the rules to the document and make winnerRule
// the root rule of the document.
document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
document.Root = winnerRule;
创建的语法具有以下形式。
<grammar version="1.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar" root="WorldCupWinner">
<rule id="WorldCupWinner" scope="public">
<item> A nation that has won the world cup is </item>
<one-of>
<item>
<ruleref uri="#EuropeanNations" />
</item>
<item>
<ruleref uri="#SouthAmericanNations" />
</item>
</one-of>
</rule>
<rule id="EuropeanNations">
<one-of>
<item> England< /item>
<item> France </item>
<item> Germany </item>
<item> Italy </item>
</one-of>
</rule>
<rule id="SouthAmericanNations">
<one-of>
<item> Argentina </item>
<item> Brazil </item>
<item> Uruguay </item>
</one-of>
</rule>
</grammar>
注解
作用域的默认值为 Private
。 专用规则只能由包含语法中根规则的规则引用或从根规则引用的另一个规则激活进行识别。 外部语法不能引用专用规则,除非私有规则声明为其包含语法的根规则。
如果其范围设置为 Public
, SrgsRule 则可以通过引用包含语法中的 对象或外部语法中的规则来激活对象进行识别 SrgsRuleRef 。