SrgsText 类
定义
表示语法元素的文本内容,这些语法元素根据万维网联合会 (W3C) 语音识别语法规范 (SRGS) 1.0 版进行定义。Represents the textual content of grammar elements defined by the World Wide Web Consortium (W3C) Speech Recognition Grammar Specification (SRGS) Version 1.0.
public ref class SrgsText : System::Speech::Recognition::SrgsGrammar::SrgsElement
[System.Serializable]
public class SrgsText : System.Speech.Recognition.SrgsGrammar.SrgsElement
[<System.Serializable>]
type SrgsText = class
inherit SrgsElement
Public Class SrgsText
Inherits SrgsElement
- 继承
- 属性
示例
下面的 c # 代码示例演示如何使用 SrgsText 类修改对象的文本内容 SrgsItem 。The following C# code example demonstrates how to use the SrgsText class to modify the textual contents of SrgsItem objects. 该示例将 SrgsItem 分别 (、和) 的对象的初始文本值更改 Large Larger Largest 为 Small 、 Medium 和 Large 。The example changes the initial text values of the SrgsItem objects (Large, Larger, and Largest) to Small, Medium, and Large, respectively.
// Create SrgsItem objects and specify their text.
SrgsItem smallItem = new SrgsItem("Large");
SrgsItem mediumItem = new SrgsItem("Larger");
SrgsItem largeItem = new SrgsItem("Largest");
SrgsText textOfItem = null;
// Change the text of smallItem.
if (smallItem.Elements[0] is SrgsText)
{
textOfItem = smallItem.Elements[0] as SrgsText;
textOfItem.Text = "Small";
}
// Change the text of mediumItem.
if (mediumItem.Elements[0] is SrgsText)
{
textOfItem = mediumItem.Elements[0] as SrgsText;
textOfItem.Text = "Medium";
}
// Change the text of largeItem.
if (largeItem.Elements[0] is SrgsText)
{
textOfItem = largeItem.Elements[0] as SrgsText;
textOfItem.Text = "Large";
}
// Create an SrgsOneOf object and add smallItem, mediumItem,
// and largeItem as alternatives.
SrgsOneOf itemSize = new SrgsOneOf(new SrgsItem[]
{ smallItem, mediumItem, largeItem });
// Create a new SrgsRule from the SrgsOneOf object, and specify its identifier.
SrgsRule size = new SrgsRule("Sizes", itemSize);
// Create an SrgsDocument object.
// Add the SrgsRule object to the collection of rules and make it the root rule.
SrgsDocument document = new SrgsDocument();
document.Rules.Add(size);
document.Root = size;
// Write the SrgsDocument to an XML grammar file.
string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
XmlWriter writer = XmlWriter.Create(srgsDocumentFile);
document.WriteSrgs(writer);
writer.Close();
下面演示了修改后的对象文本如何 SrgsItem 作为 item 元素显示在输出 XML 语法文件中。The following shows how the modified text of the SrgsItem objects would appear as item elements in the output XML grammar file.
<!-- SRGS XML Fragment -->
<one-of>
<item>Small</item>
<item>Medium</item>
<item>Large</item>
</one-of>
注解
SrgsText类表示在一组 SRGS 元素标记中找到的文本。The SrgsText class represents the text found within a set of SRGS element tags. 当 SrgsItem 使用参数构造对象时 String ,将创建一个 SrgsText 对象,并将其 Text 属性初始化为该参数的值。When an SrgsItem object is constructed with a String parameter, a SrgsText object is created with its Text property initialized to the value of that parameter. 然后,将 Text 对象添加到 Elements 对象的集合中 SrgsItem 。The Text object is then added to the Elements collection on the SrgsItem object.
构造函数
| SrgsText() |
初始化 SrgsText 类的新实例。Initializes a new instance of the SrgsText class. |
| SrgsText(String) |
在指定实例文本的情况下,初始化 SrgsText 类的新实例。Initializes a new instance of the SrgsText class, specifying the text of the instance. |
属性
| Text |
获取或设置 SrgsText 类实例内包含的文本。Gets or sets the text contained within the SrgsText class instance. |
方法
| CreateObjRef(Type) |
创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (继承自 MarshalByRefObject) |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetLifetimeService() |
已过时。
检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance. (继承自 MarshalByRefObject) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| InitializeLifetimeService() |
已过时。
获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance. (继承自 MarshalByRefObject) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| MemberwiseClone(Boolean) |
创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object. (继承自 MarshalByRefObject) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |