Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Recognition / SrgsGrammar / SrgsDocument.cs / 1 / SrgsDocument.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // // History: // 5/1/2004 jeanfp Created from the Kurosawa Code //--------------------------------------------------------------------------- using System; using System.Globalization; using System.ComponentModel; using System.Collections.ObjectModel; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Xml; using System.Collections.Generic; using System.Speech.Internal; using System.Speech.Internal.SrgsCompiler; using System.Speech.Internal.SrgsParser; #pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages. namespace System.Speech.Recognition.SrgsGrammar { ////// This class allows a _grammar to be specified in SRGS form. /// APITODO: needs programmatic access to SRGS dom; PACOG /// APITODO: needs rule activation/deactivation methods /// [Serializable] public class SrgsDocument { //******************************************************************* // // Constructors / Destructors // //******************************************************************* #region Constructors / Destructors ////// The default constructor - creates an empty SrgsGrammar object /// public SrgsDocument () { _grammar = new SrgsGrammar (); } ////// /// /// public SrgsDocument (string path) { Helpers.ThrowIfEmptyOrNull (path, "path"); using (XmlTextReader reader = new XmlTextReader (path)) { Load (reader); } } ////// TODOC /// /// public SrgsDocument (XmlReader srgsGrammar) { Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar"); Load (srgsGrammar); } #if !SPEECHSERVER && !NO_GRAMMAR_BUILDER ////// TODOC /// /// public SrgsDocument(GrammarBuilder builder) { Helpers.ThrowIfNull (builder, "builder"); // New grammar _grammar = new SrgsGrammar(); #pragma warning disable 56504 // The Culture property is the Grammar builder is already checked. _grammar.Culture = builder.Culture; #pragma warning restore 56504 // Creates SrgsDocument elements IElementFactory elementFactory = new SrgsElementFactory(_grammar); // Do it builder.CreateGrammar(elementFactory); } #endif ////// /// /// public SrgsDocument (SrgsRule grammarRootRule) : this () { Helpers.ThrowIfNull (grammarRootRule, "grammarRootRule"); Root = grammarRootRule; Rules.Add (grammarRootRule); } #endregion //******************************************************************** // // Public methods // //******************************************************************* #region public methods ////// TODOC /// /// public void WriteSrgs (XmlWriter srgsGrammar) { Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar"); // Make sure the grammar is ok _grammar.Validate (); // Write the data. _grammar.WriteSrgs (srgsGrammar); } #endregion //******************************************************************** // // Public Properties // //******************************************************************** #region Public Properties ////// Base URI of _grammar (xml:base). /// public Uri XmlBase { set { // base value can be null #pragma warning disable 56526 _grammar.XmlBase = value; #pragma warning restore 56526 } get { return _grammar.XmlBase; } } ////// Grammar language (xml:lang) /// public CultureInfo Culture { set { Helpers.ThrowIfNull (value, "value"); if (value.Equals (CultureInfo.InvariantCulture)) { throw new ArgumentException (SR.Get (SRID.InvariantCultureInfo), "value"); } _grammar.Culture = value; } get { return _grammar.Culture; } } ////// Root rule (srgs:root) /// public SrgsRule Root { set { // base value can be null #pragma warning disable 56526 _grammar.Root = value; #pragma warning restore 56526 } get { return _grammar.Root; } } ////// Grammar mode (srgs:mode) - voice, dtmf /// public SrgsGrammarMode Mode { set { _grammar.Mode = value == SrgsGrammarMode.Voice ? GrammarType.VoiceGrammar : GrammarType.DtmfGrammar; } get { return _grammar.Mode == GrammarType.VoiceGrammar ? SrgsGrammarMode.Voice : SrgsGrammarMode.Dtmf; } } ////// Grammar mode (srgs:mode) - voice, dtmf /// public SrgsPhoneticAlphabet PhoneticAlphabet { set { _grammar.PhoneticAlphabet = (AlphabetType) value; _grammar.HasPhoneticAlphabetBeenSet = true; } get { return (SrgsPhoneticAlphabet) _grammar.PhoneticAlphabet; } } ////// A collection of rules that this _grammar houses. /// // APITODO: Implementations of Rules and all other SRGS objects not here for now public SrgsRulesCollection Rules { get { return _grammar.Rules; } } #if !NO_STG ////// Programming Language used for the inline code; C#, VB or JScript /// public string Language { set { // Language can be set to null #pragma warning disable 56526 _grammar.Language = value; #pragma warning restore 56526 } get { return _grammar.Language; } } /// |summary| /// namespace /// |/summary| public string Namespace { set { // namespace can be set to null #pragma warning disable 56526 _grammar.Namespace = value; #pragma warning restore 56526 } get { return _grammar.Namespace; } } /// |summary| /// CodeBehind /// |/summary| public CollectionCodeBehind { get { return _grammar.CodeBehind; } } /// |summary| /// Add #line statements to the inline scripts if set /// |/summary| public bool Debug { get { return _grammar.Debug; } set { _grammar.Debug = value; } } /// |summary| /// language /// |/summary| public string Script { set { Helpers.ThrowIfEmptyOrNull (value, "value"); _grammar.Script = value; } get { return _grammar.Script; } } #if SPEECHSERVER /// /// TODOC /// summary> public CollectionSemanticInterpretationTags { get { return _grammar.GlobalTags; } } #endif /// |summary| /// ImportNameSpaces /// |/summary| public Collection ImportNamespaces { get { return _grammar.ImportNamespaces; } } /// |summary| /// ImportNameSpaces /// |/summary| public Collection AssemblyReferences { get { return _grammar.AssemblyReferences; } } #endif #endregion //******************************************************************* // // Internal methods // //******************************************************************** #region Internal methods // Initialize an SrgsDocument from an Srgs text source. internal void Load (XmlReader srgsGrammar) { // New grammar _grammar = new SrgsGrammar (); // For SrgsGrammar, the default is IPA, for xml grammars, it is sapi. _grammar.PhoneticAlphabet = AlphabetType.Sapi; // create an XMl Parser XmlParser srgsParser = new XmlParser (srgsGrammar, null); // Creates SrgsDocument elements srgsParser.ElementFactory = new SrgsElementFactory (_grammar); // Do it srgsParser.Parse (); // This provides the path the XML was loaded from. // {Note potentially this may also be overridden by an xml:base attribute in the XML itself. // But for this scenario that doesn't matter since this is used to calculate the correct base path.} if (!string.IsNullOrEmpty (srgsGrammar.BaseURI)) { _baseUri = new Uri (srgsGrammar.BaseURI); } } static internal GrammarOptions TagFormat2GrammarOptions (SrgsTagFormat value) { GrammarOptions newValue = 0; switch (value) { case SrgsTagFormat.KeyValuePairs: newValue = GrammarOptions.KeyValuePairSrgs; break; case SrgsTagFormat.MssV1: newValue = GrammarOptions.MssV1; break; case SrgsTagFormat.W3cV1: newValue = GrammarOptions.W3cV1; break; } return newValue; } static internal SrgsTagFormat GrammarOptions2TagFormat (GrammarOptions value) { SrgsTagFormat tagFormat = SrgsTagFormat.Default; switch (value & GrammarOptions.TagFormat) { case GrammarOptions.MssV1: tagFormat = SrgsTagFormat.MssV1; break; case GrammarOptions.W3cV1: tagFormat = SrgsTagFormat.W3cV1; break; case GrammarOptions.KeyValuePairSrgs: case GrammarOptions.KeyValuePairs: tagFormat = SrgsTagFormat.KeyValuePairs; break; } return tagFormat; } #endregion //******************************************************************* // // Internal Properties // //******************************************************************* #region Internal Properties /// /// Tag format (srgs:tag-format) /// summary> internal SrgsTagFormat TagFormat { set { _grammar.TagFormat = value; } } internal Uri BaseUri { get { return _baseUri; } } internal SrgsGrammar Grammar { get { return _grammar; } } #endregion //******************************************************************* // // Private Fields // //******************************************************************** #region Private Fields private SrgsGrammar _grammar; // Path the grammar was actually loaded from, if this exists. // Note this is different to SrgsGrammar.XmlBase which is the value of the xml:base attribute in the document itself. private Uri _baseUri; #endregion Fields } #region Enumerations /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode"]/*' /> // Grammar mode. Voice, Dtmf public enum SrgsGrammarMode { /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode.Voice"]/*' /> Voice, /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode.Dtmf"]/*' /> Dtmf } /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode"]/*' /> // Grammar mode. Voice, Dtmf public enum SrgsPhoneticAlphabet { ////// TODOC /// Sapi, ////// TODOC /// Ipa, ////// TODOC /// Ups } #endregion Enumerations } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // // History: // 5/1/2004 jeanfp Created from the Kurosawa Code //--------------------------------------------------------------------------- using System; using System.Globalization; using System.ComponentModel; using System.Collections.ObjectModel; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Xml; using System.Collections.Generic; using System.Speech.Internal; using System.Speech.Internal.SrgsCompiler; using System.Speech.Internal.SrgsParser; #pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages. namespace System.Speech.Recognition.SrgsGrammar { ////// This class allows a _grammar to be specified in SRGS form. /// APITODO: needs programmatic access to SRGS dom; PACOG /// APITODO: needs rule activation/deactivation methods /// [Serializable] public class SrgsDocument { //******************************************************************* // // Constructors / Destructors // //******************************************************************* #region Constructors / Destructors ////// The default constructor - creates an empty SrgsGrammar object /// public SrgsDocument () { _grammar = new SrgsGrammar (); } ////// /// /// public SrgsDocument (string path) { Helpers.ThrowIfEmptyOrNull (path, "path"); using (XmlTextReader reader = new XmlTextReader (path)) { Load (reader); } } ////// TODOC /// /// public SrgsDocument (XmlReader srgsGrammar) { Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar"); Load (srgsGrammar); } #if !SPEECHSERVER && !NO_GRAMMAR_BUILDER ////// TODOC /// /// public SrgsDocument(GrammarBuilder builder) { Helpers.ThrowIfNull (builder, "builder"); // New grammar _grammar = new SrgsGrammar(); #pragma warning disable 56504 // The Culture property is the Grammar builder is already checked. _grammar.Culture = builder.Culture; #pragma warning restore 56504 // Creates SrgsDocument elements IElementFactory elementFactory = new SrgsElementFactory(_grammar); // Do it builder.CreateGrammar(elementFactory); } #endif ////// /// /// public SrgsDocument (SrgsRule grammarRootRule) : this () { Helpers.ThrowIfNull (grammarRootRule, "grammarRootRule"); Root = grammarRootRule; Rules.Add (grammarRootRule); } #endregion //******************************************************************** // // Public methods // //******************************************************************* #region public methods ////// TODOC /// /// public void WriteSrgs (XmlWriter srgsGrammar) { Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar"); // Make sure the grammar is ok _grammar.Validate (); // Write the data. _grammar.WriteSrgs (srgsGrammar); } #endregion //******************************************************************** // // Public Properties // //******************************************************************** #region Public Properties ////// Base URI of _grammar (xml:base). /// public Uri XmlBase { set { // base value can be null #pragma warning disable 56526 _grammar.XmlBase = value; #pragma warning restore 56526 } get { return _grammar.XmlBase; } } ////// Grammar language (xml:lang) /// public CultureInfo Culture { set { Helpers.ThrowIfNull (value, "value"); if (value.Equals (CultureInfo.InvariantCulture)) { throw new ArgumentException (SR.Get (SRID.InvariantCultureInfo), "value"); } _grammar.Culture = value; } get { return _grammar.Culture; } } ////// Root rule (srgs:root) /// public SrgsRule Root { set { // base value can be null #pragma warning disable 56526 _grammar.Root = value; #pragma warning restore 56526 } get { return _grammar.Root; } } ////// Grammar mode (srgs:mode) - voice, dtmf /// public SrgsGrammarMode Mode { set { _grammar.Mode = value == SrgsGrammarMode.Voice ? GrammarType.VoiceGrammar : GrammarType.DtmfGrammar; } get { return _grammar.Mode == GrammarType.VoiceGrammar ? SrgsGrammarMode.Voice : SrgsGrammarMode.Dtmf; } } ////// Grammar mode (srgs:mode) - voice, dtmf /// public SrgsPhoneticAlphabet PhoneticAlphabet { set { _grammar.PhoneticAlphabet = (AlphabetType) value; _grammar.HasPhoneticAlphabetBeenSet = true; } get { return (SrgsPhoneticAlphabet) _grammar.PhoneticAlphabet; } } ////// A collection of rules that this _grammar houses. /// // APITODO: Implementations of Rules and all other SRGS objects not here for now public SrgsRulesCollection Rules { get { return _grammar.Rules; } } #if !NO_STG ////// Programming Language used for the inline code; C#, VB or JScript /// public string Language { set { // Language can be set to null #pragma warning disable 56526 _grammar.Language = value; #pragma warning restore 56526 } get { return _grammar.Language; } } /// |summary| /// namespace /// |/summary| public string Namespace { set { // namespace can be set to null #pragma warning disable 56526 _grammar.Namespace = value; #pragma warning restore 56526 } get { return _grammar.Namespace; } } /// |summary| /// CodeBehind /// |/summary| public CollectionCodeBehind { get { return _grammar.CodeBehind; } } /// |summary| /// Add #line statements to the inline scripts if set /// |/summary| public bool Debug { get { return _grammar.Debug; } set { _grammar.Debug = value; } } /// |summary| /// language /// |/summary| public string Script { set { Helpers.ThrowIfEmptyOrNull (value, "value"); _grammar.Script = value; } get { return _grammar.Script; } } #if SPEECHSERVER /// /// TODOC /// summary> public CollectionSemanticInterpretationTags { get { return _grammar.GlobalTags; } } #endif /// |summary| /// ImportNameSpaces /// |/summary| public Collection ImportNamespaces { get { return _grammar.ImportNamespaces; } } /// |summary| /// ImportNameSpaces /// |/summary| public Collection AssemblyReferences { get { return _grammar.AssemblyReferences; } } #endif #endregion //******************************************************************* // // Internal methods // //******************************************************************** #region Internal methods // Initialize an SrgsDocument from an Srgs text source. internal void Load (XmlReader srgsGrammar) { // New grammar _grammar = new SrgsGrammar (); // For SrgsGrammar, the default is IPA, for xml grammars, it is sapi. _grammar.PhoneticAlphabet = AlphabetType.Sapi; // create an XMl Parser XmlParser srgsParser = new XmlParser (srgsGrammar, null); // Creates SrgsDocument elements srgsParser.ElementFactory = new SrgsElementFactory (_grammar); // Do it srgsParser.Parse (); // This provides the path the XML was loaded from. // {Note potentially this may also be overridden by an xml:base attribute in the XML itself. // But for this scenario that doesn't matter since this is used to calculate the correct base path.} if (!string.IsNullOrEmpty (srgsGrammar.BaseURI)) { _baseUri = new Uri (srgsGrammar.BaseURI); } } static internal GrammarOptions TagFormat2GrammarOptions (SrgsTagFormat value) { GrammarOptions newValue = 0; switch (value) { case SrgsTagFormat.KeyValuePairs: newValue = GrammarOptions.KeyValuePairSrgs; break; case SrgsTagFormat.MssV1: newValue = GrammarOptions.MssV1; break; case SrgsTagFormat.W3cV1: newValue = GrammarOptions.W3cV1; break; } return newValue; } static internal SrgsTagFormat GrammarOptions2TagFormat (GrammarOptions value) { SrgsTagFormat tagFormat = SrgsTagFormat.Default; switch (value & GrammarOptions.TagFormat) { case GrammarOptions.MssV1: tagFormat = SrgsTagFormat.MssV1; break; case GrammarOptions.W3cV1: tagFormat = SrgsTagFormat.W3cV1; break; case GrammarOptions.KeyValuePairSrgs: case GrammarOptions.KeyValuePairs: tagFormat = SrgsTagFormat.KeyValuePairs; break; } return tagFormat; } #endregion //******************************************************************* // // Internal Properties // //******************************************************************* #region Internal Properties /// /// Tag format (srgs:tag-format) /// summary> internal SrgsTagFormat TagFormat { set { _grammar.TagFormat = value; } } internal Uri BaseUri { get { return _baseUri; } } internal SrgsGrammar Grammar { get { return _grammar; } } #endregion //******************************************************************* // // Private Fields // //******************************************************************** #region Private Fields private SrgsGrammar _grammar; // Path the grammar was actually loaded from, if this exists. // Note this is different to SrgsGrammar.XmlBase which is the value of the xml:base attribute in the document itself. private Uri _baseUri; #endregion Fields } #region Enumerations /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode"]/*' /> // Grammar mode. Voice, Dtmf public enum SrgsGrammarMode { /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode.Voice"]/*' /> Voice, /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode.Dtmf"]/*' /> Dtmf } /// TODOC <_include file='doc\SrgsGrammar.uex' path='docs/doc[@for="SrgsGrammarMode"]/*' /> // Grammar mode. Voice, Dtmf public enum SrgsPhoneticAlphabet { ////// TODOC /// Sapi, ////// TODOC /// Ipa, ////// TODOC /// Ups } #endregion Enumerations } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DeviceFilterEditorDialog.cs
- Privilege.cs
- XmlILAnnotation.cs
- SmiContextFactory.cs
- odbcmetadatacolumnnames.cs
- StringCollection.cs
- TypeHelper.cs
- cookieexception.cs
- IChannel.cs
- SkewTransform.cs
- ImageSourceConverter.cs
- RepeatBehavior.cs
- HtmlControlPersistable.cs
- SplitContainer.cs
- VirtualPathUtility.cs
- TypedReference.cs
- RotateTransform3D.cs
- RecognizedPhrase.cs
- WebHeaderCollection.cs
- CaseInsensitiveOrdinalStringComparer.cs
- DependencyObjectType.cs
- CalendarDesigner.cs
- EntityCommandCompilationException.cs
- DSASignatureFormatter.cs
- MaterialCollection.cs
- PropertyGeneratedEventArgs.cs
- UserControlAutomationPeer.cs
- HitTestParameters.cs
- BuildResult.cs
- LocalBuilder.cs
- GridViewSortEventArgs.cs
- Section.cs
- CheckBoxStandardAdapter.cs
- RuntimeWrappedException.cs
- SqlDataSourceStatusEventArgs.cs
- RewritingSimplifier.cs
- EventMappingSettingsCollection.cs
- RelationshipEntry.cs
- ISessionStateStore.cs
- ObjectView.cs
- Odbc32.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- Int16.cs
- Panel.cs
- ControlTemplate.cs
- RadioButtonRenderer.cs
- LabelTarget.cs
- SmtpNetworkElement.cs
- InfoCardXmlSerializer.cs
- storagemappingitemcollection.viewdictionary.cs
- FigureParaClient.cs
- MessageQueueAccessControlEntry.cs
- Debug.cs
- IndexedGlyphRun.cs
- InputManager.cs
- StructuredType.cs
- UITypeEditor.cs
- ParserStack.cs
- DataRowChangeEvent.cs
- CacheMemory.cs
- DbParameterCollection.cs
- BlurBitmapEffect.cs
- IndentedTextWriter.cs
- SetterBaseCollection.cs
- CustomErrorsSection.cs
- PowerStatus.cs
- ToolStripItemImageRenderEventArgs.cs
- NonClientArea.cs
- DrawTreeNodeEventArgs.cs
- BamlTreeUpdater.cs
- TCPClient.cs
- WindowsListViewItemStartMenu.cs
- MetadataCacheItem.cs
- Quaternion.cs
- CompilationLock.cs
- PropertyPushdownHelper.cs
- SoapMessage.cs
- TreeNodeBinding.cs
- AdRotator.cs
- TraceContext.cs
- ServiceContractDetailViewControl.cs
- OleDbWrapper.cs
- StylusButtonEventArgs.cs
- EncoderExceptionFallback.cs
- mediapermission.cs
- SupportsEventValidationAttribute.cs
- BlurBitmapEffect.cs
- FieldBuilder.cs
- DataRowChangeEvent.cs
- CssStyleCollection.cs
- ExpressionEditorAttribute.cs
- HandledEventArgs.cs
- DuplexChannel.cs
- Number.cs
- Effect.cs
- TableLayoutStyle.cs
- RenderData.cs
- TimeStampChecker.cs
- Menu.cs
- Environment.cs