Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / 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
- CreateUserWizardAutoFormat.cs
- ScrollableControl.cs
- InkCanvas.cs
- TrustLevel.cs
- SerializationEventsCache.cs
- SmiEventSink.cs
- DataBoundControl.cs
- InheritanceContextChangedEventManager.cs
- StylusCollection.cs
- StaticFileHandler.cs
- DefaultBindingPropertyAttribute.cs
- ScriptingSectionGroup.cs
- CopyEncoder.cs
- AtomPub10CategoriesDocumentFormatter.cs
- PagesChangedEventArgs.cs
- cookiecontainer.cs
- ListViewGroupConverter.cs
- MailWebEventProvider.cs
- RemotingSurrogateSelector.cs
- InvokeHandlers.cs
- SystemWebSectionGroup.cs
- GridViewSelectEventArgs.cs
- RegistrationServices.cs
- BinaryNegotiation.cs
- WebPartDisplayModeCollection.cs
- XmlIlTypeHelper.cs
- smtppermission.cs
- SqlMetaData.cs
- InputLangChangeRequestEvent.cs
- WorkflowTransactionService.cs
- LicenseContext.cs
- GB18030Encoding.cs
- SessionIDManager.cs
- ConfigurationLocation.cs
- IgnoreDeviceFilterElementCollection.cs
- DbProviderConfigurationHandler.cs
- ScrollEvent.cs
- DirectoryNotFoundException.cs
- PropertyRef.cs
- StringAnimationUsingKeyFrames.cs
- JavascriptCallbackResponseProperty.cs
- FileDialogCustomPlace.cs
- PathGradientBrush.cs
- ThrowHelper.cs
- EndpointDiscoveryElement.cs
- ConnectionPointCookie.cs
- WebPartTransformerCollection.cs
- ContainerUtilities.cs
- AnnotationHighlightLayer.cs
- HandlerBase.cs
- EntityDataSourceStatementEditor.cs
- XmlSchemaParticle.cs
- NavigationPropertyAccessor.cs
- DataBindingHandlerAttribute.cs
- Font.cs
- Oid.cs
- AnnotationHelper.cs
- WriteTimeStream.cs
- GlyphTypeface.cs
- Range.cs
- BamlMapTable.cs
- GroupBoxDesigner.cs
- CollectionView.cs
- ModuleBuilder.cs
- DictionaryBase.cs
- TypeToken.cs
- ConnectionStringsExpressionBuilder.cs
- DataGridViewCellConverter.cs
- Separator.cs
- Metafile.cs
- HttpPostedFile.cs
- RightsManagementInformation.cs
- LogicalExpr.cs
- EncryptedReference.cs
- Win32Exception.cs
- PerformanceCounterPermissionEntry.cs
- localization.cs
- Base64WriteStateInfo.cs
- SessionStateSection.cs
- CompModSwitches.cs
- PropertyOverridesTypeEditor.cs
- _LocalDataStore.cs
- EditorPartDesigner.cs
- CodeMemberField.cs
- AsyncOperationManager.cs
- _BufferOffsetSize.cs
- CrossAppDomainChannel.cs
- FlowDocumentPageViewerAutomationPeer.cs
- GlobalizationSection.cs
- BlurEffect.cs
- InputDevice.cs
- SmiGettersStream.cs
- DeferredSelectedIndexReference.cs
- SettingsSavedEventArgs.cs
- DesignerDataParameter.cs
- DesignTimeDataBinding.cs
- ViewKeyConstraint.cs
- ContentValidator.cs
- LogSwitch.cs
- ObjectDataSourceView.cs