Beispiel #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Subrule"/> class.
            /// </summary>
            /// <param name="id">The id.</param>
            /// <param name="desc">The description.</param>
            /// <param name="morpher">The morpher.</param>
            /// <param name="headLhs">The head LHS.</param>
            /// <param name="nonHeadLhs">The non-head LHS.</param>
            /// <param name="rhs">The RHS.</param>
            /// <param name="alphaVars">The alpha variables.</param>
            public Subrule(string id, string desc, Morpher morpher, IEnumerable <PhoneticPattern> headLhs,
                           IEnumerable <PhoneticPattern> nonHeadLhs, IEnumerable <MorphologicalOutput> rhs, AlphaVariables alphaVars)
                : base(id, desc, morpher)
            {
                m_alphaVars = alphaVars;

                List <PhoneticPattern> lhs = new List <PhoneticPattern>();

                lhs.AddRange(headLhs);
                lhs.AddRange(nonHeadLhs);

                m_transform = new MorphologicalTransform(lhs, rhs, MorphologicalTransform.RedupMorphType.IMPLICIT);

                // the LHS template is generated by simply concatenating all of the
                // LHS partitions; it matches the entire word, so we check for both the
                // left and right margins.
                m_headLhsTemp = new PhoneticPattern();
                m_headLhsTemp.Add(new MarginContext(Direction.LEFT));
                int partition = 0;

                foreach (PhoneticPattern pat in headLhs)
                {
                    m_headLhsTemp.AddPartition(pat, partition++);
                }
                m_headLhsTemp.Add(new MarginContext(Direction.RIGHT));

                m_firstNonHeadPartition = partition;
                m_nonHeadLhsTemp        = new PhoneticPattern();
                m_nonHeadLhsTemp.Add(new MarginContext(Direction.LEFT));
                foreach (PhoneticPattern pat in nonHeadLhs)
                {
                    m_nonHeadLhsTemp.AddPartition(pat, partition++);
                }
                m_nonHeadLhsTemp.Add(new MarginContext(Direction.RIGHT));
            }
Beispiel #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);
        }
Beispiel #3
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");
                }
            }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MorphologicalTransform"/> class.
        /// </summary>
        /// <param name="lhs">The LHS.</param>
        /// <param name="rhs">The RHS.</param>
        public MorphologicalTransform(IEnumerable <PhoneticPattern> lhs, IEnumerable <MorphologicalOutput> rhs, RedupMorphType redupMorphType)
        {
            m_lhs             = new List <PhoneticPattern>(lhs);
            m_rhs             = new List <MorphologicalOutput>(rhs);
            m_modifyFromCtxts = new Dictionary <int, SimpleContext>();

            // reduplication flags for each morphological output record
            CheckReduplication(redupMorphType);

            m_rhsTemp         = new PhoneticPattern();
            m_modifyFromCtxts = new Dictionary <int, SimpleContext>();
            m_rhsTemp.Add(new MarginContext(Direction.LEFT));
            for (int i = 0; i < m_rhs.Count; i++)
            {
                m_rhs[i].GenerateRHSTemplate(m_rhsTemp, m_lhs, m_modifyFromCtxts);
            }
            m_rhsTemp.Add(new MarginContext(Direction.RIGHT));
        }
Beispiel #5
0
        /// <summary>
        /// Generates the RHS template.
        /// </summary>
        /// <param name="rhsTemp">The RHS template.</param>
        /// <param name="lhs">The LHS.</param>
        /// <param name="modifyFromCtxts">The modify-from contexts.</param>
        /// <param name="redup">The reduplication flag.</param>
        public override void GenerateRHSTemplate(PhoneticPattern rhsTemp, IList <PhoneticPattern> lhs,
                                                 IDictionary <int, SimpleContext> modifyFromCtxts)
        {
            for (PhoneticShapeNode node = m_pshape.Begin; node != m_pshape.Last; node = node.Next)
            {
                // create contexts from the segments and boundaries in the phonetic shape
                // and append them to the RHS template
                switch (node.Type)
                {
                case PhoneticShapeNode.NodeType.SEGMENT:
                    rhsTemp.Add(new SegmentContext(node as Segment));
                    break;

                case PhoneticShapeNode.NodeType.BOUNDARY:
                    rhsTemp.Add(new BoundaryContext(node as Boundary));
                    break;
                }
            }
        }
Beispiel #6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Subrule"/> class.
            /// </summary>
            /// <param name="id">The id.</param>
            /// <param name="desc">The description.</param>
            /// <param name="morpher">The morpher.</param>
            /// <param name="lhs">The LHS.</param>
            /// <param name="rhs">The RHS.</param>
            /// <param name="alphaVars">The alpha variables.</param>
            /// <param name="redupMorphType">The full reduplication type.</param>
            public Subrule(string id, string desc, Morpher morpher, IEnumerable <PhoneticPattern> lhs,
                           IEnumerable <MorphologicalOutput> rhs, AlphaVariables alphaVars, MorphologicalTransform.RedupMorphType redupMorphType)
                : base(id, desc, morpher)
            {
                m_alphaVars = alphaVars;

                m_transform = new MorphologicalTransform(lhs, rhs, redupMorphType);

                // the LHS template is generated by simply concatenating all of the
                // LHS partitions; it matches the entire word, so we check for both the
                // left and right margins.
                m_lhsTemp = new PhoneticPattern();
                m_lhsTemp.Add(new MarginContext(Direction.LEFT));
                int partition = 0;

                foreach (PhoneticPattern pat in lhs)
                {
                    m_lhsTemp.AddPartition(pat, partition, m_transform.IsGreedy(partition));
                    partition++;
                }
                m_lhsTemp.Add(new MarginContext(Direction.RIGHT));
            }
Beispiel #7
0
        /// <summary>
        /// Generates the RHS template of a morphological rule.
        /// </summary>
        /// <param name="rhsTemp">The RHS template.</param>
        /// <param name="lhs">The LHS.</param>
        /// <param name="modifyFromCtxts">The modify-from contexts.</param>
        /// <param name="redup">The reduplication flag.</param>
        public override void GenerateRHSTemplate(PhoneticPattern rhsTemp, IList <PhoneticPattern> lhs,
                                                 IDictionary <int, SimpleContext> modifyFromCtxts)
        {
            PhoneticPattern ctxtPattern = new PhoneticPattern();

            ctxtPattern.Add(m_ctxt);
            // combines the simple context with all of the simple contexts on the LHS
            // and adds the results to the RHS template
            PhoneticPattern pattern = GenerateChangePartition(lhs[m_partition], ctxtPattern);

            rhsTemp.AddPartition(pattern, m_redup ? -1 : m_partition);
            // add context to the modify-from contexts
            modifyFromCtxts[m_partition] = m_ctxt;
        }
Beispiel #8
0
 /// <summary>
 /// Generates the RHS template of a morphological rule.
 /// </summary>
 /// <param name="rhsTemp">The RHS template.</param>
 /// <param name="lhs">The LHS.</param>
 /// <param name="modifyFromCtxts">The modify-from contexts.</param>
 /// <param name="redup">The reduplication flag.</param>
 public override void GenerateRHSTemplate(PhoneticPattern rhsTemp, IList <PhoneticPattern> lhs,
                                          IDictionary <int, SimpleContext> modifyFromCtxts)
 {
     rhsTemp.Add(m_ctxt.Clone());
 }