SrgsRule Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da SrgsRule classe.
Sobrecargas
| Nome | Descrição |
|---|---|
| SrgsRule(String) |
Inicializa uma nova instância da SrgsRule classe e especifica o identificador da regra. |
| SrgsRule(String, SrgsElement[]) |
Inicializa uma nova instância da SrgsRule classe a partir de um array de SrgsElement objetos. |
SrgsRule(String)
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
Inicializa uma nova instância da SrgsRule classe e especifica o identificador da regra.
public:
SrgsRule(System::String ^ id);
public SrgsRule(string id);
new System.Speech.Recognition.SrgsGrammar.SrgsRule : string -> System.Speech.Recognition.SrgsGrammar.SrgsRule
Public Sub New (id As String)
Parâmetros
- id
- String
O identificador da regra.
Exceções
id é null.
id está vazio.
id não é um identificador de regra adequado.
Exemplos
O exemplo seguinte cria uma gramática que reconhece a frase "Uma nação que venceu a Taça do Mundo é" seguida do nome de um país que venceu a Taça do Mundo. O exemplo cria um SrgsRule objeto nomeado winnerRule e passa o identificador WorldCupWinner como um String. O SrgsOneOf objeto consiste num array de novos SrgsItem objetos contendo alternativas a serem reconhecidas pela regra.
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;
}
Observações
O SrgsRule construtor inicializa a Id propriedade. O identificador deve ser único dentro de uma dada gramática.
O SrgsRule construtor lança a FormatException nas seguintes circunstâncias:
idnão é um nome XML válido, conforme definido na Extensible Markup Language (XML) 1.0 (Quinta Edição). Para parafrasear esta definição, um nome XML válido deve começar com uma letra, um sublinhado ('_') ou dois pontos (':') e pode ser seguido de zero ou mais caracteres NameChar (também definidos na especificação XML).idé "NULL" ou "VOID" ou "LIXO".idcontém pelo menos um carácter de ID de regra inválido. Estes caracteres são: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<', '', '>', '[', ']', '{', '}', '\', ' ', '\t', '\r', e '\n'.
Consulte também
Aplica-se a
SrgsRule(String, SrgsElement[])
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
- Origem:
- SrgsRule.cs
Inicializa uma nova instância da SrgsRule classe a partir de um array de SrgsElement objetos.
public:
SrgsRule(System::String ^ id, ... cli::array <System::Speech::Recognition::SrgsGrammar::SrgsElement ^> ^ elements);
public SrgsRule(string id, params System.Speech.Recognition.SrgsGrammar.SrgsElement[] elements);
new System.Speech.Recognition.SrgsGrammar.SrgsRule : string * System.Speech.Recognition.SrgsGrammar.SrgsElement[] -> System.Speech.Recognition.SrgsGrammar.SrgsRule
Public Sub New (id As String, ParamArray elements As SrgsElement())
Parâmetros
- id
- String
O identificador da regra.
- elements
- SrgsElement[]
Uma variedade de SrgsElement elementos.
Exceções
id está vazio.
id não é um identificador de regra adequado.
Exemplos
O exemplo seguinte cria uma gramática que reconhece a frase "Uma nação que venceu a Taça do Mundo é" seguida do nome de um país que venceu a Taça do Mundo. O exemplo cria uma regra pública chamada WorldCupWinner. O exemplo cria então dois SrgsRule objetos, ruleEurope e ruleSAmerica, passando um String para o identificador de regra e um SrgsElement array contendo um SrgsOneOf objeto. Subsequentemente, o exemplo adiciona referências de regra para ruleEurope e ruleSAmerica a partir da regra WorldCupWinner.
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 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 grammar and make winnerRule
// the root rule of the grammar.
document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
srgsGrammar.Root = winnerRule;
}
A gramática criada tem a seguinte forma.
<grammar version="1.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar" root="WorldCupWinner">
<rule id="WorldCupWinner" scope="public">
<item> A nation that has won the world cup is </item>
<one-of>
<item>
<ruleref uri="#EuropeanNations" />
</item>
<item>
<ruleref uri="#SouthAmericanNations" />
</item>
</one-of>
</rule>
<rule id="EuropeanNations">
<one-of>
<item> England </item>
<item> France </item>
<item> Germany </item>
<item> Italy </item>
</one-of>
</rule>
<rule id="SouthAmericanNations">
<one-of>
<item> Argentina </item>
<item> Brazil </item>
<item> Uruguay </item>
</one-of>
</rule>
</grammar>
Observações
O SrgsRule construtor inicializa a Id propriedade. O identificador deve ser único dentro de uma dada gramática.
O SrgsRule construtor lança a FormatException nas seguintes circunstâncias:
idnão é um nome XML válido, conforme definido na Extensible Markup Language (XML) 1.0 (Quinta Edição). Para parafrasear esta definição, um nome XML válido deve começar com uma letra, um sublinhado ('_') ou dois pontos (':') e pode ser seguido de zero ou mais caracteres NameChar (também definidos na especificação XML).idé "NULL" ou "VOID" ou "LIXO".idcontém pelo menos um carácter de ID de regra inválido. Estes caracteres são: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<', '', '>', '[', ']', '{', '}', '\', ' ', '\t', '\r', e '\n'.