Esempio n. 1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Subrule"/> class.
            /// </summary>
            /// <param name="rhs">The RHS.</param>
            /// <param name="env">The environment.</param>
            /// <param name="rule">The phonological rule.</param>
            /// <exception cref="System.ArgumentException">Thrown when the size of the RHS is greater than the
            /// size of the specified rule's LHS and the LHS's size is greater than 1. A standard phonological
            /// rule does not currently support this type of widening.</exception>
            public Subrule(PhoneticPattern rhs, Environment env, StandardPhonologicalRule rule)
            {
                m_rhs  = rhs;
                m_env  = env;
                m_rule = rule;

                switch (Type)
                {
                case ChangeType.NARROW:
                case ChangeType.EPENTHESIS:
                    // analysis target is a copy of the RHS, because there is no LHS
                    m_analysisTarget = m_rhs.Clone();
                    break;

                case ChangeType.WIDEN:
                    // before generating the analysis we must extend the length of the LHS
                    // to match the length of the RHS
                    PhoneticPattern lhs = m_rule.m_lhs.Clone();
                    while (lhs.Count != m_rhs.Count)
                    {
                        lhs.Add(lhs.First.Clone());
                    }
                    m_analysisTarget = m_rhs.Combine(lhs);
                    break;

                case ChangeType.FEATURE:
                    m_analysisTarget = m_rhs.Combine(m_rule.m_lhs);
                    break;

                case ChangeType.UNKNOWN:
                    throw new ArgumentException(HCStrings.kstidInvalidSubruleType, "rhs");
                }
            }
Esempio n. 2
0
        PhoneticPattern GenerateChangePartition(PhoneticPattern lhs, PhoneticPattern rhs)
        {
            PhoneticPattern result = new PhoneticPattern();

            foreach (PhoneticPatternNode node in lhs)
            {
                switch (node.Type)
                {
                case PhoneticPatternNode.NodeType.SIMP_CTXT:
                    PhoneticPattern temp = new PhoneticPattern();
                    temp.Add(node.Clone());
                    // generates the RHS template the same way that phonological rules generate their
                    // RHS analysis targets
                    result.AddMany(rhs.Combine(temp));
                    break;

                case PhoneticPatternNode.NodeType.PATTERN:
                    NestedPhoneticPattern nestedPattern    = node as NestedPhoneticPattern;
                    PhoneticPattern       pattern          = GenerateChangePartition(nestedPattern.Pattern, rhs);
                    NestedPhoneticPattern newNestedPattern = new NestedPhoneticPattern(pattern, nestedPattern.MinOccur,
                                                                                       nestedPattern.MaxOccur);
                    result.Add(newNestedPattern);
                    break;
                }
            }
            return(result);
        }