SrgsDocument Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru dari kelas SrgsDocument.
Overload
| Nama | Deskripsi |
|---|---|
| SrgsDocument() |
Menginisialisasi instans baru dari kelas SrgsDocument. |
| SrgsDocument(GrammarBuilder) |
Menginisialisasi instans SrgsDocument baru kelas dari GrammarBuilder objek. |
| SrgsDocument(SrgsRule) |
Menginisialisasi instans SrgsDocument baru kelas dan menentukan objek untuk SrgsRule menjadi aturan akar tata bahasa. |
| SrgsDocument(String) |
Menginisialisasi instans SrgsDocument baru kelas yang menentukan lokasi dokumen XML yang digunakan untuk mengisi SrgsDocument instans. |
| SrgsDocument(XmlReader) |
Menginisialisasi instans SrgsDocument baru kelas dari instans XmlReader yang mereferensikan file tata bahasa format XML. |
Keterangan
Dengan menggunakan konstruktor untuk kelas , SrgsDocument Anda dapat membuat instans SrgsDocument dari GrammarBuilder, , SrgsRuleatau XmlReader objek, dari string yang berisi jalur ke tata bahasa format XML, atau Anda dapat memulai instans kosong .SrgsDocument
SrgsDocument()
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
Menginisialisasi instans baru dari kelas SrgsDocument.
public:
SrgsDocument();
public SrgsDocument();
Public Sub New ()
Contoh
Contoh berikut membuat SrgsDocument objek lalu membuat aturan publik bernama winnerRule. Kemudian menciptakan yang SrgsItem terdiri dari string "Negara yang telah memenangkan Piala Dunia adalah:", dan menambahkan item ini ke Elements properti aturan. Contoh kemudian membuat dua aturan lagi (ruleEurope dan ruleSAmerica), yang masing-masing adalah SrgsOneOf objek yang berisi tiga SrgsItem objek. Setelah itu, objek lain SrgsOneOf dibuat yang berisi SrgsRuleRef objek yang merujuk ke ruleEurope dan ruleSAmerica. Objek baru SrgsOneOf kemudian ditambahkan ke Elements properti .winnerRule Setelah ini, ketiga aturan (winnerRule, , dan ruleSAmerica) ditambahkan ke Rules properti .SrgsDocumentruleEurope Akhirnya, ketiga aturan dikompilasi menjadi representasi biner tata bahasa.
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);
}
}
Keterangan
Konstruktor ini membuat instans kosong SrgsDocument . Untuk membangun tata bahasa dalam instans kosongSrgsDocument, tambahkan instans kelas yang mewakili elemen SRGS, seperti SrgsRule, , SrgsRuleRefSrgsOneOf, dan SrgsItem.
Berlaku untuk
SrgsDocument(GrammarBuilder)
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
Menginisialisasi instans SrgsDocument baru kelas dari GrammarBuilder objek.
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)
Parameter
- builder
- GrammarBuilder
Objek yang GrammarBuilder digunakan untuk membuat SrgsDocument instans.
Pengecualian
builder adalah null.
Contoh
Contoh berikut membangun tata bahasa dalam GrammarBuilder instans menggunakan Choices objek. Kemudian membuat SrgsDocument dari GrammarBuilder objek .
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);
Berlaku untuk
SrgsDocument(SrgsRule)
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
Menginisialisasi instans SrgsDocument baru kelas dan menentukan objek untuk SrgsRule menjadi aturan akar tata bahasa.
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)
Parameter
- grammarRootRule
- SrgsRule
Di root rule dalam SrgsDocument objek.
Pengecualian
grammarRootRule adalah null.
Contoh
Contoh berikut membuat dua aturan (chooseCities dan destCities) untuk memilih kota asal dan tujuan untuk penerbangan. Contoh ini menginisialisasi instans SrgsDocument menggunakan chooseCities aturan sebagai argumen. Contoh menulis konten kumpulan aturan dan nama aturan akar ke konsol.
// 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);
Keterangan
Konstruktor ini menambahkan aturan yang ditentukan ke SrgsRulesCollectionSrgsDocument objek dan mengaturnya sebagai Root aturan untuk tata bahasa.
Berlaku untuk
SrgsDocument(String)
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
Menginisialisasi instans SrgsDocument baru kelas yang menentukan lokasi dokumen XML yang digunakan untuk mengisi SrgsDocument instans.
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)
Parameter
- path
- String
Lokasi file XML SRGS.
Pengecualian
path adalah null.
path adalah string kosong.
Contoh
Contoh berikut membuat baru SrgsDocument dari file bernama "srgsDocumentFile.xml".
string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
SrgsDocument document = null;
if (File.Exists(srgsDocumentFile))
document = new SrgsDocument(srgsDocumentFile);
Keterangan
Penting
Menggunakan instans jenis ini dengan data yang tidak tepercaya adalah risiko keamanan. Gunakan objek ini hanya dengan data tepercaya. Untuk informasi selengkapnya, lihat Memvalidasi Semua Input.
Berlaku untuk
SrgsDocument(XmlReader)
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
- Sumber:
- SrgsDocument.cs
Menginisialisasi instans SrgsDocument baru kelas dari instans XmlReader yang mereferensikan file tata bahasa format 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)
Parameter
- srgsGrammar
- XmlReader
Objek XmlReader yang dibuat dengan SrgsDocument instans XML.
Pengecualian
srgsGrammar adalah null.
Contoh
Contoh berikut membuat instans baru dari SrgsDocument instans XmlReader yang mereferensikan file "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();
}
Keterangan
Penting
Menggunakan instans jenis ini dengan data yang tidak tepercaya adalah risiko keamanan. Gunakan objek ini hanya dengan data tepercaya. Untuk informasi selengkapnya, lihat Memvalidasi Semua Input.