示例#1
0
        /// <summary>
        /// Slice the pronunciation of one script file.
        /// </summary>
        /// <param name="scriptFilePath">Source file.</param>
        /// <param name="targetFilePath">Target file.</param>
        /// <returns>Data error set found.</returns>
        public ErrorSet Slice(string scriptFilePath, string targetFilePath)
        {
            XmlScriptFile script = new XmlScriptFile();
            XmlScriptFile.ContentControler controler = new XmlScriptFile.ContentControler();
            controler.LoadComments = true;
            script.Load(scriptFilePath, controler);

            ErrorSet errorSet = Slice(script);
            script.Save(targetFilePath);

            errorSet.Merge(script.ErrorSet);

            return errorSet;
        }
示例#2
0
        /// <summary>
        /// Remove all slice boundaries in the source script file
        /// And save it to target script file.
        /// </summary>
        /// <param name="sourceScriptFilePath">Source script file.</param>
        /// <param name="targetScriptFilePath">Target script file.</param>
        /// <returns>Data error set found.</returns>
        public static ErrorSet RemoveSliceBoundary(string sourceScriptFilePath,
            string targetScriptFilePath)
        {
            // Parameters validation
            if (string.IsNullOrEmpty(sourceScriptFilePath))
            {
                throw new ArgumentNullException("sourceScriptFilePath");
            }

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

            XmlScriptFile script = new XmlScriptFile();

            // Keep comments in XmlScript file
            XmlScriptFile.ContentControler controler = new XmlScriptFile.ContentControler();
            controler.LoadComments = true;
            script.Load(sourceScriptFilePath, controler);

            foreach (ScriptItem item in script.Items)
            {
                foreach (ScriptWord word in item.AllWords)
                {
                    if (!string.IsNullOrEmpty(word.Pronunciation))
                    {
                        word.Pronunciation = Pronunciation.RemoveUnitBoundary(word.Pronunciation);
                    }
                }
            }

            // Save comments in XmlScript file
            script.Save(targetScriptFilePath, Encoding.Unicode);

            return script.ErrorSet;
        }
示例#3
0
        /// <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;
        }