SrgsDocument Konstruktorer

Definition

Initierar en ny instans av SrgsDocument klassen.

Överlagringar

Name Description
SrgsDocument()

Initierar en ny instans av SrgsDocument klassen.

SrgsDocument(GrammarBuilder)

Initierar en ny instans av SrgsDocument klassen från ett GrammarBuilder objekt.

SrgsDocument(SrgsRule)

Initierar en ny instans av SrgsDocument klassen och anger ett SrgsRule objekt som ska vara rotregeln för grammatiken.

SrgsDocument(String)

Initierar en ny instans av SrgsDocument klassen som anger platsen för DET XML-dokument som används för att fylla i instansen SrgsDocument .

SrgsDocument(XmlReader)

Initierar en ny instans av SrgsDocument klassen från en instans av XmlReader som refererar till en grammatikfil i XML-format.

Kommentarer

Med hjälp av konstruktorerna för SrgsDocument klassen kan du skapa en instans av SrgsDocument från ett GrammarBuilder, SrgsRuleeller XmlReader -objekt, från en sträng som innehåller sökvägen till en XML-format grammatik, eller så kan du initiera en tom instans av SrgsDocument.

SrgsDocument()

Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs

Initierar en ny instans av SrgsDocument klassen.

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

Exempel

I följande exempel skapas ett SrgsDocument objekt och sedan skapas en offentlig regel med namnet winnerRule. Sedan skapas en SrgsItem som består av strängen "A nation that has won the World Cup is:" och lägger till det här objektet i Elements regelns egenskap. Exemplet skapar sedan ytterligare två regler (ruleEurope och ), som var och ruleSAmericaen är ett SrgsOneOf objekt som innehåller tre SrgsItem objekt. Därefter skapas ett annat SrgsOneOf objekt som innehåller SrgsRuleRef objekt som refererar till ruleEurope och ruleSAmerica. Det nya SrgsOneOf objektet läggs sedan till i Elements egenskapen winnerRule. Därefter läggs alla tre reglerna (winnerRule, ruleEuropeoch ruleSAmerica) till i Rules egenskapen SrgsDocument. Slutligen kompileras de tre reglerna till en binär representation av grammatiken.

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

Kommentarer

Den här konstruktorn skapar en tom SrgsDocument instans. Om du vill skapa en grammatik i en tom SrgsDocument instans lägger du till instanser av klasser som representerar SRGS-element, till exempel SrgsRule, SrgsRuleRef, SrgsOneOfoch SrgsItem.

Gäller för

SrgsDocument(GrammarBuilder)

Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs

Initierar en ny instans av SrgsDocument klassen från ett GrammarBuilder objekt.

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)

Parametrar

builder
GrammarBuilder

Objektet GrammarBuilder som användes för att skapa instansen SrgsDocument .

Undantag

builder är null.

Exempel

I följande exempel skapas en grammatik i en GrammarBuilder instans med hjälp av Choices objekt. Sedan skapas en SrgsDocument från objektet GrammarBuilder .

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

Gäller för

SrgsDocument(SrgsRule)

Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs

Initierar en ny instans av SrgsDocument klassen och anger ett SrgsRule objekt som ska vara rotregeln för grammatiken.

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)

Parametrar

grammarRootRule
SrgsRule

I root rule - SrgsDocument objektet.

Undantag

grammarRootRule är null.

Exempel

I följande exempel skapas två regler (chooseCities och destCities) för att välja ursprung och målstäder för en flygning. Exemplet initierar instansen SrgsDocument med hjälp av chooseCities regeln som ett argument. I exemplet skrivs innehållet i regelsamlingen och namnet på rotregeln till konsolen.

// 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);

Kommentarer

Den här konstruktorn lägger till den angivna regeln i SrgsRulesCollectionSrgsDocument objektet och anger den Root som regel för grammatiken.

Gäller för

SrgsDocument(String)

Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs

Initierar en ny instans av SrgsDocument klassen som anger platsen för DET XML-dokument som används för att fylla i instansen SrgsDocument .

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)

Parametrar

path
String

Platsen för SRGS XML-filen.

Undantag

path är null.

path är en tom sträng.

Exempel

I följande exempel skapas en ny SrgsDocument från filen med namnet "srgsDocumentFile.xml".

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

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

Kommentarer

Important

Att använda en instans av den här typen med ej betrodda data är en säkerhetsrisk. Använd endast det här objektet med betrodda data. För mer information, se Verifiera alla indata.

Gäller för

SrgsDocument(XmlReader)

Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs
Källa:
SrgsDocument.cs

Initierar en ny instans av SrgsDocument klassen från en instans av XmlReader som refererar till en grammatikfil i XML-format.

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)

Parametrar

srgsGrammar
XmlReader

Objektet XmlReader som skapades med XML-instansen SrgsDocument .

Undantag

srgsGrammar är null.

Exempel

I följande exempel skapas en ny instans av SrgsDocument från en instans av XmlReader som refererar till filen "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();
}

Kommentarer

Important

Att använda en instans av den här typen med ej betrodda data är en säkerhetsrisk. Använd endast det här objektet med betrodda data. För mer information, se Verifiera alla indata.

Gäller för