/// <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; }
/// <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; }
/// <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; }
/// <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; }
protected override bool IsSegmentMatch(Segment seg) { return seg.IsSegmentInstantiated(m_segDef); }
protected abstract bool IsSegmentMatch(Segment seg);
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); }
protected override Segment ApplyInsertionSegments() { Segment seg = new Segment(m_segDef, new FeatureBundle(false, m_featSys)); seg.InstantiateSegment(m_segDef); return seg; }
protected abstract void UnapplySegments(Segment seg);
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; }
protected override void UnapplyFeatures(Segment seg, VariableValues instantiatedVars) { seg.FeatureValues.Apply(m_antiFeatureValues, true); }
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); }
protected override void UnapplySegments(Segment seg) { foreach (SegmentDefinition segDef in m_natClass.SegmentDefinitions) seg.InstantiateSegment(segDef); }
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; }
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; }
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; }
protected override void ApplyFeatures(Segment seg, VariableValues instantiatedVars) { seg.SegmentDefinition = m_segDef; seg.FeatureValues.SetAll(false); seg.FeatureValues.Apply(m_featureValues, true); }
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; }
protected override void ApplySegments(Segment seg) { seg.ClearInstantiatedSegments(); UnapplySegments(seg); }
/// <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; }
protected override void UnapplySegments(Segment seg) { seg.SegmentDefinition = m_segDef; seg.InstantiateSegment(m_segDef); }
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); } }
protected abstract void UnapplyFeatures(Segment seg, VariableValues instantiatedVars);
/// <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; }
protected virtual bool IsFeatureMatch(Segment seg, VariableValues instantiatedVars, ModeType mode) { // check unifiability if (!seg.FeatureValues.IsUnifiable(m_featureValues)) return false; return true; }