internal State CloneSubGraph(State srcFromState, State srcEndState, State destFromState) { Dictionary <State, State> dictionary = new Dictionary <State, State>(); Stack <State> stack = new Stack <State>(); Dictionary <Tag, Tag> endArcs = new Dictionary <Tag, Tag>(); dictionary.Add(srcFromState, destFromState); stack.Push(srcFromState); while (stack.Count > 0) { srcFromState = stack.Pop(); destFromState = dictionary[srcFromState]; foreach (Arc outArc in srcFromState.OutArcs) { State end = outArc.End; State state = null; if (end != null) { if (!dictionary.ContainsKey(end)) { state = CreateNewState(end.Rule); dictionary.Add(end, state); stack.Push(end); } else { state = dictionary[end]; } } Arc arc2 = new Arc(outArc, destFromState, state); AddArc(arc2); arc2.CloneTags(outArc, _tags, endArcs, null); arc2.ConnectStates(); } } return(dictionary[srcEndState]); }
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(); } } }