Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Internal / SrgsCompiler / Item.cs / 1 / Item.cs
//------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------
using System;
using System.Speech.Internal.SrgsParser;
namespace System.Speech.Internal.SrgsCompiler
{
///
/// Summary description for Rule.
///
internal sealed class Item : ParseElementCollection, IItem
{
//*******************************************************************
//
// Constructors
//
//*******************************************************************
#region Constructors
internal Item (Backend backend, Rule rule, int minRepeat, int maxRepeat, float repeatProbability, float weigth)
: base (backend, rule)
{
// Validated by the caller
_minRepeat = minRepeat;
_maxRepeat = maxRepeat;
_repeatProbability = repeatProbability;
}
#endregion
//********************************************************************
//
// Internal Method
//
//*******************************************************************
#region Intenal Method
///
/// Process the '/item' element.
///
///
void IElement.PostParse (IElement parentElement)
{
// Special case of no words but only tags. Returns an error as the result is ambiguous
// var res= 1;
// -
//
res= res * 2;
//
// Should the result be 2 or 4
if (_maxRepeat != _minRepeat && _startArc != null && _startArc == _endArc && _endArc.IsEpsilonTransition && !_endArc.IsPropertylessTransition)
{
XmlParser.ThrowSrgsException ((SRID.InvalidTagInAnEmptyItem));
}
// empty - or repeat count == 0
if (_startArc == null || _maxRepeat == 0)
{
// Special Case: _maxRepeat = 0 => Epsilon transition.
if (_maxRepeat == 0 && _startArc != null && _startArc.End != null)
{
// Delete contents of Item. Otherwise, we will end up with states disconnected to the rest of the rule.
State endState = _startArc.End;
_startArc.End = null;
_backend.DeleteSubGraph (endState);
}
// empty item, just add an epsilon transition.
_startArc = _endArc = _backend.EpsilonTransition (_repeatProbability);
}
else
{
// Hard case if repeat count is not one
if (_minRepeat != 1 || _maxRepeat != 1)
{
// Dupplicate the states/transitions graph as many times as repeat count
//Add a state before the start to be able to duplicate the graph
_startArc = InsertState (_startArc, _repeatProbability, Position.Before);
State startState = _startArc.End;
// If _maxRepeat = Infinite, add epsilon transition loop back to the start of this
if (_maxRepeat == System.Int32.MaxValue && _minRepeat == 1)
{
_endArc = InsertState (_endArc, 1.0f, Position.After);
AddEpsilonTransition (_endArc.Start, startState, 1 - _repeatProbability);
}
else
{
State currentStartState = startState;
// For each additional repeat count, clone a new subgraph and connect with appropriate transitions.
for (UInt32 cnt = 1; cnt < _maxRepeat && cnt < 255; cnt++)
{
// Prepare to clone a new subgraph matching the
- content.
State newStartState = _backend.CreateNewState (_endArc.Start.Rule);
// Clone subgraphs and update CurrentEndState.
State newEndState = _backend.CloneSubGraph (currentStartState, _endArc.Start, newStartState);
// Connect the last state with the first state
//_endArc.Start.OutArcs.Add (_endArc);
_endArc.End = newStartState;
// reset the _endArc
System.Diagnostics.Debug.Assert (newEndState.OutArcs.CountIsOne && Arc.CompareContent (_endArc, newEndState.OutArcs.First) == 0);
_endArc = newEndState.OutArcs.First;
if (_maxRepeat == System.Int32.MaxValue)
{
// If we are beyond _minRepeat, add epsilon transition frorm startState with (1-_repeatProbability).
if (cnt == _minRepeat - 1)
{
// Create a new state and attach the last Arc to add
_endArc = InsertState (_endArc, 1.0f, Position.After);
AddEpsilonTransition (_endArc.Start, newStartState, 1 - _repeatProbability);
break;
}
}
else if (cnt <= _maxRepeat - _minRepeat)
{
// If we are beyond _minRepeat, add epsilon transition frorm startState with (1-_repeatProbability).
AddEpsilonTransition (startState, newStartState, 1 - _repeatProbability);
}
// reset the current start state
currentStartState = newStartState;
}
}
// If _minRepeat == 0, add epsilon transition from currentEndState to FinalState with (1-_repeatProbability).
// but do not do it if the only transition is an epsilon
if (_minRepeat == 0 && (_startArc != _endArc || !_startArc.IsEpsilonTransition))
{
if (!_endArc.IsEpsilonTransition || _endArc.SemanticTagCount > 0)
{
_endArc = InsertState (_endArc, 1.0f, Position.After);
}
AddEpsilonTransition (startState, _endArc.Start, 1 - _repeatProbability);
}
// Remove the added startState if possible
_startArc = TrimStart (_startArc, _backend);
}
}
// Add this item to the parent list
base.PostParse ((ParseElementCollection) parentElement);
}
#endregion
//********************************************************************
//
// Private Methods
//
//********************************************************************
#region Private Methods
private void AddEpsilonTransition (State start, State end, float weigth)
{
Arc epsilon = _backend.EpsilonTransition (weigth);
epsilon.Start = start;
epsilon.End = end;
}
#endregion
//*******************************************************************
//
// Private Fields
//
//********************************************************************
#region Private Fields
private float _repeatProbability = 0.5f;
private int _minRepeat = NotSet;
private int _maxRepeat = NotSet;
private const int NotSet = -1;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------
using System;
using System.Speech.Internal.SrgsParser;
namespace System.Speech.Internal.SrgsCompiler
{
///
/// Summary description for Rule.
///
internal sealed class Item : ParseElementCollection, IItem
{
//*******************************************************************
//
// Constructors
//
//*******************************************************************
#region Constructors
internal Item (Backend backend, Rule rule, int minRepeat, int maxRepeat, float repeatProbability, float weigth)
: base (backend, rule)
{
// Validated by the caller
_minRepeat = minRepeat;
_maxRepeat = maxRepeat;
_repeatProbability = repeatProbability;
}
#endregion
//********************************************************************
//
// Internal Method
//
//*******************************************************************
#region Intenal Method
///
/// Process the '/item' element.
///
///
void IElement.PostParse (IElement parentElement)
{
// Special case of no words but only tags. Returns an error as the result is ambiguous
// var res= 1;
// -
//
res= res * 2;
//
// Should the result be 2 or 4
if (_maxRepeat != _minRepeat && _startArc != null && _startArc == _endArc && _endArc.IsEpsilonTransition && !_endArc.IsPropertylessTransition)
{
XmlParser.ThrowSrgsException ((SRID.InvalidTagInAnEmptyItem));
}
// empty - or repeat count == 0
if (_startArc == null || _maxRepeat == 0)
{
// Special Case: _maxRepeat = 0 => Epsilon transition.
if (_maxRepeat == 0 && _startArc != null && _startArc.End != null)
{
// Delete contents of Item. Otherwise, we will end up with states disconnected to the rest of the rule.
State endState = _startArc.End;
_startArc.End = null;
_backend.DeleteSubGraph (endState);
}
// empty item, just add an epsilon transition.
_startArc = _endArc = _backend.EpsilonTransition (_repeatProbability);
}
else
{
// Hard case if repeat count is not one
if (_minRepeat != 1 || _maxRepeat != 1)
{
// Dupplicate the states/transitions graph as many times as repeat count
//Add a state before the start to be able to duplicate the graph
_startArc = InsertState (_startArc, _repeatProbability, Position.Before);
State startState = _startArc.End;
// If _maxRepeat = Infinite, add epsilon transition loop back to the start of this
if (_maxRepeat == System.Int32.MaxValue && _minRepeat == 1)
{
_endArc = InsertState (_endArc, 1.0f, Position.After);
AddEpsilonTransition (_endArc.Start, startState, 1 - _repeatProbability);
}
else
{
State currentStartState = startState;
// For each additional repeat count, clone a new subgraph and connect with appropriate transitions.
for (UInt32 cnt = 1; cnt < _maxRepeat && cnt < 255; cnt++)
{
// Prepare to clone a new subgraph matching the
- content.
State newStartState = _backend.CreateNewState (_endArc.Start.Rule);
// Clone subgraphs and update CurrentEndState.
State newEndState = _backend.CloneSubGraph (currentStartState, _endArc.Start, newStartState);
// Connect the last state with the first state
//_endArc.Start.OutArcs.Add (_endArc);
_endArc.End = newStartState;
// reset the _endArc
System.Diagnostics.Debug.Assert (newEndState.OutArcs.CountIsOne && Arc.CompareContent (_endArc, newEndState.OutArcs.First) == 0);
_endArc = newEndState.OutArcs.First;
if (_maxRepeat == System.Int32.MaxValue)
{
// If we are beyond _minRepeat, add epsilon transition frorm startState with (1-_repeatProbability).
if (cnt == _minRepeat - 1)
{
// Create a new state and attach the last Arc to add
_endArc = InsertState (_endArc, 1.0f, Position.After);
AddEpsilonTransition (_endArc.Start, newStartState, 1 - _repeatProbability);
break;
}
}
else if (cnt <= _maxRepeat - _minRepeat)
{
// If we are beyond _minRepeat, add epsilon transition frorm startState with (1-_repeatProbability).
AddEpsilonTransition (startState, newStartState, 1 - _repeatProbability);
}
// reset the current start state
currentStartState = newStartState;
}
}
// If _minRepeat == 0, add epsilon transition from currentEndState to FinalState with (1-_repeatProbability).
// but do not do it if the only transition is an epsilon
if (_minRepeat == 0 && (_startArc != _endArc || !_startArc.IsEpsilonTransition))
{
if (!_endArc.IsEpsilonTransition || _endArc.SemanticTagCount > 0)
{
_endArc = InsertState (_endArc, 1.0f, Position.After);
}
AddEpsilonTransition (startState, _endArc.Start, 1 - _repeatProbability);
}
// Remove the added startState if possible
_startArc = TrimStart (_startArc, _backend);
}
}
// Add this item to the parent list
base.PostParse ((ParseElementCollection) parentElement);
}
#endregion
//********************************************************************
//
// Private Methods
//
//********************************************************************
#region Private Methods
private void AddEpsilonTransition (State start, State end, float weigth)
{
Arc epsilon = _backend.EpsilonTransition (weigth);
epsilon.Start = start;
epsilon.End = end;
}
#endregion
//*******************************************************************
//
// Private Fields
//
//********************************************************************
#region Private Fields
private float _repeatProbability = 0.5f;
private int _minRepeat = NotSet;
private int _maxRepeat = NotSet;
private const int NotSet = -1;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- KeyedHashAlgorithm.cs
- WebProxyScriptElement.cs
- Thickness.cs
- BaseCodePageEncoding.cs
- RowSpanVector.cs
- HideDisabledControlAdapter.cs
- namescope.cs
- DataSourceSelectArguments.cs
- HttpTransportSecurity.cs
- MemberAccessException.cs
- UriSection.cs
- PropertyMapper.cs
- InvalidChannelBindingException.cs
- ToolboxComponentsCreatedEventArgs.cs
- SmiEventSink_DeferedProcessing.cs
- TextMetrics.cs
- VisualStyleInformation.cs
- ManagedWndProcTracker.cs
- GridViewRowCollection.cs
- Debug.cs
- Button.cs
- SecurityDocument.cs
- OdbcCommand.cs
- _RequestCacheProtocol.cs
- HashCryptoHandle.cs
- HtmlHistory.cs
- StylusButton.cs
- ConstructorBuilder.cs
- LabelLiteral.cs
- AsyncWaitHandle.cs
- WebScriptEnablingBehavior.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- XamlPathDataSerializer.cs
- QilTernary.cs
- LinearKeyFrames.cs
- RelationshipSet.cs
- RouteValueExpressionBuilder.cs
- ReadOnlyHierarchicalDataSourceView.cs
- WsdlInspector.cs
- InvalidEnumArgumentException.cs
- TriggerCollection.cs
- ControlCommandSet.cs
- ModelPerspective.cs
- GenericArgumentsUpdater.cs
- DataServiceSaveChangesEventArgs.cs
- ExtenderHelpers.cs
- DataListAutoFormat.cs
- CachingHintValidation.cs
- FileAuthorizationModule.cs
- CompiledRegexRunner.cs
- TransformedBitmap.cs
- _SingleItemRequestCache.cs
- OutputCacheProfile.cs
- KeyGesture.cs
- InvalidPrinterException.cs
- EventSetter.cs
- ClientSession.cs
- HtmlInputReset.cs
- CompiledQueryCacheKey.cs
- ComboBoxDesigner.cs
- ContainerActivationHelper.cs
- SiteMapNodeCollection.cs
- OleDbFactory.cs
- ProcessHostConfigUtils.cs
- SliderAutomationPeer.cs
- XamlTemplateSerializer.cs
- ButtonAutomationPeer.cs
- TokenBasedSet.cs
- ProxyWebPartConnectionCollection.cs
- CapabilitiesAssignment.cs
- StorageMappingFragment.cs
- KeySplineConverter.cs
- QilName.cs
- CfgParser.cs
- MenuCommand.cs
- GeneratedCodeAttribute.cs
- GlobalizationAssembly.cs
- UrlMapping.cs
- EncodingStreamWrapper.cs
- HtmlControlPersistable.cs
- SecUtil.cs
- HtmlHistory.cs
- GuidConverter.cs
- Vector3DConverter.cs
- EventArgs.cs
- StyleSelector.cs
- Normalization.cs
- SecuritySessionServerSettings.cs
- AdRotator.cs
- DiagnosticsConfiguration.cs
- SessionState.cs
- ExpressionBuilder.cs
- CompensationTokenData.cs
- MetadataItemSerializer.cs
- ButtonBase.cs
- CompilerGlobalScopeAttribute.cs
- FilterException.cs
- PackageDigitalSignature.cs
- BinaryParser.cs
- TemplateNodeContextMenu.cs