次の方法で共有


SrgsDocument.Rules プロパティ

定義

SrgsDocument クラスに対して現在定義されている規則のコレクションを取得します。

public:
 property System::Speech::Recognition::SrgsGrammar::SrgsRulesCollection ^ Rules { System::Speech::Recognition::SrgsGrammar::SrgsRulesCollection ^ get(); };
public System.Speech.Recognition.SrgsGrammar.SrgsRulesCollection Rules { get; }
member this.Rules : System.Speech.Recognition.SrgsGrammar.SrgsRulesCollection
Public ReadOnly Property Rules As SrgsRulesCollection

プロパティ値

SrgsDocument オブジェクトに定義されている規則を返します。

次の例では、"A nation that has the world Cup is" という語句を認識し、その後にワールドカップで優勝した国/地域の名前を認識する文法を作成します。 この例では、 SrgsDocument オブジェクトを作成し、 winnerRuleという名前のパブリック ルールを作成します。 この例では、ルール winnerRuleに文字列を追加した後、2 つのルール (ruleEuroperuleSAmerica) を作成し、それぞれに国/地域の一覧を含めます。 この例では、Add メソッドを使用して、3 つの規則 (winnerRuleruleEuroperuleSAmerica) をすべてSrgsDocumentRules プロパティに追加します。

public void WorldSoccerWinners ()
{

  // 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;
}

注釈

Rules プロパティの Add メソッドを使用して、SrgsRule オブジェクトをSrgsRulesCollectionに追加できます。 SrgsDocument オブジェクトを初期化し、引数としてSrgsRule オブジェクトを指定すると、SrgsRuleSrgsDocumentSrgsRulesCollectionに自動的に追加されます。

適用対象

こちらもご覧ください