SrgsRule Konstruktorer

Definition

Initierar en ny instans av SrgsRule klassen.

Överlagringar

Name Description
SrgsRule(String)

Initierar en ny instans av SrgsRule klassen och anger regelns identifierare.

SrgsRule(String, SrgsElement[])

Initierar en ny instans av SrgsRule klassen från en matris med SrgsElement objekt.

SrgsRule(String)

Källa:
SrgsRule.cs
Källa:
SrgsRule.cs
Källa:
SrgsRule.cs
Källa:
SrgsRule.cs

Initierar en ny instans av SrgsRule klassen och anger regelns identifierare.

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)

Parametrar

id
String

Regelns identifierare.

Undantag

id är null.

id är inte en korrekt regelidentifierare.

Exempel

I följande exempel skapas en grammatik som känner igen frasen "En nation som har vunnit VM är" följt av namnet på ett land som har vunnit VM. Exemplet skapar ett SrgsRule objekt med namnet winnerRule och skickar i identifieraren WorldCupWinner som en String. Objektet SrgsOneOf består av en matris med nya SrgsItem objekt som innehåller alternativ som ska identifieras av regeln.

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

Kommentarer

Konstruktorn SrgsRule initierar Id egenskapen. Identifieraren måste vara unik inom en viss grammatik.

Konstruktorn SrgsRule kastar en FormatException under följande omständigheter:

  • idär inte ett giltigt XML-namn enligt definitionen i XML 1.0 (Femte utgåvan). Om du vill parafrasera den här definitionen måste ett giltigt XML-namn börja med en bokstav, ett understreck ('_') eller ett kolon (':') och kan följas av noll eller fler namndiagramtecken (även definierat i XML-specifikationen).

  • id är "NULL" eller "VOID" eller "GARBAGE".

  • id innehåller minst ett ogiltigt regel-ID-tecken. De här tecknen är: '?', '*', '+', '|', '(', '^', '$', '/', ';', '.', '=', '<', '>', '[', ']', '{', '}', '\\', ', '\t', '\r' och '\n'.

Se även

Gäller för

SrgsRule(String, SrgsElement[])

Källa:
SrgsRule.cs
Källa:
SrgsRule.cs
Källa:
SrgsRule.cs
Källa:
SrgsRule.cs

Initierar en ny instans av SrgsRule klassen från en matris med 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())

Parametrar

id
String

Regelns identifierare.

elements
SrgsElement[]

En matris med SrgsElement element.

Undantag

id är null.

elements är null.

id är inte en korrekt regelidentifierare.

Exempel

I följande exempel skapas en grammatik som känner igen frasen "En nation som har vunnit VM är" följt av namnet på ett land som har vunnit VM. I exemplet skapas en offentlig regel med namnet WorldCupWinner. Exemplet skapar sedan två SrgsRule objekt och ruleEuroperuleSAmerica skickar en String för regelidentifieraren och en SrgsElement matris som innehåller ett SrgsOneOf objekt. Därefter lägger exemplet till regelreferenser till ruleEurope och ruleSAmerica från regeln 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;
}

Den skapade grammatiken har följande formulär.

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

Kommentarer

Konstruktorn SrgsRule initierar Id egenskapen. Identifieraren måste vara unik inom en viss grammatik.

Konstruktorn SrgsRule kastar en FormatException under följande omständigheter:

  • idär inte ett giltigt XML-namn enligt definitionen i XML 1.0 (Femte utgåvan). Om du vill parafrasera den här definitionen måste ett giltigt XML-namn börja med en bokstav, ett understreck ('_') eller ett kolon (':') och kan följas av noll eller fler namndiagramtecken (även definierat i XML-specifikationen).

  • id är "NULL" eller "VOID" eller "GARBAGE".

  • id innehåller minst ett ogiltigt regel-ID-tecken. De här tecknen är: '?', '*', '+', '|', '(', '^', '$', '/', ';', '.', '=', '<', '>', '[', ']', '{', '}', '\\', ', '\t', '\r' och '\n'.

Se även

Gäller för