/// <summary> /// Validate char table. /// </summary> /// <param name="table">Char table.</param> /// <param name="shallow">Shallow validation.</param> /// <param name="wordsNotInLexicon">WordsNotInLexicon.</param> /// <returns>ErrorSet.</returns> public ErrorSet Validate(CharTable table, bool shallow, Collection<string> wordsNotInLexicon) { if (table == null) { throw new ArgumentNullException("table"); } ErrorSet errorSet = new ErrorSet(); int upperCaseNumber = 0; int lowerCaseNumber = 0; int digitNumber = 0; Collection<string> symbols = new Collection<string>(); foreach (CharElement charElement in table.CharList) { if (charElement.Type == CharElement.CharType.UpperCase) { upperCaseNumber++; } else if (charElement.Type == CharElement.CharType.LowerCase) { lowerCaseNumber++; } else if (charElement.Type == CharElement.CharType.Digit) { digitNumber++; } if (!symbols.Contains(charElement.Symbol)) { symbols.Add(charElement.Symbol); } else { errorSet.Add(new Error(CharTableError.DuplicateSymbol, charElement.Symbol)); } if (!shallow) { ValidateCharElement(charElement, errorSet, wordsNotInLexicon); } } if (upperCaseNumber != lowerCaseNumber) { errorSet.Add(new Error(CharTableError.MismatchUpperAndLower, upperCaseNumber.ToString(CultureInfo.InvariantCulture), lowerCaseNumber.ToString(CultureInfo.InvariantCulture))); } if (digitNumber != 10) { errorSet.Add(new Error(CharTableError.ErrorDigitCount)); } return errorSet; }
/// <summary> /// Check and geneate isolated symbol lexion. /// </summary> /// <param name="chartable">Char table.</param> /// <param name="posSymbol">Pos of symbol.</param> /// <param name="lexiconOutput">Lexicon output.</param> /// <param name="errors">Errors.</param> public void CheckContextualSymbolInLexicon(CharTable chartable, string posSymbol, string lexiconOutput, Collection<string> errors) { if (chartable == null) { throw new ArgumentNullException("chartable"); } if (errors == null) { throw new ArgumentNullException("errors"); } if (posSymbol == null) { throw new ArgumentNullException("posSymbol"); } Lexicon lexicon = new Lexicon(chartable.Language); Collection<string> polyWord = new Collection<string>(); foreach (CharElement charElement in chartable.CharList) { LexicalItem symbolItem = _lexicon.Lookup( charElement.Symbol.ToString(), true); LexicalItem lexiconItem = new LexicalItem(lexicon.Language); LexiconPronunciation lexiconPron = new LexiconPronunciation( lexicon.Language); string pron = string.Empty; string expansion = charElement.ContextualExpansion; if (string.IsNullOrEmpty(expansion)) { continue; } lexiconItem.Grapheme = charElement.Symbol.ToString(); Collection<string> errorStrings = new Collection<string>(); bool hasError = _lexicon.GetPronunciationForWords(expansion, errorStrings, polyWord, ref pron); if (!hasError && !string.IsNullOrEmpty(pron)) { bool addWord = true; if (symbolItem != null) { string[] prons = Pronunciation.SplitIntoPhones(pron); foreach (LexiconPronunciation existPron in symbolItem.Pronunciations) { bool same = true; string[] existProns = Pronunciation.SplitIntoPhones(existPron.Symbolic); if (existProns.Length == prons.Length) { for (int i = 0; i < prons.Length; i++) { if (existProns[i] != prons[i]) { same = false; break; } } if (same) { addWord = false; break; } } } } // add the word if the symbol or pronunicaiton is not in lexicon if (addWord) { lexiconPron.Symbolic = pron; LexiconItemProperty lip = new LexiconItemProperty(); lip.PartOfSpeech = new PosItem(posSymbol); lexiconPron.Properties.Add(lip); lexiconItem.Pronunciations.Add(lexiconPron); lexicon.Items.Add(lexiconItem.Grapheme, lexiconItem); if (symbolItem != null) { errors.Add(AttributeError.SymbolDiffPronFromLex + charElement.Symbol.ToString()); } } else { errors.Add(AttributeError.InfoSymbolInLex + charElement.Symbol.ToString()); } } else { errors.Add(AttributeError.SymbolPronGenError + charElement.Symbol.ToString()); } } Lexicon.WriteAllData(lexiconOutput, lexicon, Encoding.Unicode); }
/// <summary> /// Load Char table Data object. /// </summary> /// <param name="errorSet">ErrorSet.</param> /// <returns>Char table Data object.</returns> internal override object LoadDataObject(ErrorSet errorSet) { if (errorSet == null) { throw new ArgumentNullException("errorSet"); } CharTable charTable = new CharTable(); charTable.Load(Path); errorSet.Merge(charTable.ErrorSet); return charTable; }