Example #1
0
        static void Main(string[] args)
        {
            if (args.Length <= 0 || String.IsNullOrEmpty(args[0]))
            {
                Console.WriteLine("Use: name-sorter <filepath>");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("File not found: " + args[0]);
                return;
            }

            IFileController inputFC  = new FileController(args[0]);
            IFileController outputFC = new FileController("./sorted-names-list.txt");
            INameList       nameList = new NameList(inputFC.Read());

            nameList.Sort();

            foreach (var name in nameList.GetAllNames())
            {
                Console.WriteLine(name);
            }
            ;

            outputFC.Write(nameList.GetAllNames());
        }
        public void Initialize(Subtitle subtitle)
        {
            _subtitle = subtitle;

            _language = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle);
            if (string.IsNullOrEmpty(_language))
            {
                _language = "en_US";
            }

            _nameList          = new NameList(Configuration.DictionariesDirectory, _language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            _nameListInclMulti = _nameList.GetAllNames(); // Will contains both one word names and multi names

            FindAllNames();
            if (_language.StartsWith("en", StringComparison.OrdinalIgnoreCase))
            {
                foreach (ListViewItem item in listViewNames.Items)
                {
                    var name = item.SubItems[1].Text;
                    if (name == "US")
                    {
                        item.Checked = false;
                    }
                }
            }

            GeneratePreview();
        }
Example #3
0
        private static void FixCasing(Subtitle subtitle, string language)
        {
            // fix casing normal
            var fixCasing = new FixCasing(language);

            fixCasing.Fix(subtitle);

            // fix casing for names
            var nameList          = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            var nameListInclMulti = nameList.GetAllNames();

            foreach (var paragraph in subtitle.Paragraphs)
            {
                string text       = paragraph.Text;
                string textNoTags = HtmlUtil.RemoveHtmlTags(text, true);
                if (textNoTags != textNoTags.ToUpperInvariant())
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        var st = new StrippableText(text);
                        st.FixCasing(nameListInclMulti, true, false, false, string.Empty);
                        paragraph.Text = st.MergedString;
                    }
                }
            }
        }
Example #4
0
        private void LoadNames(string language, bool reloadListBox)
        {
            var task = Task.Factory.StartNew(() =>
            {
                // names etc
                var nameList = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
                _wordListNames = nameList.GetAllNames();
                _wordListNames.Sort();
                return _wordListNames;
            });

            if (reloadListBox)
            {
                // reload the listbox on a continuation ui thead
                var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
                task.ContinueWith(originalTask =>
                {
                    listViewNames.BeginUpdate();
                    listViewNames.Items.Clear();
                    var list = new List<ListViewItem>();
                    foreach (var item in originalTask.Result)
                    {
                        list.Add(new ListViewItem(item));
                    }
                    listViewNames.Items.AddRange(list.ToArray());
                    listViewNames.EndUpdate();
                }, uiContext);
            }
        }
Example #5
0
        internal void FixCasing(Subtitle subtitle, string language)
        {
            var nameList   = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            var names      = nameList.GetAllNames();
            var subCulture = GetCultureInfoFromLanguage(language);

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

            Paragraph last = null;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (last != null)
                {
                    p.Text = FixCasing(p.Text, last.Text, names, subCulture, p.StartTime.TotalMilliseconds - last.EndTime.TotalMilliseconds);
                }
                else
                {
                    p.Text = FixCasing(p.Text, string.Empty, names, subCulture, 10000);
                }

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

                last = p;
            }
        }
Example #6
0
        public FixCasing(string language)
        {
            _language = language;
            var nameList = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            _names = nameList.GetAllNames();

            // Longer names must be first
            _names.Sort((s1, s2) => s2.Length.CompareTo(s1.Length));
        }
        public void Constructor_NoArgument_EmptyList()
        {
            // Arrange

            // Act
            INameList nameList = new NameList();

            // Assert
            Assert.IsTrue(nameList.GetAllNames().Length == 0);
        }
        public void Constructor_StringArrayArgument_EmptyList()
        {
            // Arrange
            string[] nameArray = { "Name1", "Name2" };

            // Act
            INameList nameList = new NameList(nameArray);

            // Assert
            Assert.IsTrue(nameList.GetAllNames().Length == 2);
        }
        public void AddName_NullString_NoNameAddedToList()
        {
            // Arrange
            INameList nameList = new NameList();
            string    testName = null;

            // Act
            nameList.AddName(testName);

            // Assert
            Assert.IsTrue(nameList.GetAllNames().Length == 0);
        }
        public void Initialize(Subtitle subtitle)
        {
            _subtitle = subtitle;

            _language = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle);
            if (string.IsNullOrEmpty(_language))
            {
                _language = "en_US";
            }

            _nameList          = new NameList(Configuration.DictionariesDirectory, _language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            _nameListInclMulti = _nameList.GetAllNames(); // Will contains both one word names and multi names

            FindAllNames();
            GeneratePreview();
        }
Example #11
0
        private bool StartsWithName(string input, string language)
        {
            if (_names == null)
            {
                var nameList = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
                _names = nameList.GetAllNames();
            }

            if (_names != null)
            {
                foreach (var name in _names)
                {
                    if (input.StartsWith(name + " ", StringComparison.Ordinal) || input.StartsWith(name + ",", StringComparison.Ordinal) || input.StartsWith(name + ":", StringComparison.Ordinal))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #12
0
        private bool StartsWithName(string input, string language)
        {
            if (this._names == null)
            {
                NameList nameList = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
                this._names = nameList.GetAllNames();
            }

            if (this._names != null)
            {
                foreach (string name in this._names)
                {
                    if (input.StartsWith(name + " ") || input.StartsWith(name + ",") || input.StartsWith(name + ":"))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #13
0
        internal void FixCasing(Subtitle subtitle, string language)
        {
            var nameList = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            var names    = nameList.GetAllNames();

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

            string lastLine = string.Empty;

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

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

                lastLine = p.Text;
            }
        }
Example #14
0
        public void SortBySurname_NoDuplicateSurnamesAlreadySorted_SortedCorrectly()
        {
            // Arrange
            string[] nameArray =
            {
                "Order1 Andrews",
                "Order2 Johnson",
                "Order3 Miles",
                "Order4 Peerson",
                "Order5 Wender"
            };
            INameList nameList = new NameList(nameArray);

            // Act
            nameList.Sort();
            var result = nameList.GetAllNames();

            // Assert
            for (int i = 0; i < nameArray.Length; i++)
            {
                Assert.IsTrue(result[i] == nameArray[i]);
            }
        }
        private static Subtitle FixCasing(Subtitle inputSubtitle, string language)
        {
            var subtitle = new Subtitle(inputSubtitle);

            // fix casing normal
            var fixCasing = new FixCasing(language);

            fixCasing.Fix(subtitle);

            // fix casing for names
            var nameList          = new NameList(Configuration.DictionariesDirectory, language, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            var nameListInclMulti = nameList.GetAllNames();

            foreach (var paragraph in subtitle.Paragraphs)
            {
                var text       = paragraph.Text;
                var textNoTags = HtmlUtil.RemoveHtmlTags(text, true);
                if (textNoTags != textNoTags.ToUpperInvariant() && !string.IsNullOrEmpty(text))
                {
                    var st = new StrippableText(text);
                    st.FixCasing(nameListInclMulti, true, false, false, string.Empty);
                    paragraph.Text = st.MergedString;
                }
            }

            // fix german nouns
            if (language == "de")
            {
                var germanNouns = new GermanNouns();
                foreach (var paragraph in subtitle.Paragraphs)
                {
                    paragraph.Text = germanNouns.UppercaseNouns(paragraph.Text);
                }
            }

            return(subtitle);
        }
Example #16
0
        public void SortBySurname_DuplicateSurnames_SortedCorrectly()
        {
            // Arrange
            string[] nameArray =
            {
                "Order2 Johnson",
                "Order3 Miles",
                "Order5 Wender",
                "Order4 Wender",
                "Order1 Andrews"
            };
            INameList nameList = new NameList(nameArray);

            // Act
            nameList.Sort();
            var result = nameList.GetAllNames();

            // Assert
            Assert.IsTrue(result[0] == "Order1 Andrews");
            Assert.IsTrue(result[1] == "Order2 Johnson");
            Assert.IsTrue(result[2] == "Order3 Miles");
            Assert.IsTrue(result[3] == "Order4 Wender");
            Assert.IsTrue(result[4] == "Order5 Wender");
        }