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
屬性值
一個數值會設定規則的範圍。
範例
以下範例建立一個文法,該文法承認短語「A nation who had won the World Cup」後接贏得世界盃國家的名稱。 它會建立一條名為 WorldCupWinner Public 的規則,並將該規則的範圍設定為 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 包含文法中的物件或外部文法中的規則來啟動物件以進行識別。