Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Match"/> class.
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="vars">The instantiated variables.</param>
 internal Match(PhoneticPattern pattern, VariableValues vars)
 {
     m_pattern          = pattern;
     m_partitions       = new Dictionary <int, List <PhoneticShapeNode> >();
     m_entireMatch      = new List <PhoneticShapeNode>();
     m_instantiatedVars = vars.Clone();
 }
Beispiel #2
0
        void Untruncate(PhoneticPattern lhs, PhoneticShape output, bool optional, VariableValues instantiatedVars)
        {
            // create segments from the LHS partition pattern and append them to the output
            foreach (PhoneticPatternNode node in lhs)
            {
                switch (node.Type)
                {
                case PhoneticPatternNode.NodeType.SIMP_CTXT:
                    SimpleContext ctxt   = node as SimpleContext;
                    Segment       newSeg = ctxt.UnapplyDeletion(instantiatedVars);
                    newSeg.IsOptional = optional;
                    output.Add(newSeg);
                    break;

                case PhoneticPatternNode.NodeType.PATTERN:
                    NestedPhoneticPattern nestedPattern = node as NestedPhoneticPattern;
                    // untruncate nested partitions the maximum number of times it can occur,
                    // marking any segments that occur after the minimum number of occurrences
                    // as optional
                    for (int j = 0; j < nestedPattern.MaxOccur; j++)
                    {
                        Untruncate(nestedPattern.Pattern, output, j >= nestedPattern.MinOccur, instantiatedVars);
                    }
                    break;

                case PhoneticPatternNode.NodeType.BDRY_CTXT:
                    // skip boundaries
                    break;
                }
            }
        }
Beispiel #3
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)
 {
     // copy LHS partition over the RHS, only indicate the partition if this is
     // the first time this partition is being copied
     rhsTemp.AddPartition(lhs[m_partition], m_redup ? -1 : m_partition);
 }
Beispiel #4
0
 public void Reset()
 {
     m_multApplication = MultAppOrder.LR_ITERATIVE;
     m_alphaVars       = null;
     m_lhs             = null;
     m_subrules.Clear();
 }
Beispiel #5
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 #6
0
            /// <summary>
            /// Checks for overlap of features between the specified simple context and the specified
            /// environment.
            /// </summary>
            /// <param name="ctxt">The simple context.</param>
            /// <param name="envSeq">The environment.</param>
            /// <returns>
            ///     <c>true</c> if there is no overlap, otherwise <c>false</c>.
            /// </returns>
            bool IsNonSelfOpaquing(SimpleContext ctxt, PhoneticPattern env)
            {
                foreach (PhoneticPatternNode node in env)
                {
                    switch (node.Type)
                    {
                    case PhoneticPatternNode.NodeType.SIMP_CTXT:
                        SimpleContext envCtxt = node as SimpleContext;
                        if (!envCtxt.FeatureValues.IsDisjoint(ctxt.AntiFeatureValues))
                        {
                            return(false);
                        }
                        break;

                    case PhoneticPatternNode.NodeType.BDRY_CTXT:
                        break;

                    case PhoneticPatternNode.NodeType.PATTERN:
                        NestedPhoneticPattern optSeq = node as NestedPhoneticPattern;
                        if (!IsNonSelfOpaquing(ctxt, optSeq.Pattern))
                        {
                            return(false);
                        }
                        break;
                    }
                }

                return(true);
            }
Beispiel #7
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 #8
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 #9
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="nestedPattern">The nested pattern.</param>
 public NestedPhoneticPattern(NestedPhoneticPattern nestedPattern)
     : base(nestedPattern)
 {
     m_pattern  = new PhoneticPattern(nestedPattern.m_pattern);
     m_minOccur = nestedPattern.m_minOccur;
     m_maxOccur = nestedPattern.m_maxOccur;
 }
Beispiel #10
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 #11
0
        bool ProcessIterative(PhoneticShape input, Direction dir, PhoneticPattern ptemp, ModeType mode)
        {
            bool reordered         = false;
            PhoneticShapeNode node = input.GetFirst(dir);
            Match             match;

            // iterate thru each match
            while (FindNextMatch(node, dir, ptemp, mode, out match))
            {
                // reorder the matching segments
                Reorder(dir, match);
                reordered = true;
                IList <PhoneticShapeNode> nodes = match.EntireMatch;
                node = nodes[nodes.Count - 1].GetNext(dir);
            }

            return(reordered);
        }
Beispiel #12
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 #13
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 #14
0
        bool FindNextMatch(PhoneticShapeNode node, Direction dir, PhoneticPattern ptemp, ModeType mode,
                           out Match match)
        {
            for (; node != node.Owner.GetLast(dir); node = node.GetNext(dir))
            {
                if (mode == ModeType.ANALYSIS && node.Type == PhoneticShapeNode.NodeType.BOUNDARY)
                {
                    continue;
                }

                IList <Match> matches;
                if (ptemp.IsMatch(node, dir, mode, out matches))
                {
                    match = matches[0];
                    return(true);
                }
            }

            match = null;
            return(false);
        }
Beispiel #15
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 #16
0
            void UnapplyRHS(Direction dir, IList <PhoneticShapeNode> match, VariableValues instantiatedVars)
            {
                switch (Type)
                {
                case ChangeType.FEATURE:
                    int i = 0;
                    // if there are no phonetic features, unapply using the LHS, since we are simply replacing
                    PhoneticPattern unappPattern = m_rule.Morpher.PhoneticFeatureSystem.HasFeatures ? m_analysisTarget : m_rule.m_lhs;
                    for (PhoneticPatternNode pseqNode = unappPattern.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?
                            Segment seg = match[i] as Segment;
                            ctxt.Unapply(seg, instantiatedVars);
                            break;

                        case PhoneticPatternNode.NodeType.BDRY_CTXT:
                            // skip boundaries
                            continue;
                        }
                        i++;
                    }
                    break;

                case ChangeType.EPENTHESIS:
                    // do not remove epenthesized segments, since it is possible that they will not
                    // be epenthesized during synthesis, we just mark them as optional
                    foreach (PhoneticShapeNode node in match)
                    {
                        node.IsOptional = true;
                    }
                    break;
                }
            }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NestedPhoneticPattern"/> class.
 /// </summary>
 /// <param name="pattern">The phonetic pattern.</param>
 /// <param name="minOccur">The minimum number of occurrences.</param>
 /// <param name="maxOccur">The maximum number of occurrences.</param>
 public NestedPhoneticPattern(PhoneticPattern pattern, int minOccur, int maxOccur)
 {
     m_pattern  = pattern;
     m_minOccur = minOccur;
     m_maxOccur = maxOccur;
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Environment"/> class.
 /// </summary>
 /// <param name="leftEnv">The left environment.</param>
 /// <param name="rightEnv">The right environment.</param>
 public Environment(PhoneticPattern leftEnv, PhoneticPattern rightEnv)
 {
     m_leftEnv  = leftEnv;
     m_rightEnv = rightEnv;
 }
Beispiel #19
0
 /// <summary>
 /// Generates the RHS template of a morphological rule. If the record
 /// modifies the input using a simple context, it should add that context
 /// to varFeats of modify-from contexts. It is used during unapplication.
 /// The reduplication flags are used to indicate that the same input partition
 /// is being copied multiple times.
 /// </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 abstract void GenerateRHSTemplate(PhoneticPattern rhsTemp, IList <PhoneticPattern> lhs,
                                          IDictionary <int, SimpleContext> modifyFromCtxts);
Beispiel #20
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());
 }