Exemplo n.º 1
0
        /// <summary>
        /// Checks if the specified phonetic shape matches this environment.
        /// </summary>
        /// <param name="leftNode">The left node.</param>
        /// <param name="rightNode">The right node.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="instantiatedVars">The instantiated variables.</param>
        /// <returns>
        ///     <c>true</c> if the shape successfully matched this pattern, otherwise <c>false</c>.
        /// </returns>
        public bool IsMatch(PhoneticShapeNode leftNode, PhoneticShapeNode rightNode, ModeType mode, VariableValues instantiatedVars)
        {
            VariableValues temp = instantiatedVars.Clone();

            // right environment
            if (m_rightEnv != null)
            {
                IList <Match> matches;
                if (m_rightEnv.IsMatch(rightNode, Direction.RIGHT, mode, temp, out matches))
                {
                    temp.ReplaceValues(matches[0].VariableValues);
                }
                else
                {
                    return(false);
                }
            }

            // left environment
            if (m_leftEnv != null)
            {
                IList <Match> matches;
                if (m_leftEnv.IsMatch(leftNode, Direction.LEFT, mode, temp, out matches))
                {
                    temp.ReplaceValues(matches[0].VariableValues);
                }
                else
                {
                    return(false);
                }
            }

            instantiatedVars.ReplaceValues(temp);
            return(true);
        }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
        public override bool IsUnapplicationVacuous(Segment seg, VariableValues instantiatedVars)
        {
            if (base.IsUnapplicationVacuous(seg, instantiatedVars))
            {
                return(true);
            }

            // check if the context's anti variables have already been set
            if (!m_alphaVars.GetBinding(m_antiVariables, seg, instantiatedVars.Clone()))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
		public override bool IsUnapplicationVacuous(Segment seg, VariableValues instantiatedVars)
		{
			if (base.IsUnapplicationVacuous(seg, instantiatedVars))
				return true;

			// check if the context's anti variables have already been set
			if (!m_alphaVars.GetBinding(m_antiVariables, seg, instantiatedVars.Clone()))
				return true;

			return false;
		}
Exemplo n.º 5
0
		/// <summary>
		/// Checks if the specified phonetic shape node matches this simple context.
		/// </summary>
		/// <param name="node">The phonetic shape node.</param>
		/// <param name="dir">The direction.</param>
		/// <param name="mode">The mode.</param>
		/// <param name="instantiatedVars">The instantiated variables.</param>
		/// <returns>All matches.</returns>
		internal override IList<Match> Match(PhoneticShapeNode node, Direction dir, ModeType mode,
			VariableValues instantiatedVars)
		{
			switch (node.Type)
			{
				case PhoneticShapeNode.NodeType.BOUNDARY:
					// only check boundaries in synthesis mode when the pattern is a target,
					// otherwise skip
					if (mode == ModeType.SYNTHESIS)
					{
						if (Owner.IsTarget)
						{
							return new List<Match>();
						}
						else
						{
							IList<Match> bdryMatches = Match(GetNextShapeNode(node, dir), dir, mode, instantiatedVars);
							foreach (Match match in bdryMatches)
								match.Add(node, m_partition);
							return bdryMatches;
						}
					}
					else
					{
						return Match(GetNextShapeNode(node, dir), dir, mode, instantiatedVars);
					}

				case PhoneticShapeNode.NodeType.MARGIN:
					Margin margin = node as Margin;
					if (dir == margin.MarginType)
						// we are at the end of the shape, so no match
						return new List<Match>();
					else
						return Match(GetNextShapeNode(node, dir), dir, mode, instantiatedVars);

				case PhoneticShapeNode.NodeType.SEGMENT:
					Segment seg = node as Segment;
					if (mode == ModeType.SYNTHESIS && Owner.IsTarget)
					{
						// check segment to see if it has already been altered by another
						// subrule, only matters for simultaneously applying rules
						if (!seg.IsClean)
							return new List<Match>();
					}

					VariableValues tempVars = instantiatedVars.Clone();
					if (m_featSys.HasFeatures)
					{
						if (!IsFeatureMatch(seg, tempVars, mode))
							return new List<Match>();
					}
					else
					{
						if (!IsSegmentMatch(seg))
							return new List<Match>();
					}

					// move to the next node
					IList<Match> segMatches = MatchNext(node, dir, mode, tempVars);
					foreach (Match match in segMatches)
						match.Add(node, m_partition);

					return segMatches;
			}

			return new List<Match>();
		}
Exemplo n.º 6
0
        /// <summary>
        /// Checks if the specified phonetic shape node matches this simple context.
        /// </summary>
        /// <param name="node">The phonetic shape node.</param>
        /// <param name="dir">The direction.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="instantiatedVars">The instantiated variables.</param>
        /// <returns>All matches.</returns>
        internal override IList <Match> Match(PhoneticShapeNode node, Direction dir, ModeType mode,
                                              VariableValues instantiatedVars)
        {
            switch (node.Type)
            {
            case PhoneticShapeNode.NodeType.BOUNDARY:
                // only check boundaries in synthesis mode when the pattern is a target,
                // otherwise skip
                if (mode == ModeType.SYNTHESIS)
                {
                    if (Owner.IsTarget)
                    {
                        return(new List <Match>());
                    }
                    else
                    {
                        IList <Match> bdryMatches = Match(node.GetNext(dir), dir, mode, instantiatedVars);
                        foreach (Match match in bdryMatches)
                        {
                            match.Add(node, m_partition);
                        }
                        return(bdryMatches);
                    }
                }
                else
                {
                    return(Match(node.GetNext(dir), dir, mode, instantiatedVars));
                }

            case PhoneticShapeNode.NodeType.MARGIN:
                Margin margin = node as Margin;
                if (dir == margin.MarginType)
                {
                    // we are at the end of the shape, so no match
                    return(new List <Match>());
                }
                else
                {
                    return(Match(node.GetNext(dir), dir, mode, instantiatedVars));
                }

            case PhoneticShapeNode.NodeType.SEGMENT:
                Segment seg = node as Segment;
                if (mode == ModeType.SYNTHESIS && Owner.IsTarget)
                {
                    // check segment to see if it has already been altered by another
                    // subrule, only matters for simultaneously applying rules
                    if (!seg.IsClean)
                    {
                        return(new List <Match>());
                    }
                }

                VariableValues tempVars = instantiatedVars.Clone();
                if (m_featSys.HasFeatures)
                {
                    if (!IsFeatureMatch(seg, tempVars, mode))
                    {
                        return(new List <Match>());
                    }
                }
                else
                {
                    if (!IsSegmentMatch(seg))
                    {
                        return(new List <Match>());
                    }
                }

                // move to the next node
                IList <Match> segMatches = MatchNext(node, dir, mode, tempVars);
                foreach (Match match in segMatches)
                {
                    match.Add(node, m_partition);
                }

                return(segMatches);
            }

            return(new List <Match>());
        }