Exemplo n.º 1
0
        /// <summary>
        /// Combines this pattern with the specified pattern. This is used by phonological rules to
        /// generate the RHS target and by morphological rules to generate the RHS template for
        /// modify-from output records. The patterns must be the same size.
        /// </summary>
        /// <param name="pattern">The pattern.</param>
        /// <returns>The phonetic pattern which is a combination of this pattern and the specified pattern.</returns>
        /// <exception cref="System.ArgumentException">Thrown when the size of <c>pattern</c> does not match the size of this pattern.</exception>
        public PhoneticPattern Combine(PhoneticPattern pattern)
        {
            if (Count != pattern.Count)
            {
                throw new ArgumentException(HCStrings.kstidPatternCombine, "pattern");
            }

            PhoneticPattern     result  = new PhoneticPattern();
            PhoneticPatternNode lhsNode = pattern.First;

            foreach (PhoneticPatternNode rhsNode in this)
            {
                // combine the simple contexts
                if (rhsNode.Type == PhoneticPatternNode.NodeType.SIMP_CTXT &&
                    lhsNode.Type == PhoneticPatternNode.NodeType.SIMP_CTXT)
                {
                    SimpleContext rhsCtxt = rhsNode as SimpleContext;
                    SimpleContext lhsCtxt = lhsNode as SimpleContext;

                    result.Add(rhsCtxt.Combine(lhsCtxt));
                }
                lhsNode = lhsNode.GetNext();
            }

            return(result);
        }