Beispiel #1
0
        private static string GetSemanticValue(CfgSemanticTag tag, StringBlob symbols, out string value)
        {
#pragma warning disable 0618 // VarEnum is obsolete
            switch (tag.PropVariantType)
            {
            case VarEnum.VT_EMPTY:
                value = tag._valueOffset > 0 ? symbols.FromOffset(tag._valueOffset) : tag._valueOffset.ToString(CultureInfo.InvariantCulture);
                break;

            case VarEnum.VT_I4:
            case VarEnum.VT_UI4:
                value = tag._varInt.ToString(CultureInfo.InvariantCulture);
                break;

            case VarEnum.VT_R8:
                value = tag._varDouble.ToString(CultureInfo.InvariantCulture);
                break;

            case VarEnum.VT_BOOL:
                value = tag._varInt == 0 ? "false" : "true";
                break;

            default:
                value = "Unknown property type";
                break;
            }
#pragma warning restore 0618

            return(tag._nameOffset > 0 ? symbols.FromOffset(tag._nameOffset) : tag._nameOffset.ToString(CultureInfo.InvariantCulture));
        }
Beispiel #2
0
 internal CfgSemanticTag(CfgSemanticTag cfgTag)
 {
     _flag1        = cfgTag._flag1;
     _flag2        = cfgTag._flag2;
     _flag3        = cfgTag._flag3;
     _propId       = cfgTag._propId;
     _nameOffset   = cfgTag._nameOffset;
     _varInt       = 0;
     _valueOffset  = cfgTag._valueOffset;
     _varDouble    = cfgTag._varDouble;
     StartArcIndex = 4194303u;
 }
        internal CfgSemanticTag(CfgSemanticTag cfgTag)
        {
            _flag1       = cfgTag._flag1;
            _flag2       = cfgTag._flag2;
            _flag3       = cfgTag._flag3;
            _propId      = cfgTag._propId;
            _nameOffset  = cfgTag._nameOffset;
            _varInt      = 0;
            _valueOffset = cfgTag._valueOffset;
            _varDouble   = cfgTag._varDouble;

            // Initialize
            StartArcIndex = 0x3FFFFF;
        }
Beispiel #4
0
 internal Tag(Backend be, CfgGrammar.CfgProperty property)
 {
     _be     = be;
     _cfgTag = new CfgSemanticTag(be.Symbols, property);
 }
Beispiel #5
0
 internal Tag(Backend be, CfgSemanticTag cfgTag)
 {
     _be     = be;
     _cfgTag = cfgTag;
 }
Beispiel #6
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;
        }