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 Collection CodeBehind
{
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
Collection SemanticInterpretationTags
{
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 Collection CodeBehind
{
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
Collection SemanticInterpretationTags
{
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
- ProtocolViolationException.cs
- SequenceFullException.cs
- ServiceMemoryGates.cs
- SuspendDesigner.cs
- TokenBasedSetEnumerator.cs
- MethodBuilderInstantiation.cs
- SrgsGrammarCompiler.cs
- HyperLinkStyle.cs
- AsyncStreamReader.cs
- PackageRelationshipSelector.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- ZipArchive.cs
- Privilege.cs
- MarkupCompilePass1.cs
- PreloadedPackages.cs
- oledbmetadatacolumnnames.cs
- BitmapEffectInput.cs
- FacetEnabledSchemaElement.cs
- BufferAllocator.cs
- METAHEADER.cs
- WorkflowPageSetupDialog.cs
- CompileLiteralTextParser.cs
- GridViewColumn.cs
- EventSetterHandlerConverter.cs
- StateDesigner.TransitionInfo.cs
- __ComObject.cs
- DataGridSortCommandEventArgs.cs
- OdbcException.cs
- WaitForChangedResult.cs
- DataRowView.cs
- TraceContextRecord.cs
- PrePostDescendentsWalker.cs
- XmlAnyElementAttributes.cs
- DataGridViewDataErrorEventArgs.cs
- TemplatedWizardStep.cs
- ManualResetEvent.cs
- ToolStripItemEventArgs.cs
- ConcurrencyBehavior.cs
- TableColumn.cs
- NotFiniteNumberException.cs
- XsdDataContractExporter.cs
- MemberAssignment.cs
- ProcessThreadCollection.cs
- SqlConnectionPoolProviderInfo.cs
- Function.cs
- ServiceDocument.cs
- XmlSchemaExternal.cs
- GradientBrush.cs
- Section.cs
- ButtonChrome.cs
- DataServiceProcessingPipelineEventArgs.cs
- CatalogPart.cs
- PropertyFilterAttribute.cs
- HelpFileFileNameEditor.cs
- ListContractAdapter.cs
- NavigationWindowAutomationPeer.cs
- NativeRightsManagementAPIsStructures.cs
- PublisherIdentityPermission.cs
- AsyncParams.cs
- InvalidComObjectException.cs
- QueryOutputWriter.cs
- DataBoundControlDesigner.cs
- IItemContainerGenerator.cs
- ConnectionStringSettingsCollection.cs
- NamespaceInfo.cs
- MasterPageCodeDomTreeGenerator.cs
- CorrelationManager.cs
- PluralizationServiceUtil.cs
- TdsParserHelperClasses.cs
- UidManager.cs
- FamilyMap.cs
- Sql8ExpressionRewriter.cs
- TransportContext.cs
- EngineSiteSapi.cs
- HijriCalendar.cs
- TagPrefixAttribute.cs
- ScriptingProfileServiceSection.cs
- ButtonColumn.cs
- EntityDataSourceQueryBuilder.cs
- ServiceHostingEnvironment.cs
- DbCommandDefinition.cs
- VisualBrush.cs
- DocumentApplication.cs
- SqlBulkCopyColumnMappingCollection.cs
- _TLSstream.cs
- TextRangeEditLists.cs
- Int16AnimationUsingKeyFrames.cs
- ConstructorArgumentAttribute.cs
- ColorContextHelper.cs
- WindowsEditBoxRange.cs
- MobileTemplatedControlDesigner.cs
- RSAProtectedConfigurationProvider.cs
- ConnectionOrientedTransportElement.cs
- XmlSortKey.cs
- WebOperationContext.cs
- ResXDataNode.cs
- DataStorage.cs
- Odbc32.cs
- ContentFileHelper.cs
- WmlLabelAdapter.cs