Example #1
0
		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="seg">The segment.</param>
		public Segment(Segment seg)
			: base(seg)
		{
			m_desc = seg.m_desc;
			m_segDef = seg.m_segDef;
			m_instantiatedSegs = new Set<SegmentDefinition>(seg.m_instantiatedSegs);
			m_featureValues = seg.m_featureValues.Clone();
			m_isClean = seg.m_isClean;
		}
Example #2
0
		/// <summary>
		/// Gets a valid binding between the specified variables and the feature values
		/// currently set on the specified segment. It adds the variable values to the varFeats of
		/// instantiated variables.
		/// </summary>
		/// <param name="variables">The variables.</param>
		/// <param name="seg">The segment.</param>
		/// <param name="instantiatedVars">The instantiated variables.</param>
		/// <returns><c>true</c> if a valid binding was found, otherwise <c>false</c></returns>
		public bool GetBinding(IDictionary<string, bool> variables, Segment seg, VariableValues instantiatedVars)
		{
			foreach (KeyValuePair<string, bool> varPolarity in variables)
			{
				if (!GetBinding(varPolarity.Key, varPolarity.Value, seg, instantiatedVars))
					return false;
			}

			return true;
		}
Example #3
0
		/// <summary>
		/// Gets a valid binding between the specified variable and the feature values
		/// currently set on the specified segment. It adds the variable value to the varFeats of
		/// instantiated variables.
		/// </summary>
		/// <param name="variable">The variable.</param>
		/// <param name="polarity">The variable polarity.</param>
		/// <param name="seg">The segment.</param>
		/// <param name="instantiatedVars">The instantiated variables.</param>
		/// <returns><c>true</c> if a valid binding was found, otherwise <c>false</c></returns>
		public bool GetBinding(string variable, bool polarity, Segment seg, VariableValues instantiatedVars)
		{
			bool match = false;
			foreach (FeatureValue value in GetVarFeatValue(variable, polarity, instantiatedVars))
			{
				if (seg.FeatureValues.Get(value))
				{
					instantiatedVars.Add(variable, value);
					match = true;
					break;
				}
			}

			return match;
		}
Example #4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SegmentContext"/> class from a segment.
		/// </summary>
		/// <param name="seg">The segment.</param>
		public SegmentContext(Segment seg)
			: base(seg.FeatureValues.Clone(), seg.SegmentDefinition.AntiFeatures.Clone())
		{
			m_segDef = seg.SegmentDefinition;
		}
Example #5
0
		protected override bool IsSegmentMatch(Segment seg)
		{
			return seg.IsSegmentInstantiated(m_segDef);
		}
Example #6
0
		protected abstract bool IsSegmentMatch(Segment seg);
Example #7
0
		public bool Equals(Segment other)
		{
			if (other == null)
				return false;
			if (m_featureValues.FeatureSystem.HasFeatures)
				return m_featureValues.Equals(other.m_featureValues);
			else
				return m_instantiatedSegs.Equals(other.m_instantiatedSegs);
		}
Example #8
0
		protected override Segment ApplyInsertionSegments()
		{
			Segment seg = new Segment(m_segDef, new FeatureBundle(false, m_featSys));
			seg.InstantiateSegment(m_segDef);
			return seg;
		}
Example #9
0
		protected abstract void UnapplySegments(Segment seg);
Example #10
0
		protected override Segment ApplyInsertionSegments()
		{
			Segment seg = new Segment(ToString(), new FeatureBundle(false, m_featSys));
			foreach (SegmentDefinition segDef in m_natClass.SegmentDefinitions)
				seg.InstantiateSegment(segDef);
			return seg;
		}
Example #11
0
		protected override void UnapplyFeatures(Segment seg, VariableValues instantiatedVars)
		{
			seg.FeatureValues.Apply(m_antiFeatureValues, true);
		}
Example #12
0
		protected override void UnapplyFeatures(Segment seg, VariableValues instantiatedVars)
		{
			// set the context's anti features on the segment
			seg.FeatureValues.Apply(m_antiFeatureValues, true);
			m_alphaVars.Apply(seg.FeatureValues, m_antiVariables, instantiatedVars, true);
		}
Example #13
0
		protected override void UnapplySegments(Segment seg)
		{
			foreach (SegmentDefinition segDef in m_natClass.SegmentDefinitions)
				seg.InstantiateSegment(segDef);
		}
Example #14
0
		protected override bool IsSegmentMatch(Segment seg)
		{
			if (m_natClass.NumSegmentDefinitions == 0)
				return true;

			foreach (SegmentDefinition segDef in m_natClass.SegmentDefinitions)
			{
				if (seg.IsSegmentInstantiated(segDef))
					return true;
			}
			return false;
		}
Example #15
0
		protected override bool IsFeatureMatch(Segment seg, VariableValues instantiatedVars, ModeType mode)
		{
			if (!base.IsFeatureMatch(seg, instantiatedVars, mode))
				return false;

			if (m_alphaVars != null)
			{
				// only one possible binding during synthesis
				if (Owner.IsTarget)
				{
					if (!m_alphaVars.GetBinding(m_variables, seg, instantiatedVars))
						return false;
				}
				else if (mode == ModeType.SYNTHESIS)
				{
					if (!m_alphaVars.GetBinding(m_variables, seg, instantiatedVars))
					{
						// when a variable is specified in a target and environment for agreement, the environment
						// must specify a feature for each variable
						foreach (KeyValuePair<string, bool> varPolarity in m_variables)
						{
							// check each variable to see which one is not specified in the environment
							if (!m_alphaVars.GetBinding(varPolarity.Key, varPolarity.Value, seg, new VariableValues(m_alphaVars)))
							{
								Feature f = m_alphaVars.GetFeature(varPolarity.Key);
								MorphException me = new MorphException(MorphException.MorphErrorType.UNINSTANTIATED_FEATURE, m_natClass.Morpher,
									string.Format(HCStrings.kstidUninstEnv, f.ID));
								me.Data["feature"] = f.ID;
								throw me;
							}
						}
						return false;
					}
				}
				else
				{
					// during analysis, get all possible bindings, since a feature could
					// be uninstantiated
					if (!m_alphaVars.GetAllBindings(m_variables, seg, instantiatedVars))
						return false;
				}
			}
			return true;
		}
Example #16
0
		public virtual bool IsUnapplicationVacuous(Segment seg, VariableValues instantiatedVars)
		{
			// check if the context's anti features have already been set
			if (!seg.FeatureValues.IsUnifiable(m_antiFeatureValues))
				return true;

			return false;
		}
Example #17
0
		protected override void ApplyFeatures(Segment seg, VariableValues instantiatedVars)
		{
			seg.SegmentDefinition = m_segDef;
			seg.FeatureValues.SetAll(false);
			seg.FeatureValues.Apply(m_featureValues, true);
		}
Example #18
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;
		}
Example #19
0
		protected override void ApplySegments(Segment seg)
		{
			seg.ClearInstantiatedSegments();
			UnapplySegments(seg);
		}
Example #20
0
		/// <summary>
		/// Gets all valid bindings between the specified variables and the feature values
		/// currently set on the specified segment. It adds the variable values to the varFeats of
		/// instantiated variables.
		/// </summary>
		/// <param name="variables">The variables.</param>
		/// <param name="seg">The segment.</param>
		/// <param name="instantiatedVars">The instantiated variables.</param>
		/// <returns><c>true</c> if a valid binding was found, otherwise <c>false</c></returns>
		public bool GetAllBindings(IDictionary<string, bool> variables, Segment seg, VariableValues instantiatedVars)
		{
			foreach (KeyValuePair<string, bool> varPolarity in variables)
			{
				bool match = false;
				foreach (FeatureValue value in GetVarFeatValue(varPolarity.Key, varPolarity.Value, instantiatedVars))
				{
					if (seg.FeatureValues.Get(value))
					{
						instantiatedVars.Add(varPolarity.Key, value);
						match = true;
					}
				}

				if (!match)
					return false;
			}

			return true;
		}
Example #21
0
		protected override void UnapplySegments(Segment seg)
		{
			seg.SegmentDefinition = m_segDef;
			seg.InstantiateSegment(m_segDef);
		}
Example #22
0
		public void Unapply(Segment seg, VariableValues instantiatedVars)
		{
			if (m_featSys.HasFeatures)
				UnapplyFeatures(seg, instantiatedVars);
			else
				UnapplySegments(seg);
		}
		/// <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);
			}
		}
Example #24
0
		protected abstract void UnapplyFeatures(Segment seg, VariableValues instantiatedVars);
Example #25
0
		/// <summary>
		/// Gets all valid bindings between the specified variables and the feature values
		/// currently set on the specified segment. It adds the variable values to the varFeats of
		/// instantiated variables.
		/// </summary>
		/// <param name="variables">The variables.</param>
		/// <param name="seg">The segment.</param>
		/// <param name="instantiatedVars">The instantiated variables.</param>
		/// <returns><c>true</c> if a valid binding was found, otherwise <c>false</c></returns>
		public bool GetAllBindings(IDictionary<string, bool> variables, Segment seg, VariableValues instantiatedVars)
		{
			foreach (KeyValuePair<string, bool> varPolarity in variables)
			{
				List<FeatureValue> valuesToAdd = new List<FeatureValue>();
				foreach (FeatureValue value in GetVarFeatValue(varPolarity.Key, varPolarity.Value, instantiatedVars))
				{
					if (seg.FeatureValues.Get(value))
						valuesToAdd.Add(value);
				}

				if (valuesToAdd.Count == 0)
					return false;

				foreach (FeatureValue value in valuesToAdd)
					instantiatedVars.Add(varPolarity.Key, value);
			}

			return true;
		}
		/// <summary>
		/// Gets all of the string representations that match the specified segment.
		/// </summary>
		/// <param name="seg">The segment.</param>
		/// <param name="mode">The mode.</param>
		/// <returns>The string representations.</returns>
		public IList<SegmentDefinition> GetMatchingSegmentDefinitions(Segment seg, ModeType mode)
		{
			List<SegmentDefinition> results = new List<SegmentDefinition>();

			if (Morpher.PhoneticFeatureSystem.HasFeatures)
			{
				foreach (SegmentDefinition segDef in m_segDefs.Values)
				{
					switch (mode)
					{
						case ModeType.SYNTHESIS:
							if (segDef.AnalysisFeatures.IsUnifiable(seg.FeatureValues))
								results.Add(segDef);
							break;

						case ModeType.ANALYSIS:
							if (seg.FeatureValues.IsUnifiable(segDef.SynthFeatures))
								results.Add(segDef);
							break;
					}
				}
			}
			else
			{
				results.AddRange(seg.InstantiatedSegments);
			}

			return results;
		}
		PhoneticShapeNode GetPhoneticShapeNode(string strRep, ModeType mode)
		{
			PhoneticShapeNode node = null;
			SegmentDefinition segDef = GetSegmentDefinition(strRep);
			if (segDef != null)
			{
				Segment seg = new Segment(segDef, mode == ModeType.SYNTHESIS ? segDef.SynthFeatures.Clone() : segDef.AnalysisFeatures.Clone());
				if (!Morpher.PhoneticFeatureSystem.HasFeatures)
					seg.InstantiateSegment(segDef);
				node = seg;
			}
			else
			{
				BoundaryDefinition bdryDef = GetBoundaryDefinition(strRep);
				if (bdryDef != null)
					node = new Boundary(bdryDef);
			}
			return node;
		}
Example #28
0
		protected virtual bool IsFeatureMatch(Segment seg, VariableValues instantiatedVars, ModeType mode)
		{
			// check unifiability
			if (!seg.FeatureValues.IsUnifiable(m_featureValues))
				return false;

			return true;
		}