Example #1
0
        /// <summary>
        /// Applies the simple context to the input partition and copies it over to the output
        /// phonetic shape.
        /// </summary>
        /// <param name="match">The match.</param>
        /// <param name="input">The input word synthesis.</param>
        /// <param name="output">The output word synthesis.</param>
        /// <param name="morpheme">The morpheme info.</param>
        public override void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph)
        {
            IList <PhoneticShapeNode> nodes = match.GetPartition(m_partition);

            if (nodes != null && nodes.Count > 0)
            {
                Morph morph = null;
                if (allomorph != null)
                {
                    morph = new Morph(allomorph);
                    output.Morphs.Add(morph);
                }
                for (PhoneticShapeNode node = nodes[0]; node != nodes[nodes.Count - 1].Next; node = node.Next)
                {
                    PhoneticShapeNode newNode = node.Clone();
                    if (node.Type == PhoneticShapeNode.NodeType.SEGMENT)
                    {
                        Segment seg = newNode as Segment;
                        // sets the context's features on the segment
                        m_ctxt.Apply(seg, match.VariableValues);
                        seg.IsClean   = false;
                        seg.Partition = morph == null ? -1 : morph.Partition;
                    }
                    if (morph != null)
                    {
                        morph.Shape.Add(newNode.Clone());
                    }
                    output.Shape.Add(newNode);
                }
            }
        }
Example #2
0
            /// <summary>
            /// Applies the RHS to the matched segments.
            /// </summary>
            /// <param name="dir">The direction.</param>
            /// <param name="match">The matched segments.</param>
            /// <param name="instantiatedVars">The instantiated variables.</param>
            public void ApplyRHS(Direction dir, IList <PhoneticShapeNode> match, VariableValues instantiatedVars)
            {
                switch (Type)
                {
                case ChangeType.FEATURE:
                    int i = 0;
                    for (PhoneticPatternNode pseqNode = m_rhs.GetFirst(dir); pseqNode != null;
                         pseqNode = pseqNode.GetNext(dir))
                    {
                        switch (pseqNode.Type)
                        {
                        case PhoneticPatternNode.NodeType.SIMP_CTXT:
                            SimpleContext ctxt = pseqNode as SimpleContext;
                            // match[i] should be a segment, should I check that here?
                            while (match[i].Type == PhoneticShapeNode.NodeType.BOUNDARY)
                            {
                                i++;
                            }
                            Segment seg = match[i] as Segment;
                            ctxt.Apply(seg, instantiatedVars);
                            // marked the segment as altered
                            seg.IsClean = false;
                            break;

                        case PhoneticPatternNode.NodeType.BDRY_CTXT:
                            // boundaries should match, should I check that here?
                            break;
                        }
                        i++;
                    }
                    break;

                case ChangeType.NARROW:
                    ApplyInsertion(dir, match, instantiatedVars);
                    // remove matching segments
                    foreach (PhoneticShapeNode node in match)
                    {
                        node.Remove();
                    }
                    break;

                case ChangeType.EPENTHESIS:
                    // insert new segments or boundaries
                    ApplyInsertion(dir, match, instantiatedVars);
                    break;
                }
            }