Język

SrgsRule Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy SrgsRule.

Przeciążenia

Nazwisko Opis
SrgsRule(String)

Inicjuje nowe wystąpienie SrgsRule klasy i określa identyfikator reguły.

SrgsRule(String, SrgsElement[])

Inicjuje nowe wystąpienie SrgsRule klasy z tablicy SrgsElement obiektów.

SrgsRule(String)

Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs

Inicjuje nowe wystąpienie SrgsRule klasy i określa identyfikator reguły.

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)

Parametry

id
String

Identyfikator reguły.

Wyjątki

Parametr id ma wartość null.

id nie jest prawidłowym identyfikatorem reguły.

Przykłady

W poniższym przykładzie tworzona jest gramatyka, która rozpoznaje frazę "Naród, który wygrał Puchar Świata", a następnie nazwę kraju, który wygrał Mistrzostwa Świata. Przykład tworzy SrgsRule obiekt o nazwie winnerRule i przekazuje identyfikator WorldCupWinner jako String. Obiekt SrgsOneOf składa się z tablicy nowych SrgsItem obiektów zawierających alternatywy rozpoznawane przez regułę.

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

Uwagi

Konstruktor SrgsRule inicjuje Id właściwość . Identyfikator musi być unikatowy w ramach danej gramatyki.

Konstruktor SrgsRule zgłasza wyjątek FormatException w następujących okolicznościach:

  • id nie jest prawidłową nazwą XML zdefiniowaną w języku Extensible Markup Language (XML) 1.0 (piąta wersja). Aby sparafrazować tę definicję, prawidłowa nazwa XML musi zaczynać się literą, podkreśleniem ('_') lub dwukropkiem (':') i może być po nim zero lub więcej znaków NameChar (zdefiniowanych również w specyfikacji XML).

  • id ma wartość "NULL" lub "VOID" lub "GARBAGE".

  • id zawiera co najmniej jeden nieprawidłowy znak identyfikatora reguły. Te znaki to: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<',> '[', '[', ']', '{', '}', '\', ', '\', '\r' i '\n'.

Zobacz też

Dotyczy

SrgsRule(String, SrgsElement[])

Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs
Źródło:
SrgsRule.cs

Inicjuje nowe wystąpienie SrgsRule klasy z tablicy SrgsElement obiektów.

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

Parametry

id
String

Identyfikator reguły.

elements
SrgsElement[]

Tablica SrgsElement elementów.

Wyjątki

Parametr id ma wartość null.

Parametr elements ma wartość null.

id nie jest prawidłowym identyfikatorem reguły.

Przykłady

W poniższym przykładzie tworzona jest gramatyka, która rozpoznaje frazę "Naród, który wygrał Puchar Świata", a następnie nazwę kraju, który wygrał Mistrzostwa Świata. W przykładzie tworzona jest reguła publiczna o nazwie WorldCupWinner. W tym przykładzie tworzone są dwa SrgsRule obiekty i ruleEuroperuleSAmerica , przekazując String element dla identyfikatora reguły i tablicę SrgsElement zawierającą SrgsOneOf obiekt. Następnie przykład dodaje odwołania reguły do ruleEurope i ruleSAmerica z reguły 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;
}

Utworzona gramatyka ma następujący formularz.

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

Uwagi

Konstruktor SrgsRule inicjuje Id właściwość . Identyfikator musi być unikatowy w ramach danej gramatyki.

Konstruktor SrgsRule zgłasza wyjątek FormatException w następujących okolicznościach:

  • id nie jest prawidłową nazwą XML zdefiniowaną w języku Extensible Markup Language (XML) 1.0 (piąta wersja). Aby sparafrazować tę definicję, prawidłowa nazwa XML musi zaczynać się literą, podkreśleniem ('_') lub dwukropkiem (':') i może być po nim zero lub więcej znaków NameChar (zdefiniowanych również w specyfikacji XML).

  • id ma wartość "NULL" lub "VOID" lub "GARBAGE".

  • id zawiera co najmniej jeden nieprawidłowy znak identyfikatora reguły. Te znaki to: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<',> '[', '[', ']', '{', '}', '\', ', '\', '\r' i '\n'.

Zobacz też

Dotyczy