Aracılığıyla paylaş


SrgsDocument Oluşturucular

Tanım

SrgsDocument sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

SrgsDocument()

SrgsDocument sınıfının yeni bir örneğini başlatır.

SrgsDocument(GrammarBuilder)

Bir nesneden sınıfının yeni bir örneğini başlatır SrgsDocument GrammarBuilder .

SrgsDocument(SrgsRule)

Sınıfının yeni bir örneğini başlatır SrgsDocument ve SrgsRule dilbilgisinin kök kuralı olacak bir nesne belirtir.

SrgsDocument(String)

SrgsDocumentÖrneği doldurmanız için kullanılan XML belgesinin konumunu belirten sınıfının yeni bir örneğini başlatır SrgsDocument .

SrgsDocument(XmlReader)

SrgsDocument XmlReader XML biçimindeki dilbilgisi dosyasına başvuran bir örneğinden sınıfının yeni bir örneğini başlatır.

Açıklamalar

Sınıf için oluşturucuları kullanarak, SrgsDocument SrgsDocument bir GrammarBuilder , SrgsRule , veya XmlReader nesnesinden, XML biçimindeki bir dilbilgisine yol içeren bir dizeden bir örneği oluşturabilir veya boş bir örneği başlatabilirsiniz SrgsDocument .

SrgsDocument()

SrgsDocument sınıfının yeni bir örneğini başlatır.

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

Örnekler

Aşağıdaki örnek bir nesnesi oluşturur SrgsDocument ve sonra adlı ortak bir kural oluşturur winnerRule . Daha sonra SrgsItem , "Dünya Kupa 'ı kazandığı bir ulus:" dizesinden oluşan bir dize oluşturur ve bu öğeyi Elements kuralın özelliğine ekler. Daha sonra örnek ruleEurope ruleSAmerica , her biri SrgsOneOf üç nesne içeren bir nesne olan iki daha fazla kural (ve) oluşturur SrgsItem . Bundan sonra, SrgsOneOf SrgsRuleRef ve öğesine başvuran nesneleri içeren başka bir nesne oluşturulur ruleEurope ruleSAmerica . Yeni SrgsOneOf nesne daha sonra Elements özelliğine eklenir winnerRule . Bundan sonra, üç kural ( winnerRule , ruleEurope , ve ruleSAmerica ) özelliğine eklenir Rules SrgsDocument . Son olarak, üç kural, dilbilgisinin ikili gösterimine derlenir.

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

Açıklamalar

Bu Oluşturucu boş bir SrgsDocument örnek oluşturur. Boş bir örnek içinde dilbilgisi oluşturmak için,, SrgsDocument ve gibi srgs öğelerini temsil eden sınıfların örneklerini ekleyin SrgsRule SrgsRuleRef SrgsOneOf SrgsItem .

Şunlara uygulanır

SrgsDocument(GrammarBuilder)

Bir nesneden sınıfının yeni bir örneğini başlatır SrgsDocument 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)

Parametreler

builder
GrammarBuilder

GrammarBuilderÖrneği oluşturmak için kullanılan nesne SrgsDocument .

Özel durumlar

builder, null değeridir.

Örnekler

Aşağıdaki örnek, GrammarBuilder nesneleri kullanarak bir örnekte dilbilgisi oluşturur Choices . Bundan sonra nesnesinden bir oluşturur SrgsDocument 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);  

Şunlara uygulanır

SrgsDocument(SrgsRule)

Sınıfının yeni bir örneğini başlatır SrgsDocument ve SrgsRule dilbilgisinin kök kuralı olacak bir nesne belirtir.

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)

Parametreler

grammarRootRule
SrgsRule

root rule SrgsDocument Nesnesi.

Özel durumlar

grammarRootRule, null değeridir.

Örnekler

Aşağıdaki örnek, chooseCities destCities bir uçuş için kaynak ve hedef şehirleri seçmek üzere iki kural (ve) oluşturur. Örnek, SrgsDocument chooseCities kuralı bir bağımsız değişken olarak kullanarak örneğini başlatır. Örnek, kurallar koleksiyonunun içeriğini ve kök kuralın adını konsola yazar.

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

Açıklamalar

Bu Oluşturucu, belirtilen kuralı nesnenin öğesine ekler SrgsRulesCollection SrgsDocument ve Root dilbilgisinde kural olarak ayarlar.

Şunlara uygulanır

SrgsDocument(String)

SrgsDocumentÖrneği doldurmanız için kullanılan XML belgesinin konumunu belirten sınıfının yeni bir örneğini başlatır 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)

Parametreler

path
String

SRGS XML dosyasının konumu.

Özel durumlar

path, null değeridir.

path boş bir dizedir.

Örnekler

Aşağıdaki örnek, SrgsDocument "srgsDocumentFile.xml" adlı dosyadan yeni bir oluşturur.

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

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

Şunlara uygulanır

SrgsDocument(XmlReader)

SrgsDocument XmlReader XML biçimindeki dilbilgisi dosyasına başvuran bir örneğinden sınıfının yeni bir örneğini başlatır.

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)

Parametreler

srgsGrammar
XmlReader

XmlReader SrgsDocument XML örneğiyle oluşturulan nesne.

Özel durumlar

srgsGrammar, null değeridir.

Örnekler

Aşağıdaki örnek, SrgsDocument XmlReader "srgsDocumentFile.xml" dosyasına başvuran bir örneğinden yeni bir örneğini oluşturur.

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

Şunlara uygulanır