SrgsDocument Konstruktory

Definice

Inicializuje novou instanci SrgsDocument třídy.

Přetížení

Name Description
SrgsDocument()

Inicializuje novou instanci SrgsDocument třídy.

SrgsDocument(GrammarBuilder)

Inicializuje novou instanci SrgsDocument třídy z objektu GrammarBuilder .

SrgsDocument(SrgsRule)

Inicializuje novou instanci SrgsDocument třídy a určuje SrgsRule objekt, který má být kořenovým pravidlem gramatiky.

SrgsDocument(String)

Inicializuje novou instanci SrgsDocument třídy určující umístění dokumentu XML, který se používá k vyplnění SrgsDocument instance.

SrgsDocument(XmlReader)

Inicializuje novou instanci SrgsDocument třídy z instance XmlReader , která odkazuje na gramatický soubor ve formátu XML.

Poznámky

Pomocí konstruktorů pro SrgsDocument třídu můžete vytvořit instanci SrgsDocument z objektu GrammarBuilder, SrgsRulenebo XmlReader z řetězce, který obsahuje cestu k gramatikě formátu XML, nebo můžete zahájit prázdnou instanci SrgsDocument.

SrgsDocument()

Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs

Inicializuje novou instanci SrgsDocument třídy.

public:
 SrgsDocument();
public SrgsDocument();
Public Sub New ()

Příklady

Následující příklad vytvoří SrgsDocument objekt a pak vytvoří veřejné pravidlo s názvem winnerRule. Pak vytvoří SrgsItem , který se skládá z řetězce "Národ, který vyhrál Světový pohár je:" a přidá tuto položku do Elements vlastnosti pravidla. Příklad pak vytvoří dvě další pravidla (ruleEurope a ruleSAmerica), z nichž každý je SrgsOneOf objekt, který obsahuje tři SrgsItem objekty. Potom se vytvoří jiný SrgsOneOf objekt, který obsahuje SrgsRuleRef objekty odkazující na ruleEurope a ruleSAmerica. SrgsOneOf Nový objekt se pak přidá do Elements vlastnosti winnerRule. Za tímto účelem jsou do vlastnosti přidána winnerRulevšechna tři pravidla (ruleEurope, ruleSAmericaa Rules) .SrgsDocument Nakonec se tři pravidla kompilují do binární reprezentace gramatiky.

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;

  String fileName = Path.GetTempFileName();
  using (FileStream stream = new FileStream(fileName, FileMode.Create))
  {

    // Compile the grammar to a binary format.
    SrgsGrammarCompiler.Compile(document, stream);
  }
}

Poznámky

Tento konstruktor vytvoří prázdnou SrgsDocument instanci. Chcete-li vytvořit gramatiku v prázdné SrgsDocument instanci, přidejte instance tříd, které představují prvky SRGS, například SrgsRule, SrgsRuleRef, SrgsOneOfa SrgsItem.

Platí pro

SrgsDocument(GrammarBuilder)

Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs

Inicializuje novou instanci SrgsDocument třídy z objektu GrammarBuilder .

public:
 SrgsDocument(System::Speech::Recognition::GrammarBuilder ^ builder);
public SrgsDocument(System.Speech.Recognition.GrammarBuilder builder);
new System.Speech.Recognition.SrgsGrammar.SrgsDocument : System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.SrgsGrammar.SrgsDocument
Public Sub New (builder As GrammarBuilder)

Parametry

builder
GrammarBuilder

Objekt GrammarBuilder použitý k vytvoření SrgsDocument instance.

Výjimky

builder je null.

Příklady

Následující příklad vytvoří gramatiku GrammarBuilder v instanci pomocí Choices objektů. Potom z SrgsDocument objektu GrammarBuilder vytvoří objekt.

GrammarBuilder builder = null;

// Create new Choices objects and add countries/regions, and create GrammarBuilder objects.
Choices choicesEurope = new Choices(new string[] { "England", "France", "Germany", "Italy" });
GrammarBuilder europe = new GrammarBuilder(choicesEurope);

Choices choicesSAmerica = new Choices(new string[] { "Argentina", "Brazil", "Uruguay" });
GrammarBuilder sAmerica = new GrammarBuilder(choicesSAmerica);

Choices worldCupWinnerChoices = new Choices(new GrammarBuilder[] {choicesEurope, choicesSAmerica});

// Create new GrammarBuilder from a Choices object.
builder = new GrammarBuilder(worldCupWinnerChoices);

// Create an SrgsDocument object from a GrammarBuilder object.
SrgsDocument document = new SrgsDocument(builder);

Platí pro

SrgsDocument(SrgsRule)

Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs

Inicializuje novou instanci SrgsDocument třídy a určuje SrgsRule objekt, který má být kořenovým pravidlem gramatiky.

public:
 SrgsDocument(System::Speech::Recognition::SrgsGrammar::SrgsRule ^ grammarRootRule);
public SrgsDocument(System.Speech.Recognition.SrgsGrammar.SrgsRule grammarRootRule);
new System.Speech.Recognition.SrgsGrammar.SrgsDocument : System.Speech.Recognition.SrgsGrammar.SrgsRule -> System.Speech.Recognition.SrgsGrammar.SrgsDocument
Public Sub New (grammarRootRule As SrgsRule)

Parametry

grammarRootRule
SrgsRule

Objekt root rule je v objektu SrgsDocument .

Výjimky

grammarRootRule je null.

Příklady

Následující příklad vytvoří dvě pravidla (chooseCities a destCities) pro výběr počátečního a cílového města pro let. Příklad inicializuje SrgsDocument instanci pomocí chooseCities pravidla jako argumentu. Příklad zapíše obsah kolekce pravidel a název kořenového pravidla do konzoly.

// Create a rule that contains a list of destination cities.
SrgsRule destCities = new SrgsRule("Destination");
SrgsOneOf toCities = new SrgsOneOf(new string[] { "New York", "Seattle", "Denver" });
destCities.Add(toCities);

// Create a list of origin cities and supporting phrases.
SrgsOneOf fromCities = new SrgsOneOf(new SrgsItem[] {
  new SrgsItem("Dallas"), new SrgsItem("Miami"), new SrgsItem("Chicago") });
SrgsItem intro = new SrgsItem("I want to fly from");
SrgsItem to = new SrgsItem("to");

// Create the root rule of the grammar, and assemble the components.
SrgsRule chooseCities = new SrgsRule("Trip");
chooseCities.Add(intro);
chooseCities.Add(fromCities);
chooseCities.Add(to);
chooseCities.Add(new SrgsRuleRef(destCities));

// Create the SrgsDocument and specify the root rule to add.
SrgsDocument bookFlight = new SrgsDocument(chooseCities);

// Add the rule for the destination cities to the document's rule collection.
bookFlight.Rules.Add(new SrgsRule[] { destCities });

// Display the contents of the Rules collection and the name of the root rule.
foreach (SrgsRule rule in bookFlight.Rules)
{
  Console.WriteLine("Rule " + rule.Id + " is in the rules collection");
}
Console.WriteLine("Root Rule " + bookFlight.Root.Id);

// Create a Grammar object and load it to the recognizer.
Grammar g = new Grammar(bookFlight);
g.Name = ("City Chooser");
recognizer.LoadGrammarAsync(g);

Poznámky

Tento konstruktor přidá zadané pravidlo do SrgsRulesCollection objektu SrgsDocument a nastaví ho jako Root pravidlo pro gramatiku.

Platí pro

SrgsDocument(String)

Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs

Inicializuje novou instanci SrgsDocument třídy určující umístění dokumentu XML, který se používá k vyplnění SrgsDocument instance.

public:
 SrgsDocument(System::String ^ path);
public SrgsDocument(string path);
new System.Speech.Recognition.SrgsGrammar.SrgsDocument : string -> System.Speech.Recognition.SrgsGrammar.SrgsDocument
Public Sub New (path As String)

Parametry

path
String

Umístění souboru XML SRGS.

Výjimky

path je null.

path je prázdný řetězec.

Příklady

Následující příklad vytvoří nový SrgsDocument ze souboru s názvem "srgsDocumentFile.xml".

string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
SrgsDocument document = null;

if (File.Exists(srgsDocumentFile))
   document = new SrgsDocument(srgsDocumentFile);

Poznámky

Důležité

Použití instance tohoto typu s nedůvěryhodnými daty představuje bezpečnostní riziko. Tento objekt použijte pouze s důvěryhodnými daty. Další informace naleznete v tématu Ověření všech vstupů.

Platí pro

SrgsDocument(XmlReader)

Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs
Zdroj:
SrgsDocument.cs

Inicializuje novou instanci SrgsDocument třídy z instance XmlReader , která odkazuje na gramatický soubor ve formátu XML.

public:
 SrgsDocument(System::Xml::XmlReader ^ srgsGrammar);
public SrgsDocument(System.Xml.XmlReader srgsGrammar);
new System.Speech.Recognition.SrgsGrammar.SrgsDocument : System.Xml.XmlReader -> System.Speech.Recognition.SrgsGrammar.SrgsDocument
Public Sub New (srgsGrammar As XmlReader)

Parametry

srgsGrammar
XmlReader

Objekt XmlReader , který byl vytvořen s SrgsDocument instancí XML.

Výjimky

srgsGrammar je null.

Příklady

Následující příklad vytvoří novou instanci z instance SrgsDocumentXmlReader , která odkazuje na soubor "srgsDocumentFile.xml".

string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
SrgsDocument document = null;

if (File.Exists(srgsDocumentFile))
{
  XmlReader reader = XmlReader.Create(srgsDocumentFile);
  document = new SrgsDocument(reader);
  reader.Close();
}

Poznámky

Důležité

Použití instance tohoto typu s nedůvěryhodnými daty představuje bezpečnostní riziko. Tento objekt použijte pouze s důvěryhodnými daty. Další informace naleznete v tématu Ověření všech vstupů.

Platí pro