示例#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);
        }
示例#2
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);
        }
示例#3
0
 internal CfgArc(CfgArc arc)
 {
     _flag1 = arc._flag1;
     _flag2 = arc._flag2;
 }
示例#4
0
        internal void InitFromBinaryGrammar(StreamMarshaler streamHelper)
        {
            CfgGrammar.CfgHeader header = CfgGrammar.ConvertCfgHeader(streamHelper);
            _words          = header.pszWords;
            _symbols        = header.pszSymbols;
            _grammarOptions = header.GrammarOptions;
            State[] array = new State[header.arcs.Length];
            SortedDictionary <int, Rule> sortedDictionary = new SortedDictionary <int, Rule>();
            int count = _rules.Count;

            BuildRulesFromBinaryGrammar(header, array, sortedDictionary, count);
            Arc[]  array2 = new Arc[header.arcs.Length];
            bool   flag   = true;
            CfgArc cfgArc = default(CfgArc);
            State  state  = null;
            IEnumerator <KeyValuePair <int, Rule> > enumerator = sortedDictionary.GetEnumerator();

            if (enumerator.MoveNext())
            {
                KeyValuePair <int, Rule> current = enumerator.Current;
                Rule value = current.Value;
                for (int i = 1; i < header.arcs.Length; i++)
                {
                    CfgArc cfgArc2 = header.arcs[i];
                    if (cfgArc2.RuleRef)
                    {
                        value._listRules.Add(_rules[(int)cfgArc2.TransitionIndex]);
                    }
                    if (current.Key == i)
                    {
                        value = current.Value;
                        if (enumerator.MoveNext())
                        {
                            current = enumerator.Current;
                        }
                    }
                    if (flag || cfgArc.LastArc)
                    {
                        if (array[i] == null)
                        {
                            uint nextHandle = CfgGrammar.NextHandle;
                            array[i] = new State(value, nextHandle, i);
                            AddState(array[i]);
                        }
                        state = array[i];
                    }
                    int   nextStartArcIndex = (int)cfgArc2.NextStartArcIndex;
                    State end = null;
                    if (state != null && nextStartArcIndex != 0)
                    {
                        if (array[nextStartArcIndex] == null)
                        {
                            uint nextHandle2 = CfgGrammar.NextHandle;
                            array[nextStartArcIndex] = new State(value, nextHandle2, nextStartArcIndex);
                            AddState(array[nextStartArcIndex]);
                        }
                        end = array[nextStartArcIndex];
                    }
                    float flWeight = (header.weights != null) ? header.weights[i] : 1f;
                    Arc   arc;
                    if (cfgArc2.RuleRef)
                    {
                        Rule ruleRef = _rules[(int)cfgArc2.TransitionIndex];
                        arc = new Arc(null, ruleRef, _words, flWeight, 0, null, MatchMode.AllWords, ref _fNeedWeightTable);
                    }
                    else
                    {
                        int transitionIndex = (int)cfgArc2.TransitionIndex;
                        int num             = (transitionIndex == 4194302 || transitionIndex == 4194301 || transitionIndex == 4194303) ? transitionIndex : 0;
                        arc = new Arc((int)((num == 0) ? cfgArc2.TransitionIndex : 0), flWeight, cfgArc2.LowConfRequired ? (-1) : (cfgArc2.HighConfRequired ? 1 : 0), num, MatchMode.AllWords, ref _fNeedWeightTable);
                    }
                    arc.Start = state;
                    arc.End   = end;
                    AddArc(arc);
                    array2[i] = arc;
                    flag      = false;
                    cfgArc    = cfgArc2;
                }
            }
            int j = 1;
            int k = 0;

            for (; j < header.arcs.Length; j++)
            {
                CfgArc cfgArc3 = header.arcs[j];
                if (!cfgArc3.HasSemanticTag)
                {
                    continue;
                }
                for (; k < header.tags.Length && header.tags[k].StartArcIndex == j; k++)
                {
                    CfgSemanticTag cfgTag = header.tags[k];
                    Tag            tag    = new Tag(this, cfgTag);
                    _tags.Add(tag);
                    array2[tag._cfgTag.StartArcIndex].AddStartTag(tag);
                    array2[tag._cfgTag.EndArcIndex].AddEndTag(tag);
                    if (cfgTag._nameOffset > 0)
                    {
                        tag._cfgTag._nameOffset = _symbols.OffsetFromId(_symbols.Find(_symbols.FromOffset(cfgTag._nameOffset)));
                    }
                    else
                    {
                        tag._cfgTag._valueOffset = _symbols.OffsetFromId(_symbols.Find(_symbols.FromOffset(cfgTag._valueOffset)));
                    }
                }
            }
            _fNeedWeightTable = true;
            if (header.BasePath != null)
            {
                SetBasePath(header.BasePath);
            }
            _guid              = header.GrammarGUID;
            _langId            = header.langId;
            _grammarMode       = header.GrammarMode;
            _fLoadedFromBinary = true;
        }