Beispiel #1
0
        void Reorder(Direction dir, Match match)
        {
            if (match.EntireMatch.Count == 0)
            {
                return;
            }

            PhoneticShapeNode first = null;
            PhoneticShapeNode last  = null;

            switch (dir)
            {
            case Direction.RIGHT:
                first = match.EntireMatch[0];
                last  = match.EntireMatch[match.EntireMatch.Count - 1];
                break;

            case Direction.LEFT:
                first = match.EntireMatch[match.EntireMatch.Count - 1];
                last  = match.EntireMatch[0];
                break;
            }

            // remove the matching segments, so that we can reinsert them in the
            // new order
            PhoneticShapeNode cur = first.Prev;

            for (PhoneticShapeNode node = first; node != last.Next; node = node.Next)
            {
                node.Remove();
            }

            // reinsert the segments in the new order
            for (int i = 0; i < m_lhsTemp.Count; i++)
            {
                IList <PhoneticShapeNode> partNodes = match.GetPartition(i);
                if (partNodes == null)
                {
                    continue;
                }

                IEnumerable <PhoneticShapeNode> partEnum = dir == Direction.RIGHT ? partNodes
                                        : ReverseNodes(partNodes);
                foreach (PhoneticShapeNode node in partEnum)
                {
                    cur.Insert(node, Direction.RIGHT);
                    cur = node;
                }
            }
        }
Beispiel #2
0
            bool UnapplyNarrow(PhoneticShape input)
            {
                List <Match>      matches = new List <Match>();
                PhoneticShapeNode node    = input.First;
                Match             match;

                // deletion subrules are always treated like simultaneous subrules during unapplication
                while (FindNextMatchRHS(node, Direction.RIGHT, out match))
                {
                    matches.Add(match);
                    node = match.EntireMatch[0].Next;
                }

                foreach (Match m in matches)
                {
                    PhoneticShapeNode cur = m.EntireMatch[m.EntireMatch.Count - 1];
                    foreach (PhoneticPatternNode lhsNode in m_rule.m_lhs)
                    {
                        if (lhsNode.Type != PhoneticPatternNode.NodeType.SIMP_CTXT)
                        {
                            continue;
                        }

                        SimpleContext ctxt   = lhsNode as SimpleContext;
                        Segment       newSeg = ctxt.UnapplyDeletion(m.VariableValues);
                        // mark the undeleted segment as optional
                        newSeg.IsOptional = true;
                        cur.Insert(newSeg, Direction.RIGHT);
                        cur = newSeg;
                    }

                    if (m_analysisTarget.Count > 0)
                    {
                        foreach (PhoneticShapeNode matchNode in m.EntireMatch)
                        {
                            matchNode.IsOptional = true;
                        }
                    }
                }

                return(matches.Count > 0);
            }
Beispiel #3
0
            void ApplyInsertion(Direction dir, IList <PhoneticShapeNode> match, VariableValues instantiatedVars)
            {
                PhoneticShapeNode cur = match[match.Count - 1];

                for (PhoneticPatternNode pseqNode = m_rhs.GetFirst(dir); pseqNode != null;
                     pseqNode = pseqNode.GetNext(dir))
                {
                    PhoneticShapeNode newNode = null;
                    switch (pseqNode.Type)
                    {
                    case PhoneticPatternNode.NodeType.SIMP_CTXT:
                        SimpleContext ctxt = pseqNode as SimpleContext;
                        newNode = ctxt.ApplyInsertion(instantiatedVars);
                        break;

                    case PhoneticPatternNode.NodeType.BDRY_CTXT:
                        newNode = new Boundary(pseqNode as BoundaryContext);
                        break;
                    }

                    if (newNode != null)
                    {
                        try
                        {
                            cur.Insert(newNode, dir);
                        }
                        catch (InvalidOperationException ioe)
                        {
                            MorphException me = new MorphException(MorphException.MorphErrorType.TOO_MANY_SEGS, m_rule.Morpher,
                                                                   string.Format(HCStrings.kstidTooManySegs, m_rule.ID), ioe);
                            me.Data["rule"] = m_rule.ID;
                            throw me;
                        }
                        cur = newNode;
                    }
                }
            }