/// <summary> /// Validate char element. /// </summary> /// <param name="element">Char element.</param> /// <param name="errorSet">Errors.</param> /// <param name="wordsNotInLexicon">WordsNotInLexicon.</param> public void ValidateCharElement(CharElement element, ErrorSet errorSet, Collection<string> wordsNotInLexicon) { if (errorSet == null) { throw new ArgumentNullException("errors"); } if (element == null) { throw new ArgumentNullException("element"); } if (string.IsNullOrEmpty(element.Symbol)) { errorSet.Add(new Error(CharTableError.EmptySymbol)); } else { EnsureInitialized(); if (_lexicon.Lookup(element.Symbol, true) == null) { errorSet.Add(new Error(CharTableError.SymbolNotInLexicon, element.Symbol)); } if (!element.IsAlphabet()) { // IsolatedExpansion should not empty for no-alphabet if (!string.IsNullOrEmpty(element.IsolatedExpansion)) { ValidateExpansion(element.IsolatedExpansion, "IsolatedSymbolReadout", errorSet, wordsNotInLexicon); } else { errorSet.Add(new Error(CharTableError.EmptyIsolatedSymbol, element.Symbol)); } // ContextualSymbolReadout is optional for no-alphabet if (!string.IsNullOrEmpty(element.ContextualExpansion)) { ValidateExpansion(element.ContextualExpansion, "ContextualSymbolReadout", errorSet, wordsNotInLexicon); } // No-alphabet should not have features. if (element.Feature != CharTableCompiler.CharFeature.None) { errorSet.Add(new Error(CharTableError.NonAlphabetShouldNoFeatures, element.Symbol)); } // No-alphabet should not have pronunciation. if (!string.IsNullOrEmpty(element.Pronunciation)) { errorSet.Add(new Error(CharTableError.NonAlphabetShouldNoPronunciation, element.Symbol)); } } else { if (string.IsNullOrEmpty(element.Pronunciation)) { errorSet.Add(new Error(CharTableError.AlphabetNoPron, element.Symbol)); } else { ErrorSet pronErrorSet = Pronunciation.Validate( element.Pronunciation, _phoneset); foreach (Error error in pronErrorSet.Errors) { Error alphabetError = new Error(CharTableError.AlphabetInvalidPron, error, element.Symbol, element.Pronunciation); // Keep the same error level with pronunciation error. alphabetError.Severity = error.Severity; errorSet.Add(alphabetError); } } if (element.Feature == CharTableCompiler.CharFeature.None) { errorSet.Add(new Error(CharTableError.AlphabetNoFeatures, element.Symbol)); } if (!string.IsNullOrEmpty(element.IsolatedExpansion) || !string.IsNullOrEmpty(element.ContextualExpansion)) { errorSet.Add(new Error(CharTableError.AlphabetShouldNoExpansion, element.Symbol)); } } } }
/// <summary> /// Load XML file. /// </summary> /// <param name="xmlDoc">Xml document.</param> /// <param name="nsmgr">Nsmgr.</param> /// <param name="contentController">Content controller.</param> protected override void Load(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, object contentController) { if (xmlDoc == null) { throw new ArgumentNullException("xmlDoc"); } if (nsmgr == null) { throw new ArgumentNullException("nsmgr"); } Language = Localor.StringToLanguage(xmlDoc.DocumentElement.GetAttribute("lang")); XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/tts:chartable/tts:char", nsmgr); _charList.Clear(); foreach (XmlNode node in nodeList) { CharElement charElement = new CharElement(); XmlNode attrNode = node.Attributes["symbol"]; string symbolString = attrNode.Value.Trim(); if (string.IsNullOrEmpty(symbolString)) { this.ErrorSet.Add(new Error(CharTableError.EmptySymbol, symbolString)); } else { if (!CharElement.IsSingleChar(symbolString)) { this.ErrorSet.Add(new Error(CharTableError.SymbolNotSingleChar, symbolString)); } charElement.Symbol = symbolString; } attrNode = node.Attributes["isolatedSymbolReadout"]; if (attrNode != null) { charElement.IsolatedExpansion = Regex.Replace(attrNode.Value.Trim(), @" +", " "); } attrNode = node.Attributes["contextualSymbolReadout"]; if (attrNode != null) { charElement.ContextualExpansion = attrNode.Value.Trim(); } attrNode = node.Attributes["pron"]; if (attrNode != null) { charElement.Pronunciation = attrNode.Value.Trim(); } attrNode = node.Attributes["feature"]; if (attrNode != null) { string[] features = attrNode.Value.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string feature in features) { charElement.Feature |= (CharTableCompiler.CharFeature)Enum.Parse( typeof(CharTableCompiler.CharFeature), feature, true); } } attrNode = node.Attributes["type"]; // Default is symbol charElement.Type = CharElement.CharType.Symbol; if (attrNode != null) { charElement.Type = (CharElement.CharType)Enum.Parse( typeof(CharElement.CharType), attrNode.Value.Trim(), true); } CharList.Add(charElement); } }