SrgsOneOf Constructor (String[])

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

Initializes a new instance of the SrgsOneOf class from an array of String objects.

Namespace:  Microsoft.Speech.Recognition.SrgsGrammar
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	ParamArray items As String() _
)
Visual Basic (Usage)
Dim items As String()

Dim instance As New SrgsOneOf(items)
C#
public SrgsOneOf(
	params string[] items
)

Parameters

items
Type: array<System..::..String>[]()[][]

The alternative items to add.

Exceptions

ExceptionCondition
ArgumentNullException

items is nullNothingnullptrunita null reference (Nothing in Visual Basic).

Any element in the items array is nullNothingnullptrunita null reference (Nothing in Visual Basic).

Examples

The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country that has won the World Cup. The example uses the SrgsOneOf element to build lists of acceptable country names from an array of String objects. The example then adds one of the resulting SrgsOneOf objects to their respective rules for European countries and South American countries.

 Copy imageCopy Code
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;
}

See Also