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; }
private static void AddArc(Arc arc) { }
internal void CloneSubGraph(Rule rule, Backend org, Backend extra, Dictionary <State, State> srcToDestHash, bool fromOrg) { Backend backend = fromOrg ? org : extra; List <State> list = new List <State>(); Dictionary <Tag, Tag> endArcs = new Dictionary <Tag, Tag>(); CloneState(rule._firstState, list, srcToDestHash); while (list.Count > 0) { State state = list[0]; list.RemoveAt(0); State start = srcToDestHash[state]; foreach (Arc outArc in state.OutArcs) { State end = outArc.End; State end2 = null; if (end != null) { if (!srcToDestHash.ContainsKey(end)) { CloneState(end, list, srcToDestHash); } end2 = srcToDestHash[end]; } int idWord = outArc.WordId; if (backend != null && outArc.WordId > 0) { _words.Add(backend.Words[outArc.WordId], out idWord); } Arc arc2 = new Arc(outArc, start, end2, idWord); arc2.CloneTags(outArc, _tags, endArcs, this); if (outArc.RuleRef != null) { string text; if (outArc.RuleRef.Name.IndexOf("URL:DYNAMIC#", StringComparison.Ordinal) == 0) { text = outArc.RuleRef.Name.Substring(12); if (fromOrg && FindInRules(text) == null) { Rule rule2 = extra.FindInRules(text); if (rule2 == null) { XmlParser.ThrowSrgsException(SRID.DynamicRuleNotFound, text); } CloneSubGraph(rule2, org, extra, srcToDestHash, false); } } else if (outArc.RuleRef.Name.IndexOf("URL:STATIC#", StringComparison.Ordinal) == 0) { text = outArc.RuleRef.Name.Substring(11); if (!fromOrg && FindInRules(text) == null) { Rule rule3 = org.FindInRules(text); if (rule3 == null) { XmlParser.ThrowSrgsException(SRID.DynamicRuleNotFound, text); } CloneSubGraph(rule3, org, extra, srcToDestHash, true); } } else { text = outArc.RuleRef.Name; Rule rule4 = org.FindInRules(text); if (!fromOrg) { CloneSubGraph(outArc.RuleRef, org, extra, srcToDestHash, true); } } Rule rule5 = FindInRules(text); if (rule5 == null) { rule5 = CloneState(outArc.RuleRef._firstState, list, srcToDestHash); } arc2.RuleRef = rule5; } arc2.ConnectStates(); } } }