/// <summary> /// Applies this subrule to the specified word synthesis. /// </summary> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <returns><c>true</c> if the subrule was successfully applied, otherwise <c>false</c></returns> public bool Apply(WordSynthesis input, out WordSynthesis output) { output = null; // check MPR features if ((m_requiredMPRFeatures != null && m_requiredMPRFeatures.Count > 0 && !m_requiredMPRFeatures.IsMatch(input.MPRFeatures)) || (m_excludedMPRFeatures != null && m_excludedMPRFeatures.Count > 0 && m_excludedMPRFeatures.IsMatch(input.MPRFeatures))) { return(false); } VariableValues instantiatedVars = new VariableValues(m_alphaVars); IList <Match> headMatches, nonHeadMatches; if (m_headLhsTemp.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.SYNTHESIS, instantiatedVars, out headMatches) && m_nonHeadLhsTemp.IsMatch(input.NonHead.Shape.First, Direction.RIGHT, ModeType.SYNTHESIS, instantiatedVars, out nonHeadMatches)) { output = input.Clone(); ApplyRHS(headMatches[0], nonHeadMatches[0], input, output); if (m_outputMPRFeatures != null) { output.MPRFeatures.AddOutput(m_outputMPRFeatures); } return(true); } return(false); }
/// <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); }
bool MatchAnalysisTarget(PhoneticShapeNode node, Direction dir, out Match match) { // check analysis target IList <Match> matches; VariableValues instantiatedVars = new VariableValues(m_rule.m_alphaVars); if (!m_analysisTarget.IsMatch(node, dir, ModeType.ANALYSIS, instantiatedVars, out matches)) { match = null; return(false); } match = matches[0]; // check vacuous unapplication // even if the subrule matches, we do not want to successfully unapply if no real changes are // going to be made to the phonetic shape if (!CheckVacuousUnapplication(match, dir)) { match = null; return(false); } // finally, check environment if (!MatchEnvNonempty(match.EntireMatch, dir, ModeType.ANALYSIS, match.VariableValues)) { match = null; return(false); } return(true); }
bool FindNextMatchLHS(PhoneticShapeNode node, Direction dir, out Match match) { for (; node != node.Owner.GetLast(dir); node = node.GetNext(dir)) { VariableValues instantiatedVars = new VariableValues(m_alphaVars); if (m_lhs.Count == 0) { // epenthesis rules always match the LHS match = new Match(instantiatedVars); match.Add(node); return(true); } else { IList <Match> matches; if (m_lhs.IsMatch(node, dir, ModeType.SYNTHESIS, instantiatedVars, out matches)) { match = matches[0]; return(true); } } } match = null; return(false); }
bool FindNextMatch(PhoneticShapeNode node, Direction dir, PhoneticPattern ptemp, ModeType mode, out Match match) { for (; node != node.Owner.GetLast(dir); node = node.GetNext(dir)) { if (mode == ModeType.ANALYSIS && node.Type == PhoneticShapeNode.NodeType.BOUNDARY) { continue; } IList <Match> matches; if (ptemp.IsMatch(node, dir, mode, out matches)) { match = matches[0]; return(true); } } match = null; return(false); }