当前位置: 首页>>代码示例>>C#>>正文


C# ErrorSet.Merge方法代码示例

本文整理汇总了C#中ErrorSet.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorSet.Merge方法的具体用法?C# ErrorSet.Merge怎么用?C# ErrorSet.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ErrorSet的用法示例。


在下文中一共展示了ErrorSet.Merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateSilenceInWord

        /// <summary>
        /// Checks whether the data contains -sil- in within a word.
        /// </summary>
        /// <param name="script">Script file instance.</param>
        /// <param name="item">Script item.</param>
        /// <param name="fileMap">File list map.</param>
        /// <param name="segmentDir">Segment file directory.</param>
        /// <param name="errorSet">Data error set found.</param>
        public static void ValidateSilenceInWord(XmlScriptFile script, ScriptItem item,
            FileListMap fileMap, string segmentDir, ErrorSet errorSet)
        {
            string segmentFilePath = Path.Combine(segmentDir, fileMap.Map[item.Id] + ".txt");

            StringBuilder errorMessage = new StringBuilder();
            SegmentFile segmentFile = ValidateAlignmentFile(segmentFilePath, errorMessage);
            if (errorMessage.Length != 0)
            {
                errorSet.Add(ScriptError.OtherErrors, item.Id, errorMessage.ToString());
            }
            else
            {
                int indexOfSegment = 0;
                foreach (ScriptWord word in item.AllPronouncedNormalWords)
                {
                    ErrorSet errors = new ErrorSet();
                    Collection<string> phones = word.GetNormalPhoneNames(script.PhoneSet, errors);
                    if (errors.Count > 0)
                    {
                        errorSet.Merge(errors);
                        break;
                    }

                    if (segmentFile.WaveSegments[indexOfSegment].IsSilenceFeature)
                    {
                        ++indexOfSegment;
                    }

                    for (int i = 0; i < phones.Count; ++i, ++indexOfSegment)
                    {
                        if (segmentFile.WaveSegments[indexOfSegment].IsSilenceFeature)
                        {
                            errorSet.Add(ScriptError.OtherErrors,
                                item.Id,
                                Helper.NeutralFormat("Alignment file {0} is invalid, for silence in word {1}.", segmentFilePath, word.Grapheme));
                            ++indexOfSegment;
                        }

                        if (segmentFile.WaveSegments[indexOfSegment].Label != phones[i])
                        {
                            string message = string.Format(CultureInfo.InvariantCulture,
                                "phone [{0}/{1}] at {2} does not match between script and segment.",
                                WaveSegment.FormatLabel(phones[i]),
                                segmentFile.WaveSegments[indexOfSegment].Label,
                                i);
                            errorSet.Add(ScriptError.OtherErrors, item.Id, message);
                        }
                    }
                }
            }
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:60,代码来源:XmlVoiceFont.cs

示例2: Add

        /// <summary>
        /// Add one item to script file.
        /// This method will check whether the item is balid before adding.
        /// </summary>
        /// <param name="item">The item to be added.</param>
        /// <param name="errors">The errors if failed to add.</param>
        /// <param name="validate">Whether validate schema and content.</param>
        /// <param name="sort">Whether insert the script item in the sort position.</param>
        /// <returns>True if successfully added.</returns>
        public bool Add(ScriptItem item, ErrorSet errors, bool validate, bool sort)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            // check schema, should throw exception if invalid
            CheckSchema(item);

            bool added = true;
            errors.Clear();

            // content checking, should add to errors if invalid
            if (_itemDic.ContainsKey(item.Id))
            {
                errors.Add(ScriptError.DuplicateItemId, item.Id);
            }

            if (validate)
            {
                ErrorSet contentErrors = new ErrorSet();
                XmlScriptValidateSetting validateSetting = new XmlScriptValidateSetting(PhoneSet, PosSet);
                ScriptItem.IsValidItem(item, contentErrors, validateSetting);
                errors.Merge(contentErrors);
            }

            if (errors.Count > 0)
            {
                added = false;
            }

            if (added)
            {
                _itemDic.Add(item.Id, item);
                if (sort)
                {
                    bool inserted = false;
                    for (int i = 0; i < _items.Count; i++)
                    {
                        if (string.Compare(item.Id, _items[i].Id, StringComparison.OrdinalIgnoreCase) < 0)
                        {
                            _items.Insert(i, item);
                            inserted = true;
                            break;
                        }
                    }

                    if (!inserted)
                    {
                        _items.Add(item);
                    }
                }
                else
                {
                    _items.Add(item);
                }
            }

            return added;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:75,代码来源:XmlScriptFile.cs

示例3: FindUnmatchedSentences

        /// <summary>
        /// Find unmatching sentences between filemap file and script file
        /// <param />
        /// This function should be merged with that in forcedalignment into common library.
        /// </summary>
        /// <param name="scriptFilePath">The location of script file.</param>
        /// <param name="language">Language of the script file.</param>
        /// <param name="mapFilePath">The location of file fist map path.</param>
        /// <returns>Unmatching sentence ids.</returns>
        public static ErrorSet FindUnmatchedSentences(string scriptFilePath,
            Language language, string mapFilePath)
        {
            ErrorSet errorSet = new ErrorSet();
            TtsPhoneSet phoneSet = Localor.GetPhoneSet(language);
            XmlScriptValidateSetting validateSetting = new XmlScriptValidateSetting(phoneSet, null);
            XmlScriptFile script = XmlScriptFile.LoadWithValidation(scriptFilePath, validateSetting);
            script.Remove(ScriptHelper.GetNeedDeleteItemIds(script.ErrorSet));

            Dictionary<string, string> map = Microsoft.Tts.Offline.FileListMap.ReadAllData(mapFilePath);
            errorSet.Merge(script.ErrorSet);
            foreach (string sid in script.ItemDic.Keys)
            {
                if (!map.ContainsKey(sid))
                {
                    string message = Helper.NeutralFormat(
                        "Script item {0} in script file but not in file list map file", sid);
                    errorSet.Add(ScriptError.OtherErrors, sid, message);
                }
            }

            foreach (string sid in map.Keys)
            {
                if (!script.ItemDic.ContainsKey(sid))
                {
                    string message = Helper.NeutralFormat(
                        "Script item {0} in file list map file but not in script file", sid);
                    errorSet.Add(ScriptError.OtherErrors, sid, message);
                }
            }

            return errorSet;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:42,代码来源:FontCompilerConfig.cs

示例4: BuildMonoMlf

        /// <summary>
        /// Build mlf from script item.
        /// </summary>
        /// <param name="item">Script item.</param>
        /// <param name="sw">Text writer.</param>
        /// <param name="writeToFile">Whether writing to file.</param>
        /// <param name="phoneme">Phoneme.</param>
        /// <param name="sliceData">Slice data.</param>
        /// <returns>Errors.</returns>
        private static ErrorSet BuildMonoMlf(ScriptItem item, StreamWriter sw, 
            bool writeToFile, Phoneme phoneme, SliceData sliceData)
        {
            Debug.Assert(item != null);
            Debug.Assert(phoneme != null);

            if (writeToFile && sw == null)
            {
                throw new ArgumentNullException("sw");
            }

            Collection<ScriptWord> allPronouncedNormalWords = item.AllPronouncedNormalWords;
            ErrorSet errors = new ErrorSet();
            if (allPronouncedNormalWords.Count == 0)
            {
                errors.Add(ScriptError.OtherErrors, item.Id, Helper.NeutralFormat("No pronounced normal word."));
            }
            else
            {
                for (int i = 0; i < allPronouncedNormalWords.Count; i++)
                {
                    ScriptWord word = allPronouncedNormalWords[i];
                    Debug.Assert(word != null);
                    if (string.IsNullOrEmpty(word.Pronunciation))
                    {
                        errors.Add(ScriptError.OtherErrors, item.Id, Helper.NeutralFormat("No pronunciation normal word '{1}' in script item {0}.", item.Id, word.Grapheme));
                    }
                }

                if (errors.Count == 0)
                {
                    if (writeToFile)
                    {
                        sw.WriteLine("\"*/{0}.lab\"", item.Id);
                        sw.WriteLine(Phoneme.SilencePhone);
                    }

                    for (int i = 0; i < allPronouncedNormalWords.Count; i++)
                    {
                        ScriptWord word = allPronouncedNormalWords[i];
                        Collection<TtsUnit> units = word.GetUnits(phoneme, sliceData);
                        if (phoneme.Tts2srMapType == Phoneme.TtsToSrMappingType.PhoneBased)
                        {
                            foreach (TtsUnit unit in units)
                            {
                                errors.Merge(BuildMonoMlf(unit, item, sw, writeToFile, phoneme));
                            }
                        }
                        else if (phoneme.Tts2srMapType == Phoneme.TtsToSrMappingType.SyllableBased)
                        {
                            foreach (ScriptSyllable syllable in word.UnitSyllables)
                            {
                                errors.Merge(BuildMonoMlf(syllable, item, sw, writeToFile, phoneme));
                            }
                        }

                        if (writeToFile && i + 1 < allPronouncedNormalWords.Count)
                        {
                            sw.WriteLine(Phoneme.ShortPausePhone);
                        }
                    }

                    if (writeToFile)
                    {
                        sw.WriteLine(Phoneme.SilencePhone);
                        sw.WriteLine(".");  // end of sentence
                    }
                }
            }

            return errors;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:81,代码来源:ScriptHelper.cs

示例5: LoadDataObject

        /// <summary>
        /// Load Lexicon Attribute Schema Data object.
        /// </summary>
        /// <param name="errorSet">ErrorSet.</param>
        /// <returns>Lexicon Attribute Schema Data object.</returns>
        internal override object LoadDataObject(ErrorSet errorSet)
        {
            if (errorSet == null)
            {
                throw new ArgumentNullException("errorSet");
            }

            LexicalAttributeSchema schema = new LexicalAttributeSchema();
            schema.Load(this.Path);
            schema.Validate();
            errorSet.Merge(schema.ErrorSet);
            if (schema.ErrorSet.Contains(ErrorSeverity.MustFix))
            {
                schema = null;
            }

            return schema;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:23,代码来源:DataConfiguration.cs

示例6: CompileForeignLtsCollection

        /// <summary>
        /// Compile the foreign LTS collection.
        /// </summary>
        /// <param name="configuration">Foreign LTS configuration.</param>
        /// <param name="outputStream">Output steam.</param>
        /// <returns>Error set.</returns>
        private ErrorSet CompileForeignLtsCollection(string configuration, Stream outputStream)
        {
            ErrorSet errorSet = new ErrorSet();

            // The configuration is written in
            // "originLanguageA : phonesetA ; RuleA ; originLanguageB: phonesetB ; RuleB"
            string[] phonesetLtsList = configuration.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            ushort count = Convert.ToUInt16(phonesetLtsList.Length / 2);
            Offline.Language[] languages = new Offline.Language[count];
            TtsPhoneSet[] phoneSets = new TtsPhoneSet[count];
            string[] ltsPaths = new string[count];

            // Load the phone sets
            for (ushort i = 0; i < count; i++)
            {
                languages[i] = Offline.Language.Neutral;
                string phoneSetPath = phonesetLtsList[i * 2].Trim();
                int languageSeparatorIndex = phoneSetPath.IndexOf(":");
                if (languageSeparatorIndex != -1)
                {
                    string language = phoneSetPath.Substring(0, languageSeparatorIndex).Trim();
                    languages[i] = Localor.StringToLanguage(language);
                    phoneSetPath = phoneSetPath.Substring(languageSeparatorIndex + 1, phoneSetPath.Length - languageSeparatorIndex - 1).Trim();
                }

                if (!Path.IsPathRooted(phoneSetPath))
                {
                    phoneSetPath = Path.Combine(_dataHandlerList.DataRoot, phoneSetPath);
                }

                phoneSets[i] = new TtsPhoneSet();
                phoneSets[i].Load(phoneSetPath);
                phoneSets[i].Validate();
                if (languages[i] == Offline.Language.Neutral)
                {
                    languages[i] = phoneSets[i].Language;
                }

                errorSet.Merge(phoneSets[i].ErrorSet);
                if (phoneSets[i].ErrorSet.Contains(ErrorSeverity.MustFix))
                {
                    phoneSets[i] = null;
                }
                else
                {
                    ltsPaths[i] = phonesetLtsList[(i * 2) + 1].Trim();
                    if (!Path.IsPathRooted(ltsPaths[i]))
                    {
                        ltsPaths[i] = Path.Combine(_dataHandlerList.DataRoot, ltsPaths[i]);
                    }
                }
            }

            if (!errorSet.Contains(ErrorSeverity.MustFix))
            {
                BinaryWriter bw = new BinaryWriter(outputStream);
                {
                    bw.Write((ushort)count);
                    for (ushort i = 0; i < count; i++)
                    {
                        bw.Write((ushort)languages[i]);
                        bw.Write((ushort)phoneSets[i].Language);
                    }

                    // Write phone set offset
                    long phoneSetOffset = bw.BaseStream.Position;
                    for (byte i = 0; i < count; i++)
                    {
                        bw.Write((uint)0);
                    }

                    // Write LTS offset
                    long ltsOffset = bw.BaseStream.Position;
                    for (byte i = 0; i < count; i++)
                    {
                        bw.Write((uint)0);
                    }

                    // Write phone set
                    for (byte i = 0; i < count; i++)
                    {
                        long offset = bw.BaseStream.Position;
                        bw.BaseStream.Seek(phoneSetOffset, SeekOrigin.Begin);
                        if (offset > uint.MaxValue)
                        {
                            throw new InvalidDataException(Helper.NeutralFormat(
                                "Foreign LTS collection size exceeds the maximal size {0}", uint.MaxValue));
                        }

                        bw.Write((uint)offset);
                        phoneSetOffset += sizeof(uint);
                        bw.BaseStream.Seek(offset, SeekOrigin.Begin);
                        errorSet.Merge(PhoneSetCompiler.Compile(phoneSets[i], bw.BaseStream));
                    }
//.........这里部分代码省略.........
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:101,代码来源:LangDataCompiler.cs

示例7: GetPhones

        /// <summary>
        /// Get the Phones of this item.
        /// </summary>
        /// <param name="phoneSet">Phone set.</param>
        /// <param name="errors">Errors if having invalid phone.</param>
        /// <returns>The phones.</returns>
        public Collection<Phone> GetPhones(TtsPhoneSet phoneSet, ErrorSet errors)
        {
            if (phoneSet == null)
            {
                throw new ArgumentNullException("phoneSet");
            }

            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            errors.Clear();
            Collection<Phone> phones = new Collection<Phone>();
            foreach (ScriptSentence sentence in Sentences)
            {
                ErrorSet sentenceErrors = new ErrorSet();
                foreach (Phone phone in sentence.GetPhones(phoneSet, sentenceErrors))
                {
                    phones.Add(phone);
                }

                errors.Merge(sentenceErrors);
            }

            return phones;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:33,代码来源:ScriptItem.cs

示例8: LoadScriptsWithoutValidation

        /// <summary>
        /// Load all the script items from a folder
        /// Note: Here don't validate the content, But duplicate item ID is not allowed.
        /// </summary>
        /// <param name="sourceDir">Script dir.</param>
        /// <param name="errors">Errors happened.</param>
        /// <returns>Loaded items collection.</returns>
        public static Collection<ScriptItem> LoadScriptsWithoutValidation(string sourceDir, ErrorSet errors)
        {
            if (string.IsNullOrEmpty(sourceDir))
            {
                throw new ArgumentNullException("sourceDir");
            }

            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            Collection<ScriptItem> items = new Collection<ScriptItem>();
            Dictionary<string, string> ids = new Dictionary<string, string>();
            string pattern = @"*" + XmlScriptFile.Extension;
            Language language = Language.Neutral;
            foreach (string file in Directory.GetFiles(sourceDir, pattern, SearchOption.AllDirectories))
            {
                XmlScriptFile script = new XmlScriptFile();
                XmlScriptFile.ContentControler controler = new XmlScriptFile.ContentControler();
                controler.LoadComments = true;
                script.Load(file, controler);
                if (language == Language.Neutral)
                {
                    language = script.Language;
                }
                else if (language != script.Language)
                {
                    throw new InvalidDataException(Helper.NeutralFormat(
                        "The language name in File [{0}] is different from other files.", file));
                }

                errors.Merge(script.ErrorSet);
                foreach (ScriptItem item in script.Items)
                {
                    if (ids.ContainsKey(item.Id))
                    {
                        errors.Add(ScriptError.DuplicateItemId, item.Id);
                    }
                    else
                    {
                        item.ScriptFile = null;
                        items.Add(item);
                    }
                }
            }

            return items;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:56,代码来源:ScriptHelper.cs

示例9: ConvertXmlScriptToTwoLineScript

        /// <summary>
        /// Convert XML script to two-line script.
        /// </summary>
        /// <param name="xmlScript">Input XML script.</param>
        /// <param name="targetFile">Output script.</param>
        /// <param name="phoneSet">
        /// Phone set used to convert pronunciation
        /// It can be null when you can directly get the word's pronunciation in the word's attribute.
        /// </param>
        /// <returns>Errors happened.</returns>
        public static ErrorSet ConvertXmlScriptToTwoLineScript(string xmlScript, 
            string targetFile, TtsPhoneSet phoneSet)
        {
            if (string.IsNullOrEmpty(xmlScript))
            {
                throw new ArgumentNullException("xmlScript");
            }

            if (string.IsNullOrEmpty(targetFile))
            {
                throw new ArgumentNullException("targetFile");
            }

            if (!Directory.Exists(Path.GetDirectoryName(targetFile)))
            {
                throw new DirectoryNotFoundException(targetFile);
            }

            ErrorSet errorSet = new ErrorSet();
            XmlScriptFile script = new XmlScriptFile();
            script.Load(xmlScript);
            ScriptFile oldScript = new ScriptFile(script.Language);
            foreach (ScriptItem item in script.Items)
            {
                ErrorSet itemErrors = new ErrorSet();
                ScriptItem oldItem = ConvertScriptItemToTwoLineFormat(item, phoneSet, itemErrors);
                if (itemErrors.Count != 0)
                {
                    errorSet.Merge(itemErrors);
                }
                else
                {
                    oldScript.Items.Add(oldItem.Id, oldItem);
                }
            }

            oldScript.Save(targetFile, true, true);

            return errorSet;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:50,代码来源:ScriptHelper.cs

示例10: ConvertTwoLineScriptToXmlScript

        /// <summary>
        /// Convert two-line script to XML script.
        /// </summary>
        /// <param name="twoLineScript">Input two-line script.</param>
        /// <param name="targetFile">Output script.</param>
        /// <param name="language">Language.</param>
        /// <param name="inScriptWithoutPron">Whether input script without pronunciation.</param>
        /// <returns>Errors.</returns>
        public static ErrorSet ConvertTwoLineScriptToXmlScript(string twoLineScript,
            string targetFile, Language language, bool inScriptWithoutPron)
        {
            if (string.IsNullOrEmpty(twoLineScript))
            {
                throw new ArgumentNullException("twoLineScript");
            }

            if (string.IsNullOrEmpty(targetFile))
            {
                throw new ArgumentNullException("targetFile");
            }

            if (!Directory.Exists(Path.GetDirectoryName(targetFile)))
            {
                throw new DirectoryNotFoundException(targetFile);
            }

            ErrorSet errorSet = new ErrorSet();
            Collection<ScriptItem> items = new Collection<ScriptItem>();
            DataErrorSet errors = ScriptFile.ReadAllData(twoLineScript, items, !inScriptWithoutPron, true);
            if (errors.Errors.Count > 0)
            {
                foreach (DataError error in errors.Errors)
                {
                    if (!string.IsNullOrEmpty(error.SentenceId))
                    {
                        errorSet.Add(ScriptError.OtherErrors, error.SentenceId, error.ToString());
                    }
                }
            }

            XmlScriptFile script = new XmlScriptFile(language);
            foreach (ScriptItem item in items)
            {
                ErrorSet itemErrors = new ErrorSet();
                ScriptItem newItem = ConvertScriptItemToXmlFormat(item, inScriptWithoutPron, itemErrors);
                if (itemErrors.Count != 0)
                {
                    errorSet.Merge(itemErrors);
                }
                else
                {
                    script.Items.Add(newItem);
                }
            }

            script.Save(targetFile, Encoding.Unicode);

            return errorSet;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:59,代码来源:ScriptHelper.cs

示例11: MergeScripts

        /// <summary>
        /// Merge scripts in a folder into a script file.
        /// Error items are removed from the output file.
        /// </summary>
        /// <param name="scriptDir">Dir conataining script file.</param>
        /// <param name="errorSet">Error set.</param>
        /// <param name="resetId">True means resetting id.</param>
        /// <param name="validateSetting">Validation setting.</param>
        /// <param name="contentController">Contenct controller.</param>
        /// <returns>Xml script file.</returns>
        public static XmlScriptFile MergeScripts(string scriptDir, ErrorSet errorSet,
            bool resetId, XmlScriptValidateSetting validateSetting, object contentController)
        {
            if (string.IsNullOrEmpty(scriptDir))
            {
                throw new ArgumentNullException("scriptDir");
            }

            if (errorSet == null)
            {
                throw new ArgumentNullException("errorSet");
            }

            if (validateSetting == null)
            {
                throw new ArgumentNullException("validateSetting");
            }

            if (!Directory.Exists(scriptDir))
            {
                throw new DirectoryNotFoundException(scriptDir);
            }

            validateSetting.VerifySetting();
            
            XmlScriptValidationScope scope = validateSetting.ValidationScope;

            string[] subFiles = Directory.GetFiles(
                scriptDir, "*" + XmlScriptFile.Extension, SearchOption.AllDirectories);
            XmlScriptFile mergedScript = new XmlScriptFile();

            long id = 0;
            foreach (string file in subFiles)
            {
                XmlScriptFile script = new XmlScriptFile();
                script.Load(file, contentController);
                if (mergedScript.Language == Language.Neutral)
                {
                    mergedScript.Language = script.Language;
                }
                else if (mergedScript.Language != script.Language)
                {
                    throw new InvalidDataException(Helper.NeutralFormat("Inconsistent langage in {0}", file));
                }

                if (scope != XmlScriptValidationScope.None)
                {
                    script.PosSet = validateSetting.PosSet;
                    script.PhoneSet = validateSetting.PhoneSet;

                    script.Validate(validateSetting);
                    script.Remove(GetNeedDeleteItemIds(script.ErrorSet));
                }

                errorSet.Merge(script.ErrorSet);
                foreach (ScriptItem item in script.Items)
                {
                    item.Id = resetId ? Helper.NeutralFormat("{0:D10}", ++id) : item.Id;

                    ErrorSet addErrors = new ErrorSet();
                    if (!mergedScript.Add(item, addErrors, false))
                    {
                        // Added failed
                        errorSet.Merge(addErrors);
                    }
                }
            }

            return mergedScript;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:80,代码来源:ScriptHelper.cs

示例12: ConvertIntoArray

        public static ArrayList ConvertIntoArray(string grammaticalCase, ErrorSet errorSet)
        {
            if (errorSet == null)
            {
                throw new ArgumentNullException("errorSet");
            }

            ArrayList arrayList = new ArrayList();

            int id = 0;
            errorSet.Merge(StringToId(grammaticalCase, out id));
            foreach (int i in Enum.GetValues(typeof(GrammaticalCase)))
            {
                if ((id & i) != 0)
                {
                    arrayList.Add(Enum.GetName(typeof(GrammaticalCase), i).ToLower(CultureInfo.InvariantCulture));
                }
            }

            return arrayList;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:21,代码来源:LexicalItem.cs

示例13: CompileLexicon

        private ErrorSet CompileLexicon(Stream outputStream)
        {
            if (outputStream == null)
            {
                throw new ArgumentNullException("outputStream");
            }

            ErrorSet errorSet = new ErrorSet();

            ErrorSet subErrorSet = new ErrorSet();
            LexicalAttributeSchema schema = (LexicalAttributeSchema)GetObject(
                RawDataName.LexicalAttributeSchema, subErrorSet);
            MergeDependencyError(errorSet, subErrorSet, _schemaFullName);

            subErrorSet.Clear();
            TtsPhoneSet phoneSet = (TtsPhoneSet)GetObject(RawDataName.PhoneSet, subErrorSet);
            MergeDependencyError(errorSet, subErrorSet, RawDataName.PhoneSet);

            if (!errorSet.Contains(ErrorSeverity.MustFix))
            {
                Microsoft.Tts.Offline.Core.Lexicon lexicon = (Microsoft.Tts.Offline.Core.Lexicon)GetObject(RawDataName.Lexicon, errorSet);
                errorSet.Merge(lexicon.ErrorSet);

                // Change to case insensitive lexicon
                MemoryStream lexiconStream = new MemoryStream();
                using (XmlWriter xmlWriter = XmlWriter.Create(lexiconStream))
                {
                    Microsoft.Tts.Offline.Core.Lexicon.ContentControler lexiconControler = 
                        new Microsoft.Tts.Offline.Core.Lexicon.ContentControler();
                    lexiconControler.IsCaseSensitive = true;
                    lexicon.Save(xmlWriter, lexiconControler);
                }

                lexiconStream.Seek(0, SeekOrigin.Begin);
                Microsoft.Tts.Offline.Core.Lexicon caseInsensitiveLexicon = new Microsoft.Tts.Offline.Core.Lexicon();
                using (StreamReader sr = new StreamReader(lexiconStream))
                {
                    caseInsensitiveLexicon.Load(sr);
                }

                if (caseInsensitiveLexicon != null && !errorSet.Contains(ErrorSeverity.MustFix))
                {
                    caseInsensitiveLexicon.LexicalAttributeSchema = schema;

                    caseInsensitiveLexicon.PhoneSet = phoneSet;
                    caseInsensitiveLexicon.Validate();

                    // Set severity of errors only in case-insensitive lexicon to NoError for they're not treated as real error
                    caseInsensitiveLexicon.ErrorSet.SetSeverity(ErrorSeverity.NoError);

                    string vendorLexiconPath = Helper.GetTempFileName();

                    caseInsensitiveLexicon.SaveToVendorLexicon(vendorLexiconPath);

                    string toolFileName = ToolName.BldVendor2;
                    string binaryLexiconPath = Helper.GetTempFileName();

                    string compilingArguments = Helper.NeutralFormat("-v {0} V2 \"{1}\" \"{2}\" \"{3}\" TTS",
                        (int)_language, _dataHandlerList.Datas[RawDataName.LexicalAttributeSchema].Path,
                        vendorLexiconPath, binaryLexiconPath);
                    string toolPath = Path.Combine(ToolDir, toolFileName);

                    CheckToolExists(toolPath, errorSet);
                    if (!errorSet.Contains(ErrorSeverity.MustFix))
                    {
                        HandleCommandLine(ModuleDataName.Lexicon, toolPath, compilingArguments,
                            binaryLexiconPath, outputStream, errorSet);
                    }

                    File.Delete(vendorLexiconPath);

                    errorSet.Merge(caseInsensitiveLexicon.ErrorSet);
                }
                else if (lexicon == null)
                {
                    errorSet.Add(DataCompilerError.RawDataError, "Lexicon");
                }
                else
                {
                    errorSet.Merge(caseInsensitiveLexicon.ErrorSet);
                }
            }

            return errorSet;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:85,代码来源:LangDataCompiler.cs

示例14: GetPhones

        /// <summary>
        /// Get the Phones of this sentence.
        /// </summary>
        /// <param name="phoneSet">Phone set.</param>
        /// <param name="errors">Errors if having invalid phone.</param>
        /// <returns>The phones.</returns>
        public Collection<Phone> GetPhones(TtsPhoneSet phoneSet, ErrorSet errors)
        {
            if (phoneSet == null)
            {
                throw new ArgumentNullException("phoneSet");
            }

            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            errors.Clear();
            Collection<Phone> phones = new Collection<Phone>();
            foreach (ScriptWord word in Words)
            {
                ErrorSet wordErrors = new ErrorSet();
                foreach (Phone phone in word.GetPhones(phoneSet, wordErrors))
                {
                    phones.Add(phone);
                }

                errors.Merge(wordErrors);
            }

            return phones;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:33,代码来源:ScriptSentence.cs

示例15: CompileCharTable

        /// <summary>
        /// Char table compiler.
        /// </summary>
        /// <param name="outputStream">Output Stream.</param>
        /// <returns>ErrorSet.</returns>
        private ErrorSet CompileCharTable(Stream outputStream)
        {
            ErrorSet errorSet = new ErrorSet();

            try
            {
                CharTable charTable = (CharTable)GetObject(RawDataName.CharTable, errorSet);

                ChartableValidator charTableValidator = new ChartableValidator();
                Microsoft.Tts.Offline.Core.Lexicon lexicon = (Microsoft.Tts.Offline.Core.Lexicon)GetObject(RawDataName.Lexicon, errorSet);
                TtsPhoneSet phoneSet = (TtsPhoneSet)GetObject(RawDataName.PhoneSet, errorSet);
                if (!errorSet.Contains(ErrorSeverity.MustFix))
                {
                    charTableValidator.Lexicon = lexicon;
                    charTableValidator.PhoneSet = phoneSet;
                    charTableValidator.EnsureInitialized();

                    if (charTable.Language != charTableValidator.Language)
                    {
                        throw new InvalidDataException("chartable language should match with lexicon or phoneset");
                    }

                    ErrorSet charTableErrors = charTableValidator.Validate(charTable, false, null);
                    foreach (Error error in charTableErrors.Errors)
                    {
                        if (error.Severity == ErrorSeverity.MustFix)
                        {
                            errorSet.Add(DataCompilerError.CompilingLogWithError,
                                RawDataName.CharTable, error.ToString());
                        }
                        else
                        {
                            errorSet.Add(DataCompilerError.CompilingLogWithWarning,
                                RawDataName.CharTable, error.ToString());
                        }
                    }

                    errorSet.Merge(CharTableCompiler.Compile(charTable, phoneSet, outputStream));
                }
            }
            catch (XmlException e)
            {
                errorSet.Add(DataCompilerError.RawDataError, e.Message);
            }

            return errorSet;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:52,代码来源:LangDataCompiler.cs


注:本文中的ErrorSet.Merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。