共用方式為


SrgsOneOf 建構函式

定義

建立 SrgsOneOf 類別的新執行個體。

多載

SrgsOneOf()

初始化 SrgsOneOf 類別的新執行個體。

SrgsOneOf(SrgsItem[])

SrgsItem 物件的陣列,初始化 SrgsOneOf 類別的新執行個體。

SrgsOneOf(String[])

String 物件的陣列,初始化 SrgsOneOf 類別的新執行個體。

備註

您可以從 物件的陣列 String 、物件的陣列或空白清單,建構 類別的 SrgsItem 實例 SrgsOneOf 。 使用 SrgsItem 物件,而不是 String 替代專案清單中的 物件,可讓您將 的屬性 SrgsItem 套用至清單中的每個專案,例如 MinRepeatMaxRepeatRepeatProbabilityWeight

SrgsOneOf()

來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs

初始化 SrgsOneOf 類別的新執行個體。

public:
 SrgsOneOf();
public SrgsOneOf ();
Public Sub New ()

範例

下列範例會 SrgsOneOf 使用 元素來建置包含國家/地區名稱的專案 SrgsItem 清單,其中任一個專案都可以用來辨識包含的片語。 然後,此範例會將其中一個產生的 SrgsOneOf 物件新增至歐洲和南非國家/地區各自的規則。 此外,此範例會 SrgsOneOf 使用 物件,將 和 ruleSAmerica 的規則參考 ruleEurope 分組到兩個替代專案清單中,其中一個可能用來辨識口語輸入。

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

另請參閱

適用於

SrgsOneOf(SrgsItem[])

來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs

SrgsItem 物件的陣列,初始化 SrgsOneOf 類別的新執行個體。

public:
 SrgsOneOf(... cli::array <System::Speech::Recognition::SrgsGrammar::SrgsItem ^> ^ items);
public SrgsOneOf (params System.Speech.Recognition.SrgsGrammar.SrgsItem[] items);
new System.Speech.Recognition.SrgsGrammar.SrgsOneOf : System.Speech.Recognition.SrgsGrammar.SrgsItem[] -> System.Speech.Recognition.SrgsGrammar.SrgsOneOf
Public Sub New (ParamArray items As SrgsItem())

參數

items
SrgsItem[]

要加入的替代項目。

例外狀況

itemsnull

items 陣列中的任何元素都是 null

範例

下列範例會建立一個文法,以辨識「已贏得世界盃的國家/地區」片語,後面接著已贏得 World Cup 的國家/地區名稱。 它會建立名為 的 WorldCupWinner 公用規則。 然後,它會使用 SrgsOneOf 包含新 SrgsItem 物件陣列的物件來建立兩 SrgsRule 個物件。 若要查看這個範例產生的文法,請參閱 SrgsRule

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

另請參閱

適用於

SrgsOneOf(String[])

來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs
來源:
SrgsOneOf.cs

String 物件的陣列,初始化 SrgsOneOf 類別的新執行個體。

public:
 SrgsOneOf(... cli::array <System::String ^> ^ items);
public SrgsOneOf (params string[] items);
new System.Speech.Recognition.SrgsGrammar.SrgsOneOf : string[] -> System.Speech.Recognition.SrgsGrammar.SrgsOneOf
Public Sub New (ParamArray items As String())

參數

items
String[]

要加入的替代項目。

例外狀況

itemsnull

items 陣列中的任何元素都是 null

範例

下列範例會建立一個文法,以辨識「已贏得世界盃的國家/地區」片語,後面接著已贏得 World Cup 的國家/地區名稱。 此範例會 SrgsOneOf 使用 專案,從 物件的陣列 String 建置可接受的國家/地區名稱清單。 然後,此範例會將其中一個產生的 SrgsOneOf 物件新增至歐洲和南非國家/地區各自的規則。

public void WorldSoccerWinners ()
{
    // Create a grammar from an SRGSDocument, create a new rule
  // and set its scope to public.
  SrgsDocument srgsGrammar = 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 string[] {"England","France","Germany","Italy"});
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf (new string[] {"Argentina","Brazil","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 grammar and make winnerRule
  // the root rule of the grammar.
  srgsGrammar.Rules.Add (new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  srgsGrammar.Root = winnerRule;
}

另請參閱

適用於