Поделиться через


SrgsOneOf Конструкторы

Определение

Создает новый экземпляр класса SrgsOneOf.

Перегрузки

SrgsOneOf()

Инициализирует новый экземпляр класса SrgsOneOf.

SrgsOneOf(SrgsItem[])

Инициализирует новый экземпляр класса SrgsOneOf из массива объектов SrgsItem.

SrgsOneOf(String[])

Инициализирует новый экземпляр класса SrgsOneOf из массива объектов String.

Комментарии

Экземпляр SrgsOneOf класса можно создать из массива String объектов, из массива SrgsItem объектов или в виде пустого списка. Использование SrgsItem объектов вместо String объектов в списке альтернатив позволяет применять свойства SrgsItem к каждому элементу в списке, например MinRepeat, MaxRepeat, RepeatProbabilityи Weight.

SrgsOneOf()

Исходный код:
SrgsOneOf.cs
Исходный код:
SrgsOneOf.cs
Исходный код:
SrgsOneOf.cs
Исходный код:
SrgsOneOf.cs

Инициализирует новый экземпляр класса SrgsOneOf.

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

Примеры

В следующем примере элемент используется SrgsOneOf для создания списков элементов, SrgsItem содержащих названия стран или регионов, любой из которых может использоваться для распознавания содержащей фразы. Затем в примере один из результируемых SrgsOneOf объектов добавляется в соответствующие правила для европейских и южноамериканских стран и регионов. Далее в примере объект используется для группировки SrgsOneOf ссылок на ruleEurope правила и ruleSAmerica в список из двух альтернатив, один из которых может использоваться для распознавания устного ввода.

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
Исходный код:
SrgsOneOf.cs

Инициализирует новый экземпляр класса SrgsOneOf из массива объектов SrgsItem.

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

Альтернативные элементы для добавления.

Исключения

items имеет значение null.

Все элементы массива items имеют значение null.

Примеры

В следующем примере создается грамматика, которая распознает фразу "Нация, которая выиграла Кубок мира", за которой следует название страны или региона, выигравшего Кубок мира. Он создает открытое правило с именем WorldCupWinner. Затем он создает два SrgsRule объекта с помощью SrgsOneOf объектов, содержащих массивы новых SrgsItem объектов. Чтобы просмотреть грамматику, созданную в этом примере, см. раздел 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
Исходный код:
SrgsOneOf.cs

Инициализирует новый экземпляр класса SrgsOneOf из массива объектов String.

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

Альтернативные элементы для добавления.

Исключения

items имеет значение null.

Все элементы массива 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;
}

См. также раздел

Применяется к