GrammarBuilder.AppendRuleReference Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Appends a grammar file or a grammar rule to the current sequence of grammar elements.
Overloads
AppendRuleReference(String) |
Appends a grammar definition file to the current sequence of grammar elements. |
AppendRuleReference(String, String) |
Appends the specified rule of a grammar definition file to the current sequence of grammar elements. |
Remarks
The AppendRuleReference methods can append a grammar file or a grammar rule from a file. These methods allow applications to make use of pre-deployed or publicly available grammar rules. The application must have read access to the location of specified grammar files.
These methods can read a speech recognition grammar from the following formats.
XML-format files that conform to the W3C Speech Recognition Grammar Specification (SRGS) Version 1.0
Binary files that conform to the Microsoft Speech Recognition Grammar Binary Format (.cfg file extension)
Compiling an XML-format SRGS grammar file to a binary grammar file with the .cfg extension can reduce the time consumed by searches for a match, especially if the grammar requires recognition of a large number of words and phrases. For information about compiling SRGS grammars to the CFG binary format, see SrgsGrammarCompiler.
AppendRuleReference(String)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Appends a grammar definition file to the current sequence of grammar elements.
public:
void AppendRuleReference(System::String ^ path);
public void AppendRuleReference (string path);
member this.AppendRuleReference : string -> unit
Public Sub AppendRuleReference (path As String)
Parameters
- path
- String
The path or Universal Resource Identifier (URI) of the file that describes a speech recognition grammar in a supported format.
Examples
The following C# example creates a speech recognition grammar that uses the rule named Cities
in a local SRGS file, cities.grxml. The content of the cities.grxml file appears below the C# code example.
private static Grammar CreateCitiesGrammar1()
{
GrammarBuilder builder = new GrammarBuilder();
builder.AppendRuleReference("file://c:/temp/cities.grxml");
Grammar citiesGrammar = new Grammar(builder);
citiesGrammar.Name = "Cities Grammar 1";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-16" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.grxml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item> Seattle </item>
<item> Los Angeles </item>
<item> New York </item>
<item> Miami </item>
</one-of>
</rule>
</grammar>
Remarks
The URI provided by the path
argument may be local or remote. The application must have read access to the location of specified grammar files.
A W3C Speech Recognition Grammar Specification (SRGS) representation can define a root rule. This method appends the grammar, beginning with its root rule, to the current sequence of grammar elements. To append a specific grammar rule, use the AppendRuleReference method.
See also
Applies to
AppendRuleReference(String, String)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Appends the specified rule of a grammar definition file to the current sequence of grammar elements.
public:
void AppendRuleReference(System::String ^ path, System::String ^ rule);
public void AppendRuleReference (string path, string rule);
member this.AppendRuleReference : string * string -> unit
Public Sub AppendRuleReference (path As String, rule As String)
Parameters
- path
- String
The file path or Universal Resource Identifier (URI) of the file that describes a speech recognition grammar in a supported format.
- rule
- String
The identifier of the rule to append, or null
to append the default root rule of the grammar file.
Examples
The following C# example creates a speech recognition grammar that uses the rule named Cities
in a local SRGS file, cities.grxml. The content of the cities.grxml file appears below the C# code example.
private static Grammar CreateCitiesGrammar2()
{
GrammarBuilder builder = new GrammarBuilder();
builder.Append("Does");
builder.AppendRuleReference(@"c:\temp\cities.grxml", "Cities");
builder.Append("have a shuttle");
Grammar citiesGrammar = new Grammar(builder);
citiesGrammar.Name = "Cities Grammar 2";
return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
tag-format="semantics/1.0" root="Main">
<!-- cities.grxml:
Defines an SRGS grammar for requesting a flight. This grammar includes
a Cities rule that lists the cities that can be used for departures
and destinations. -->
<rule id="Main">
<item>
I would like to fly from <ruleref uri="#Cities"/>
to <ruleref uri="#Cities"/>
</item>
</rule>
<rule id="Cities" scope="public">
<one-of>
<item> Seattle </item>
<item> Los Angeles </item>
<item> New York </item>
<item> Miami </item>
</one-of>
</rule>
</grammar>
Remarks
The URI provided by the path
argument may be local or remote. The application must have read access to the location of specified grammar files.
You can use the use the AppendRuleReference method to append a grammar file beginning with its root rule.
See also
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기