/// <summary> /// Initializes a new instance of the <see cref="Subrule"/> class. /// </summary> /// <param name="rhs">The RHS.</param> /// <param name="env">The environment.</param> /// <param name="rule">The phonological rule.</param> /// <exception cref="System.ArgumentException">Thrown when the size of the RHS is greater than the /// size of the specified rule's LHS and the LHS's size is greater than 1. A standard phonological /// rule does not currently support this type of widening.</exception> public Subrule(PhoneticPattern rhs, Environment env, StandardPhonologicalRule rule) { m_rhs = rhs; m_env = env; m_rule = rule; switch (Type) { case ChangeType.NARROW: case ChangeType.EPENTHESIS: // analysis target is a copy of the RHS, because there is no LHS m_analysisTarget = m_rhs.Clone(); break; case ChangeType.WIDEN: // before generating the analysis we must extend the length of the LHS // to match the length of the RHS PhoneticPattern lhs = m_rule.m_lhs.Clone(); while (lhs.Count != m_rhs.Count) lhs.Add(lhs.First.Clone()); m_analysisTarget = m_rhs.Combine(lhs); break; case ChangeType.FEATURE: m_analysisTarget = m_rhs.Combine(m_rule.m_lhs); break; case ChangeType.UNKNOWN: throw new ArgumentException(HCStrings.kstidInvalidSubruleType, "rhs"); } }
/// <summary> /// Initializes a new instance of the <see cref="Subrule"/> class. /// </summary> /// <param name="rhs">The RHS.</param> /// <param name="env">The environment.</param> /// <param name="rule">The phonological rule.</param> /// <exception cref="System.ArgumentException">Thrown when the size of the RHS is greater than the /// size of the specified rule's LHS and the LHS's size is greater than 1. A standard phonological /// rule does not currently support this type of widening.</exception> public Subrule(PhoneticPattern rhs, Environment env, StandardPhonologicalRule rule) { m_rhs = rhs; m_env = env; m_rule = rule; switch (Type) { case ChangeType.NARROW: case ChangeType.EPENTHESIS: // analysis target is a copy of the RHS, because there is no LHS m_analysisTarget = m_rhs.Clone(); break; case ChangeType.WIDEN: // before generating the analysis we must extend the length of the LHS // to match the length of the RHS PhoneticPattern lhs = m_rule.m_lhs.Clone(); while (lhs.Count != m_rhs.Count) { lhs.Add(lhs.First.Clone()); } m_analysisTarget = m_rhs.Combine(lhs); break; case ChangeType.FEATURE: m_analysisTarget = m_rhs.Combine(m_rule.m_lhs); break; case ChangeType.UNKNOWN: throw new ArgumentException(HCStrings.kstidInvalidSubruleType, "rhs"); } }
void LoadPSubrule(XmlElement psubruleNode, StandardPhonologicalRule prule, Dictionary<string, string> varFeatIds) { XmlElement structElem = psubruleNode.SelectSingleNode("PhonologicalSubruleStructure[@isActive='yes']") as XmlElement; PhoneticPattern rhs = new PhoneticPattern(true); LoadPSeq(rhs, structElem.SelectSingleNode("PhoneticOutput/PhoneticSequence") as XmlElement, prule.AlphaVariables, varFeatIds, null); Environment env = LoadEnv(structElem.SelectSingleNode("Environment"), prule.AlphaVariables, varFeatIds); StandardPhonologicalRule.Subrule sr = null; try { sr = new StandardPhonologicalRule.Subrule(rhs, env, prule); } catch (ArgumentException ae) { LoadException le = new LoadException(LoadException.LoadErrorType.INVALID_SUBRULE_TYPE, this, HCStrings.kstidInvalidSubruleType, ae); le.Data["rule"] = prule.ID; throw le; } sr.RequiredPOSs = LoadPOSs(psubruleNode.GetAttribute("requiredPartsOfSpeech")); sr.RequiredMPRFeatures = LoadMPRFeatures(psubruleNode.GetAttribute("requiredMPRFeatures")); sr.ExcludedMPRFeatures = LoadMPRFeatures(psubruleNode.GetAttribute("excludedMPRFeatures")); prule.AddSubrule(sr); }
void LoadPRule(XmlElement pruleNode) { string id = pruleNode.GetAttribute("id"); string name = pruleNode.SelectSingleNode("Name").InnerText; StandardPhonologicalRule prule = new StandardPhonologicalRule(id, name, m_curMorpher); prule.MultApplication = GetMultAppOrder(pruleNode.GetAttribute("multipleApplicationOrder")); Dictionary<string, string> varFeatIds; prule.AlphaVariables = LoadAlphaVars(pruleNode.SelectSingleNode("VariableFeatures") as XmlElement, out varFeatIds); XmlElement pseqElem = pruleNode.SelectSingleNode("PhoneticInputSequence/PhoneticSequence") as XmlElement; prule.LHS = new PhoneticPattern(true); LoadPSeq(prule.LHS, pseqElem, prule.AlphaVariables, varFeatIds, null); XmlNodeList subruleList = pruleNode.SelectNodes("PhonologicalSubrules/PhonologicalSubrule"); foreach (XmlNode subruleNode in subruleList) LoadPSubrule(subruleNode as XmlElement, prule, varFeatIds); m_curMorpher.AddPhonologicalRule(prule); string[] stratumIds = pruleNode.GetAttribute("ruleStrata").Split(' '); foreach (string stratumId in stratumIds) GetStratum(stratumId).AddPhonologicalRule(prule); }