SrgsDocument.Rules Propiedad

Definición

Obtiene la colección de reglas definidas actualmente para la clase 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

Valor de propiedad

SrgsRulesCollection

Devuelve las reglas definidas para el objeto SrgsDocument.

Ejemplos

En el ejemplo siguiente se crea una gramática que reconoce la frase "un país que ha ganado la Copa del mundo" seguido del nombre de un país o región que ha ganado la Copa del mundo. En el ejemplo se crea un SrgsDocument objeto y, a continuación, se crea una regla pública denominada winnerRule . Después de agregar una cadena a la regla winnerRule , en el ejemplo se crean dos reglas más ( ruleEurope y ruleSAmerica ), cada una de las cuales contiene una lista de países o regiones. Con el Add método, el ejemplo agrega las tres reglas ( winnerRule , ruleEurope y ruleSAmerica ) a la Rules propiedad de SrgsDocument .

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

Comentarios

Puede agregar SrgsRule objetos a SrgsRulesCollection mediante el Add método en la Rules propiedad. Si Inicializa un SrgsDocument objeto y especifica un SrgsRule objeto como argumento, SrgsRule se agrega automáticamente a SrgsRulesCollection para SrgsDocument .

Se aplica a

Consulte también