Example #1
0
        internal float Serialize(StreamMarshaler streamBuffer, bool isLast, uint arcIndex)
        {
            CfgArc cfgArc = default(CfgArc);

            cfgArc.LastArc           = isLast;
            cfgArc.HasSemanticTag    = (SemanticTagCount > 0);
            cfgArc.NextStartArcIndex = (uint)((_end != null) ? _end.SerializeId : 0);
            if (_ruleRef != null)
            {
                cfgArc.RuleRef         = true;
                cfgArc.TransitionIndex = (uint)_ruleRef._iSerialize;
            }
            else
            {
                cfgArc.RuleRef = false;
                if (_specialTransitionIndex != 0)
                {
                    cfgArc.TransitionIndex = (uint)_specialTransitionIndex;
                }
                else
                {
                    cfgArc.TransitionIndex = (uint)_iWord;
                }
            }
            cfgArc.LowConfRequired  = (_confidence < 0);
            cfgArc.HighConfRequired = (_confidence > 0);
            cfgArc.MatchMode        = (uint)_matchMode;
            _iSerialize             = arcIndex;
            streamBuffer.WriteStream(cfgArc);
            return(_flWeight);
        }
Example #2
0
        internal void Serialize(StreamMarshaler streamBuffer)
        {
            // Dynamic rules and imports have no arcs
            _cfgRule.FirstArcIndex = _firstState != null && !_firstState.OutArcs.IsEmpty ? (uint)_firstState.SerializeId : 0;

            _cfgRule.DirtyRule = true;

            streamBuffer.WriteStream(_cfgRule);
        }
Example #3
0
        internal void Serialize(StringBlob symbols, StreamMarshaler streamBuffer)
        {
            CfgScriptRef cfgScriptRef = default(CfgScriptRef);

            cfgScriptRef._idRule   = symbols.Find(_rule);
            cfgScriptRef._method   = _method;
            cfgScriptRef._idMethod = _idSymbol;
            streamBuffer.WriteStream(cfgScriptRef);
        }
Example #4
0
        internal static float SerializeExtraEpsilonWithTag(StreamMarshaler streamBuffer, Arc arc, bool isLast, uint arcIndex)
        {
            CfgArc cfgArc = default(CfgArc);

            cfgArc.LastArc           = isLast;
            cfgArc.HasSemanticTag    = true;
            cfgArc.NextStartArcIndex = arcIndex;
            cfgArc.TransitionIndex   = 0u;
            cfgArc.LowConfRequired   = false;
            cfgArc.HighConfRequired  = false;
            cfgArc.MatchMode         = (uint)arc._matchMode;
            streamBuffer.WriteStream(cfgArc);
            return(arc._flWeight);
        }
Example #5
0
        internal void Serialize(StringBlob symbols, StreamMarshaler streamBuffer)
        {
            CfgScriptRef script = new();

            // Get the symbol id for the rule
            script._idRule = symbols.Find(_rule);

            script._method = _method;

            script._idMethod = _idSymbol;

            System.Diagnostics.Debug.Assert(script._idRule != -1 && script._idMethod != -1);

            streamBuffer.WriteStream(script);
        }
Example #6
0
File: Arc.cs Project: z77ma/runtime
        internal float Serialize(StreamMarshaler streamBuffer, bool isLast, uint arcIndex)
        {
            CfgArc A = new();

            A.LastArc           = isLast;
            A.HasSemanticTag    = SemanticTagCount > 0;
            A.NextStartArcIndex = (uint)(_end != null ? _end.SerializeId : 0);
            if (_ruleRef != null)
            {
                A.RuleRef         = true;
                A.TransitionIndex = (uint)_ruleRef._iSerialize; //_pFirstState.SerializeId;
            }
            else
            {
                A.RuleRef = false;
                if (_specialTransitionIndex != 0)
                {
                    A.TransitionIndex = (uint)_specialTransitionIndex;
                }
                else
                {
                    A.TransitionIndex = (uint)_iWord;
                }
            }

            A.LowConfRequired  = (_confidence < 0);
            A.HighConfRequired = (_confidence > 0);
            A.MatchMode        = (uint)_matchMode;

            // For new arcs SerializeId is INFINITE so we set it correctly here.
            // For existing states we preserve the index from loading,
            //  unless new states have been added in, in which case the arc index,
            //  and hence the transition id have changed. There is a workaround in ReloadCmd
            //  to invalidate rules in this case.
            _iSerialize = arcIndex;

            streamBuffer.WriteStream(A);
            return(_flWeight);
        }
Example #7
0
 internal void Serialize(StreamMarshaler streamBuffer)
 {
     _cfgRule.FirstArcIndex = (uint)((_firstState != null && !_firstState.OutArcs.IsEmpty) ? _firstState.SerializeId : 0);
     _cfgRule.DirtyRule     = true;
     streamBuffer.WriteStream(_cfgRule);
 }
Example #8
0
 internal void Serialize(StreamMarshaler streamBuffer)
 {
     streamBuffer.WriteStream(_cfgTag);
 }
Example #9
0
 private void WriteWaveHeader(StreamMarshaler sm)
 {
     char[] array = new char[4]
     {
         'R',
         'I',
         'F',
         'F'
     };
     byte[] array2 = _audioFormat.FormatSpecificData();
     sm.WriteArray(array, array.Length);
     sm.WriteStream((uint)(_rawAudioData.Length + 38 + array2.Length));
     char[] array3 = new char[4]
     {
         'W',
         'A',
         'V',
         'E'
     };
     sm.WriteArray(array3, array3.Length);
     char[] array4 = new char[4]
     {
         'f',
         'm',
         't',
         ' '
     };
     sm.WriteArray(array4, array4.Length);
     sm.WriteStream(18 + array2.Length);
     sm.WriteStream((ushort)_audioFormat.EncodingFormat);
     sm.WriteStream((ushort)_audioFormat.ChannelCount);
     sm.WriteStream(_audioFormat.SamplesPerSecond);
     sm.WriteStream(_audioFormat.AverageBytesPerSecond);
     sm.WriteStream((ushort)_audioFormat.BlockAlign);
     sm.WriteStream((ushort)_audioFormat.BitsPerSample);
     sm.WriteStream((ushort)array2.Length);
     if (array2.Length != 0)
     {
         sm.WriteStream(array2);
     }
     char[] array5 = new char[4]
     {
         'd',
         'a',
         't',
         'a'
     };
     sm.WriteArray(array5, array5.Length);
     sm.WriteStream(_rawAudioData.Length);
 }
Example #10
0
        internal void Commit(StreamMarshaler streamBuffer)
        {
            long         position = streamBuffer.Stream.Position;
            List <State> list     = new List <State>(_states);

            _states = null;
            list.Sort();
            ValidateAndTagRules();
            CheckLeftRecursion(list);
            int num    = (_basePath != null) ? (_basePath.Length + 1) : 0;
            int idWord = 0;

            if (_globalTags.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string globalTag in _globalTags)
                {
                    stringBuilder.Append(globalTag);
                }
                _symbols.Add(stringBuilder.ToString(), out idWord);
                idWord = _symbols.OffsetFromId(idWord);
                if (idWord > 65535)
                {
                    throw new OverflowException(SR.Get(SRID.TooManyRulesWithSemanticsGlobals));
                }
            }
            foreach (ScriptRef scriptRef in _scriptRefs)
            {
                _symbols.Add(scriptRef._sMethod, out scriptRef._idSymbol);
            }
            int cArcs;

            float[] pWeights;
            CfgGrammar.CfgSerializedHeader o = BuildHeader(list, num, (ushort)idWord, out cArcs, out pWeights);
            streamBuffer.WriteStream(o);
            streamBuffer.WriteArrayChar(_words.SerializeData(), _words.SerializeSize());
            streamBuffer.WriteArrayChar(_symbols.SerializeData(), _symbols.SerializeSize());
            foreach (Rule rule in _rules)
            {
                rule.Serialize(streamBuffer);
            }
            if (num > 0)
            {
                streamBuffer.WriteArrayChar(_basePath.ToCharArray(), _basePath.Length);
                streamBuffer.WriteArrayChar(_achZero, 1);
                streamBuffer.WriteArray(_abZero3, (num * 2) & 3);
            }
            streamBuffer.WriteStream(default(CfgArc));
            int  iOffset    = 1;
            uint iArcOffset = 1u;
            bool flag       = (GrammarOptions & GrammarOptions.MssV1) == GrammarOptions.MssV1;

            foreach (State item in list)
            {
                item.SerializeStateEntries(streamBuffer, flag, pWeights, ref iArcOffset, ref iOffset);
            }
            if (_fNeedWeightTable)
            {
                streamBuffer.WriteArray(pWeights, cArcs);
            }
            if (!flag)
            {
                foreach (State item2 in list)
                {
                    item2.SetEndArcIndexForTags();
                }
            }
            for (int num2 = _tags.Count - 1; num2 >= 0; num2--)
            {
                if (_tags[num2]._cfgTag.ArcIndex == 0)
                {
                    _tags.RemoveAt(num2);
                }
            }
            _tags.Sort();
            foreach (Tag tag in _tags)
            {
                tag.Serialize(streamBuffer);
            }
            foreach (ScriptRef scriptRef2 in _scriptRefs)
            {
                scriptRef2.Serialize(_symbols, streamBuffer);
            }
            if (_il != null && _il.Length != 0)
            {
                streamBuffer.Stream.Write(_il, 0, _il.Length);
            }
            if (_pdb != null && _pdb.Length != 0)
            {
                streamBuffer.Stream.Write(_pdb, 0, _pdb.Length);
            }
        }
Example #11
0
        private void WriteWaveHeader(StreamMarshaler sm)
        {
            char[] riff = new char[4] {
                'R', 'I', 'F', 'F'
            };
            byte[] formatSpecificData = _audioFormat.FormatSpecificData();
            sm.WriteArray <char>(riff, riff.Length);

            sm.WriteStream((uint)(_rawAudioData.Length + 38 + formatSpecificData.Length)); // Must be four bytes

            char[] wave = new char[4] {
                'W', 'A', 'V', 'E'
            };
            sm.WriteArray(wave, wave.Length);

            char[] fmt = new char[4] {
                'f', 'm', 't', ' '
            };
            sm.WriteArray(fmt, fmt.Length);

            sm.WriteStream(18 + formatSpecificData.Length);

            sm.WriteStream((ushort)_audioFormat.EncodingFormat);
            sm.WriteStream((ushort)_audioFormat.ChannelCount);
            sm.WriteStream(_audioFormat.SamplesPerSecond);
            sm.WriteStream(_audioFormat.AverageBytesPerSecond);
            sm.WriteStream((ushort)_audioFormat.BlockAlign);
            sm.WriteStream((ushort)_audioFormat.BitsPerSample);
            sm.WriteStream((ushort)formatSpecificData.Length);

            // write codec specific data
            if (formatSpecificData.Length > 0)
            {
                sm.WriteStream(formatSpecificData);
            }

            char[] data = new char[4] {
                'd', 'a', 't', 'a'
            };
            sm.WriteArray(data, data.Length);
            sm.WriteStream(_rawAudioData.Length);
        }