/// <summary> /// TryParseConditionLine. /// </summary> /// <param name="line">Line.</param> /// <param name="phoneSet">PhoneSet.</param> /// <param name="polyphonyWord">PolyphonyWord.</param> /// <param name="errorSet">ErrorSet.</param> /// <returns>Whether the line is condition line.</returns> private bool TryParseConditionLine(string line, TtsPhoneSet phoneSet, PolyphonyRule polyphonyWord, ErrorSet errorSet) { bool isConditionLine = false; if (IsConditionLine(line)) { isConditionLine = true; if (polyphonyWord == null) { errorSet.Add(PolyRuleError.MissKeyValueLine, line); } errorSet.AddRange(ParseConditionLine(line, phoneSet, polyphonyWord)); } return isConditionLine; }
/// <summary> /// TryParseKeyLine. /// </summary> /// <param name="line">Line.</param> /// <param name="polyphonyWord">PolyphonyWord.</param> /// <param name="errorSet">ErrorSet.</param> /// <param name="domain">Domain.</param> /// <returns>Whether the line is key line.</returns> private bool TryParseKeyLine(string line, ref PolyphonyRule polyphonyWord, ErrorSet errorSet, string domain) { bool isKeyLine = false; if (IsKeyLine(line)) { isKeyLine = true; if (polyphonyWord != null) { if (polyphonyWord.PolyphonyProns.Count == 0) { errorSet.Add(PolyRuleError.NoConditionForWord, polyphonyWord.Word); } else { _polyphonyWords.Add(polyphonyWord); } } polyphonyWord = new PolyphonyRule(); polyphonyWord.Domain = domain; int errorCountBeforeParsing = errorSet.Errors.Count; string keyValue = ParseKeyValueLine(line, errorSet); if (errorSet.Errors.Count == errorCountBeforeParsing) { polyphonyWord.Word = keyValue; } } return isKeyLine; }
/// <summary> /// ParseConditionLine. /// </summary> /// <param name="line">Line.</param> /// <param name="phoneSet">PhoneSet.</param> /// <param name="polyphonyWord">PolyphonyWord.</param> /// <returns>ErrorSet.</returns> private ErrorSet ParseConditionLine(string line, TtsPhoneSet phoneSet, PolyphonyRule polyphonyWord) { ErrorSet errorSet = new ErrorSet(); Match match = Regex.Match(line, ConditionLineRegex); if (match.Groups.Count < 3) { errorSet.Add(PolyRuleError.InvalidConditionFormat, line); } else { PolyphonyPron polyphonyPron = new PolyphonyPron(); polyphonyPron.Pron = match.Groups[2].ToString().Trim(); // Allow empty pronunciation for polyphony rule. if (!string.IsNullOrEmpty(polyphonyPron.Pron) && phoneSet != null) { errorSet.AddRange(Pronunciation.Validate(polyphonyPron.Pron, phoneSet)); } string conditions = match.Groups[1].ToString().Trim(); bool hasMatched = false; foreach (Match conditionMatch in Regex.Matches(conditions, ConditionRegex)) { hasMatched = true; string expression = conditionMatch.Value; PolyphonyCondition condition = new PolyphonyCondition(); ParsePolyCondition(expression.Trim(), condition, errorSet); polyphonyPron.Conditions.Add(condition); } if (hasMatched) { if (errorSet.GetSeverityCount(ErrorSeverity.MustFix) == 0) { if (polyphonyWord == null) { errorSet.Add(PolyRuleError.MissKeyValueLine, line); } else { polyphonyWord.PolyphonyProns.Add(polyphonyPron); } } } else { errorSet.Add(PolyRuleError.InvalidConditionFormat, line); } } return errorSet; }