Sdílet prostřednictvím


SrgsRule Konstruktory

Definice

Inicializuje novou instanci SrgsRule třídy.

Přetížení

SrgsRule(String)

Inicializuje novou instanci SrgsRule třídy a určuje identifikátor pravidla.

SrgsRule(String, SrgsElement[])

Inicializuje novou instanci SrgsRule třídy z pole SrgsElement objektů.

SrgsRule(String)

Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs

Inicializuje novou instanci SrgsRule třídy a určuje identifikátor pravidla.

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

Identifikátor pravidla.

Výjimky

id je null.

id je prázdný.

id není správný identifikátor pravidla.

Příklady

Následující příklad vytvoří gramatiku, která rozpozná frázi "A nation that has has won the World Cup is" následovaný názvem země, která vyhrála mistrovství světa. Příklad vytvoří SrgsRule objekt s názvem winnerRule a předá identifikátor WorldCupWinner jako String. Objekt se SrgsOneOf skládá z pole nových SrgsItem objektů obsahujících alternativy, které mají být rozpoznány pravidlem.

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

Poznámky

Konstruktor SrgsRule inicializuje Id vlastnost. Identifikátor musí být jedinečný v rámci dané gramatiky.

Konstruktor SrgsRule vyvolá chybu FormatException v následujících případech:

  • idnení platný název XML, jak je definováno v jazyce XML (Extensible Markup Language) 1.0 (pátá edice). Aby bylo možné tuto definici parafrázovat, musí platný název XML začínat písmenem, podtržítkem ('_') nebo dvojtečka (':') a za ním může následovat nula nebo více znaků NameChar (také definovaných ve specifikaci XML).

  • id je "NULL" nebo "VOID" nebo "GARBAGE".

  • id obsahuje alespoň jeden neplatný znak ID pravidla. Tyto znaky jsou: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<',> '', '[', '], '{', '}', '\\', ' ', '\t', '\r' a '\n'.

Viz také

Platí pro

SrgsRule(String, SrgsElement[])

Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs
Zdroj:
SrgsRule.cs

Inicializuje novou instanci SrgsRule třídy z pole SrgsElement objektů.

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

Identifikátor pravidla.

elements
SrgsElement[]

Pole SrgsElement prvků.

Výjimky

id je null.

elements je null.

id je prázdný.

id není správný identifikátor pravidla.

Příklady

Následující příklad vytvoří gramatiku, která rozpozná frázi "A nation that has has won the World Cup is" následovaný názvem země, která vyhrála mistrovství světa. Příklad vytvoří veřejné pravidlo s názvem WorldCupWinner. Příklad pak vytvoří dva SrgsRule objekty ruleEurope a , ruleSAmericapředávající String identifikátor pravidla a SrgsElement pole obsahující SrgsOneOf objekt. Následně příklad přidá odkazy na pravidlo do ruleEurope a ruleSAmerica z pravidla 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;
}

Vytvořená gramatika má následující formulář.

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

Poznámky

Konstruktor SrgsRule inicializuje Id vlastnost. Identifikátor musí být jedinečný v rámci dané gramatiky.

Konstruktor SrgsRule vyvolá chybu FormatException v následujících případech:

  • idnení platný název XML, jak je definováno v jazyce XML (Extensible Markup Language) 1.0 (pátá edice). Aby bylo možné tuto definici parafrázovat, musí platný název XML začínat písmenem, podtržítkem ('_') nebo dvojtečka (':') a za ním může následovat nula nebo více znaků NameChar (také definovaných ve specifikaci XML).

  • id je "NULL" nebo "VOID" nebo "GARBAGE".

  • id obsahuje alespoň jeden neplatný znak ID pravidla. Tyto znaky jsou: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<',> '', '[', '], '{', '}', '\\', ' ', '\t', '\r' a '\n'.

Viz také

Platí pro