SrgsRule Constructores

Definición

Inicializa una nueva instancia de la clase SrgsRule.

Sobrecargas

SrgsRule(String)

Inicializa una nueva instancia de la clase SrgsRule y especifica el identificador para la regla.

SrgsRule(String, SrgsElement[])

Inicializa una nueva instancia de la clase SrgsRule desde una matriz de objetos SrgsElement.

SrgsRule(String)

Source:
SrgsRule.cs
Source:
SrgsRule.cs
Source:
SrgsRule.cs

Inicializa una nueva instancia de la clase SrgsRule y especifica el identificador para la regla.

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

El identificador de la regla.

Excepciones

id es null.

id está vacía.

id no es un identificador de regla apropiado.

Ejemplos

En el ejemplo siguiente se crea una gramática que reconoce la frase "Una nación que ha ganado la Copa Mundial" seguida del nombre de un país que ha ganado la Copa Mundial. En el ejemplo se crea un SrgsRule objeto denominado winnerRule y se pasa el identificador WorldCupWinner como .String El SrgsOneOf objeto consta de una matriz de nuevos SrgsItem objetos que contienen alternativas que la regla reconoce.

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

El SrgsRule constructor inicializa la Id propiedad . El identificador debe ser único dentro de una gramática determinada.

El SrgsRule constructor produce una FormatException excepción en las siguientes circunstancias:

  • idno es un nombre XML válido, tal como se define en Lenguaje de marcado extensible (XML) 1.0 (Quinta edición). Para definir esta definición, un nombre XML válido debe comenzar con una letra, un carácter de subrayado ('_') o dos puntos (':') y puede ir seguido de cero o más caracteres NameChar (también definidos en la especificación XML).

  • id es "NULL" o "VOID" o "GARBAGE".

  • id contiene al menos un carácter de identificador de regla no válido. Estos caracteres son: '?', '*', '+', '|', '(', '),'^', '$', '/', ';', '.', '=', '',> '<', '[', ']', '{', '}', '\\', ', '\t', '\r' y '\n'.

Consulte también

Se aplica a

SrgsRule(String, SrgsElement[])

Source:
SrgsRule.cs
Source:
SrgsRule.cs
Source:
SrgsRule.cs

Inicializa una nueva instancia de la clase SrgsRule desde una matriz de objetos SrgsElement.

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

El identificador de la regla.

elements
SrgsElement[]

Matriz de elementos SrgsElement.

Excepciones

id es null.

elements es null.

id está vacía.

id no es un identificador de regla apropiado.

Ejemplos

En el ejemplo siguiente se crea una gramática que reconoce la frase "Una nación que ha ganado la Copa Mundial" seguida del nombre de un país que ha ganado la Copa Mundial. En el ejemplo se crea una regla pública denominada WorldCupWinner. A continuación, el ejemplo crea dos SrgsRule objetos, ruleEurope y ruleSAmerica, pasando un String para el identificador de regla y una SrgsElement matriz que contiene un SrgsOneOf objeto . Posteriormente, en el ejemplo se agregan referencias de regla a ruleEurope y ruleSAmerica desde la regla 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;
}

La gramática creada tiene el siguiente formato.

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

Comentarios

El SrgsRule constructor inicializa la Id propiedad . El identificador debe ser único dentro de una gramática determinada.

El SrgsRule constructor produce una FormatException excepción en las siguientes circunstancias:

  • idno es un nombre XML válido, tal como se define en Lenguaje de marcado extensible (XML) 1.0 (Quinta edición). Para definir esta definición, un nombre XML válido debe comenzar con una letra, un carácter de subrayado ('_') o dos puntos (':') y puede ir seguido de cero o más caracteres NameChar (también definidos en la especificación XML).

  • id es "NULL" o "VOID" o "GARBAGE".

  • id contiene al menos un carácter de identificador de regla no válido. Estos caracteres son: '?', '*', '+', '|', '(', '),'^', '$', '/', ';', '.', '=', '',> '<', '[', ']', '{', '}', '\\', ', '\t', '\r' y '\n'.

Consulte también

Se aplica a