Example #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;
				}
			}
		}
		/// <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);
				}
			}
		}
		/// <summary>
		/// Unapplies this transform to the specified partition in the specified match.
		/// </summary>
		/// <param name="match">The match.</param>
		/// <param name="partition">The partition.</param>
		/// <param name="output">The output.</param>
		public void Unapply(Match match, int partition, PhoneticShape output)
		{
			IList<PhoneticShapeNode> nodes = match.GetPartition(partition);
			if (nodes != null && nodes.Count > 0)
			{
				SimpleContext ctxt;
				if (!m_modifyFromCtxts.TryGetValue(partition, out ctxt))
					ctxt = null;

				foreach (PhoneticShapeNode node in nodes)
				{
					switch (node.Type)
					{
						case PhoneticShapeNode.NodeType.SEGMENT:
							Segment newSeg = new Segment(node as Segment);
							// if there is a modify-from context on this partition, unapply it
							if (ctxt != null)
								ctxt.Unapply(newSeg, match.VariableValues);
							output.Add(newSeg);
							break;

						case PhoneticShapeNode.NodeType.BOUNDARY:
							output.Add(node.Clone());
							break;
					}
				}
			}
			else
			{
				// untruncate a partition
				Untruncate(m_lhs[partition], output, false, match.VariableValues);
			}
		}
		/// <summary>
		/// Copies a partition from the input phonetic shape 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;
				for (PhoneticShapeNode node = nodes[0]; node != nodes[nodes.Count - 1].Next; node = node.Next)
				{
					PhoneticShapeNode newNode = node.Clone();
					// mark the reduplicated segments with the gloss partition
					if (m_redup)
					{
						if (allomorph != null)
						{
							if (morph == null)
							{
								morph = new Morph(allomorph);
								output.Morphs.Add(morph);
							}
							newNode.Partition = morph.Partition;
							morph.Shape.Add(node.Clone());
						}
						else
						{
							newNode.Partition = -1;
						}
					}
					else if (node.Partition != -1)
					{
						if (morph == null || morph.Partition != node.Partition)
						{
							morph = input.Morphs[node.Partition].Clone();
							morph.Shape.Clear();
							output.Morphs.Add(morph);
						}
						newNode.Partition = morph.Partition;
						morph.Shape.Add(node.Clone());
					}
					output.Shape.Add(newNode);
				}
			}
		}