示例#1
0
        /// <summary>
        /// Detects whether the two FSTs are identical. Identity is stronger than equality in that
        /// the state numbering and all other information must be the same.
        /// </summary>
        /// <param name="other">The FST to compare to.</param>
        /// <returns>true if both FSTs are identical, false otherwise</returns>
        public bool IsIdentical(FST other)
        {
            if (other == null)
            {
                throw new ArgumentNullException();
            }

            if (_MaxState != other._MaxState ||
                _StartState != other._StartState ||
                _States.Count != other._States.Count)
            {
                return(false);
            }

            SortTransitions();
            other.SortTransitions();

            foreach (KeyValuePair <int, State> kvp in _States)
            {
                State otherState;
                if (!other._States.TryGetValue(kvp.Key, out otherState))
                {
                    return(false);
                }

                if (kvp.Value.IsFinal != otherState.IsFinal ||
                    kvp.Value.IsInitial != otherState.IsInitial ||
                    kvp.Value.TransitionCount != otherState.TransitionCount)
                {
                    return(false);
                }

                for (int t = 0; t < kvp.Value.TransitionCount; ++t)
                {
                    FSTTransition tt = kvp.Value.Transitions[t];
                    FSTTransition ot = otherState.Transitions[t];
                    if (tt.Source != ot.Source ||
                        tt.Target != ot.Target ||
                        tt.Input.Symbol != ot.Input.Symbol ||
                        tt.Output.Symbol != ot.Output.Symbol)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }