SrgsDocument コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SrgsDocument クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| SrgsDocument() |
SrgsDocument クラスの新しいインスタンスを初期化します。 |
| SrgsDocument(GrammarBuilder) |
GrammarBuilder オブジェクトからSrgsDocument クラスの新しいインスタンスを初期化します。 |
| SrgsDocument(SrgsRule) |
SrgsDocument クラスの新しいインスタンスを初期化し、SrgsRule オブジェクトを文法のルート 規則として指定します。 |
| SrgsDocument(String) |
SrgsDocument インスタンスの入力に使用する XML ドキュメントの場所を指定して、SrgsDocument クラスの新しいインスタンスを初期化します。 |
| SrgsDocument(XmlReader) |
XML 形式の文法ファイルを参照するXmlReaderのインスタンスから、SrgsDocument クラスの新しいインスタンスを初期化します。 |
注釈
SrgsDocument クラスのコンストラクターを使用すると、XML 形式の文法へのパスを含む文字列から、GrammarBuilder、SrgsRule、またはXmlReader オブジェクトからSrgsDocumentのインスタンスを作成したり、SrgsDocumentの空のインスタンスを開始したりできます。
SrgsDocument()
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
SrgsDocument クラスの新しいインスタンスを初期化します。
public:
SrgsDocument();
public SrgsDocument();
Public Sub New ()
例
次の例では、 SrgsDocument オブジェクトを作成し、 winnerRuleという名前のパブリック ルールを作成します。 次に、"A nation that has the world Cup is:" という文字列で構成される SrgsItem を作成し、ルールの Elements プロパティにこの項目を追加します。 次に、さらに 2 つのルール (ruleEuropeとruleSAmerica) を作成し、それぞれが 3 つのSrgsItem オブジェクトを含むSrgsOneOf オブジェクトです。 その後、ruleEuropeとruleSAmericaを参照するSrgsRuleRefオブジェクトを含む別のSrgsOneOf オブジェクトが作成されます。 その後、新しいSrgsOneOf オブジェクトがwinnerRuleのElements プロパティに追加されます。 その後、3 つのルール (winnerRule、ruleEurope、ruleSAmerica) がすべて、SrgsDocumentのRules プロパティに追加されます。 最後に、3 つの規則は文法のバイナリ表現にコンパイルされます。
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);
}
}
注釈
このコンストラクターは、空の SrgsDocument インスタンスを作成します。 空の SrgsDocument インスタンス内に文法を構築するには、 SrgsRule、 SrgsRuleRef、 SrgsOneOf、 SrgsItemなど、SRGS 要素を表すクラスのインスタンスを追加します。
適用対象
SrgsDocument(GrammarBuilder)
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
GrammarBuilder オブジェクトからSrgsDocument クラスの新しいインスタンスを初期化します。
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)
パラメーター
- builder
- GrammarBuilder
SrgsDocument インスタンスの作成に使用するGrammarBuilder オブジェクト。
例外
builder は nullです。
例
次の例では、Choices オブジェクトを使用して、GrammarBuilder インスタンスに文法を作成します。 次に、GrammarBuilder オブジェクトからSrgsDocumentを作成します。
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);
適用対象
SrgsDocument(SrgsRule)
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
SrgsDocument クラスの新しいインスタンスを初期化し、SrgsRule オブジェクトを文法のルート 規則として指定します。
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)
パラメーター
- grammarRootRule
- SrgsRule
SrgsDocument オブジェクト内のroot rule。
例外
grammarRootRule は nullです。
例
次の例では、フライトの出発地と目的地を選択するための 2 つのルール (chooseCities と destCities) を作成します。 この例では、chooseCities 規則を引数として使用して、SrgsDocument インスタンスを初期化します。 この例では、ルール コレクションの内容とルート 規則の名前をコンソールに書き込みます。
// 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);
注釈
このコンストラクターは、指定した規則をSrgsDocument オブジェクトのSrgsRulesCollectionに追加し、文法のRoot規則として設定します。
適用対象
SrgsDocument(String)
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
SrgsDocument インスタンスの入力に使用する XML ドキュメントの場所を指定して、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)
パラメーター
- path
- String
SRGS XML ファイルの場所。
例外
path は nullです。
path は空の文字列です。
例
次の例では、"srgsDocumentFile.xml" という名前のファイルから新しい SrgsDocument を作成します。
string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
SrgsDocument document = null;
if (File.Exists(srgsDocumentFile))
document = new SrgsDocument(srgsDocumentFile);
注釈
Important
信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。
適用対象
SrgsDocument(XmlReader)
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
- ソース:
- SrgsDocument.cs
XML 形式の文法ファイルを参照するXmlReaderのインスタンスから、SrgsDocument クラスの新しいインスタンスを初期化します。
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)
パラメーター
- srgsGrammar
- XmlReader
SrgsDocument XML インスタンスで作成されたXmlReader オブジェクト。
例外
srgsGrammar は nullです。
例
次の例では、ファイル "srgsDocumentFile.xml" を参照するXmlReaderのインスタンスからSrgsDocumentの新しいインスタンスを作成します。
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();
}
注釈
Important
信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。