Share via


SrgsOneOf 构造函数

定义

创建 SrgsOneOf 类的新实例。

重载

SrgsOneOf()

初始化 SrgsOneOf 类的新实例。

SrgsOneOf(SrgsItem[])

SrgsItem 对象的数组初始化 SrgsOneOf 类的新实例。

SrgsOneOf(String[])

String 对象的数组初始化 SrgsOneOf 类的新实例。

注解

可以从对象的数组、对象的数组String或空列表构造 类的SrgsItem实例SrgsOneOf。 使用 SrgsItem 替代项列表中的 对象, String 可以将 的属性 SrgsItem 应用于列表中的每个项,例如 MinRepeatMaxRepeatRepeatProbabilityWeight

SrgsOneOf()

Source:
SrgsOneOf.cs
Source:
SrgsOneOf.cs
Source:
SrgsOneOf.cs

初始化 SrgsOneOf 类的新实例。

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

示例

以下示例使用 SrgsOneOf 元素生成包含国家/地区名称的 SrgsItem 元素列表,其中任何一个都可用于识别包含短语。 然后,该示例将生成的 SrgsOneOf 对象之一添加到欧洲和南美国家/地区各自的规则中。 此外,该示例使用 SrgsOneOf 对象将 对 ruleEuroperuleSAmerica 的规则引用分组为两个替代项的列表,其中任一替代项都可用于识别语音输入。

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[])

Source:
SrgsOneOf.cs
Source:
SrgsOneOf.cs
Source:
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

示例

以下示例创建一个语法,该语法识别短语“赢得世界杯的国家为”,后跟赢得世界杯的国家/地区的名称。 它创建名为 的公共 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[])

Source:
SrgsOneOf.cs
Source:
SrgsOneOf.cs
Source:
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

示例

以下示例创建一个语法,该语法识别短语“赢得世界杯的国家为”,后跟赢得世界杯的国家/地区的名称。 该示例使用 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;
}

另请参阅

适用于