Dela via


SrgsText Class

Definition

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
public class SrgsText : System.Speech.Recognition.SrgsGrammar.SrgsElement
[System.Serializable]
public class SrgsText : System.Speech.Recognition.SrgsGrammar.SrgsElement
type SrgsText = class
    inherit SrgsElement
[<System.Serializable>]
type SrgsText = class
    inherit SrgsElement
Public Class SrgsText
Inherits SrgsElement
Inheritance
Attributes

Examples

The following C# code example demonstrates how to use the SrgsText class to modify the textual contents of SrgsItem objects. 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();  

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>  

Remarks

The SrgsText class represents the text found within a set of SRGS element tags. 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. The Text object is then added to the Elements collection on the SrgsItem object.

Constructors

SrgsText()

Initializes a new instance of the SrgsText class.

SrgsText(String)

Initializes a new instance of the SrgsText class, specifying the text of the instance.

Properties

Text

Gets or sets the text contained within the SrgsText class instance.

Methods

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also