Пример #1
0
        internal void FixCasing(Subtitle subtitle, string language)
        {
            var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            var namesEtc = namesList.GetAllNames();

            // Longer names must be first
            namesEtc.Sort((s1, s2) => s2.Length.CompareTo(s1.Length));

            string lastLine = string.Empty;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                p.Text = FixCasing(p.Text, lastLine, namesEtc);

                // fix casing of English alone i to I
                if (radioButtonNormal.Checked && language.StartsWith("en", StringComparison.Ordinal))
                {
                    p.Text = FixEnglishAloneILowerToUpper(p.Text);
                }

                lastLine = p.Text;
            }
        }
Пример #2
0
        private void MakeSureNamesListIsLoaded()
        {
            if (_namesEtcList == null)
            {
                _namesEtcList = new List<string>();
                string languageTwoLetterCode = Utilities.AutoDetectGoogleLanguage(Subtitle);

                // Will contains both one word names and multi names
                var namesList = new NamesList(Configuration.DictionariesFolder, languageTwoLetterCode, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
                _namesEtcList = namesList.GetAllNames();
            }
        }
Пример #3
0
        private void LoadNamesEtc(string language, bool reloadListBox)
        {
            var task = Task.Factory.StartNew(() =>
            {
                // names etc
                var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
                _wordListNamesEtc = namesList.GetAllNames();
                _wordListNamesEtc.Sort();
                return _wordListNamesEtc;
            });

            if (reloadListBox)
            {
                // reload the listbox on a continuation ui thead
                var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
                task.ContinueWith(originalTask =>
                {
                    listBoxNamesEtc.BeginUpdate();
                    listBoxNamesEtc.Items.Clear();
                    foreach (var name in originalTask.Result)
                    {
                        listBoxNamesEtc.Items.Add(name);
                    }
                    listBoxNamesEtc.EndUpdate();
                }, uiContext);
            }
        }
Пример #4
0
        private void FindAllNames()
        {
            string language = LanguageAutoDetect.AutoDetectLanguageName("en_US", _subtitle);
            if (string.IsNullOrEmpty(language))
                language = "en_US";

            var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);

            // Will contains both one word names and multi names
            var namesEtcList = namesList.GetAllNames();

            if (language.StartsWith("en", StringComparison.Ordinal))
            {
                namesEtcList.Remove("Black");
                namesEtcList.Remove("Bill");
                namesEtcList.Remove("Long");
                namesEtcList.Remove("Don");
            }

            var sb = new StringBuilder();
            foreach (Paragraph p in _subtitle.Paragraphs)
                sb.AppendLine(p.Text);
            string text = HtmlUtil.RemoveHtmlTags(sb.ToString());
            string textToLower = text.ToLower();
            listViewNames.BeginUpdate();
            foreach (string name in namesEtcList)
            {
                int startIndex = textToLower.IndexOf(name.ToLower(), StringComparison.Ordinal);
                if (startIndex >= 0)
                {
                    while (startIndex >= 0 && startIndex < text.Length &&
                           textToLower.Substring(startIndex).Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower())
                    {
                        bool startOk = (startIndex == 0) || (text[startIndex - 1] == ' ') || (text[startIndex - 1] == '-') ||
                                       (text[startIndex - 1] == '"') || (text[startIndex - 1] == '\'') || (text[startIndex - 1] == '>') ||
                                       (Environment.NewLine.EndsWith(text[startIndex - 1].ToString(CultureInfo.InvariantCulture)));

                        if (startOk)
                        {
                            int end = startIndex + name.Length;
                            bool endOk = end <= text.Length;
                            if (endOk)
                                endOk = end == text.Length || ExpectedEndChars.Contains(text[end]);

                            if (endOk && text.Substring(startIndex, name.Length) != name) // do not add names where casing already is correct
                            {
                                if (!_usedNames.Contains(name))
                                {
                                    _usedNames.Add(name);
                                    AddToListViewNames(name);
                                    break; // break while
                                }
                            }
                        }

                        startIndex = textToLower.IndexOf(name.ToLower(), startIndex + 2, StringComparison.Ordinal);
                    }
                }
            }
            listViewNames.EndUpdate();
            groupBoxNames.Text = string.Format(Configuration.Settings.Language.ChangeCasingNames.NamesFoundInSubtitleX, listViewNames.Items.Count);
        }