SrgsDocument.Rules Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la collection de règles actuellement définies pour la SrgsDocument classe.
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
Valeur de propriété
Retourne les règles définies pour l’objet SrgsDocument .
Exemples
L’exemple suivant crée une grammaire qui reconnaît l’expression « Une nation qui a remporté la Coupe du Monde est » suivie du nom d’un pays/région qui a remporté la Coupe du Monde. L’exemple crée un SrgsDocument objet, puis crée une règle publique nommée winnerRule. Après avoir ajouté une chaîne à la règle winnerRule, l’exemple crée deux autres règles (ruleEurope et ruleSAmerica), chacune contenant une liste de pays/régions. À l’aide de la Add méthode, l’exemple ajoute les trois règles (winnerRule, ruleEuropeet ruleSAmerica) à la Rules propriété du 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;
}
Remarques
Vous pouvez ajouter des SrgsRule objets à l’aide SrgsRulesCollection de la Add méthode sur la Rules propriété. Si vous initialisez un SrgsDocument objet et spécifiez un SrgsRule objet en tant qu’argument, il SrgsRule est automatiquement ajouté à l’objet SrgsRulesCollection pour le SrgsDocument.