private void AddToWordlist(string word, Wordlist list)
 {
     if (!string.IsNullOrWhiteSpace(word))
     {
         list?.Add(word);
     }
 }
Exemplo n.º 2
0
        private Wordlist AddItemsToWordlist(Wordlist listOne, Wordlist listTwo)
        {
            if (listTwo != null)
            {
                listOne?.Items.ToList().ForEach(newItem => listTwo.Add(newItem));
            }

            return(listTwo?.Count > 0 ? listTwo : null);
        }
Exemplo n.º 3
0
        private void ReadFromExcel(ExcelWorksheet workSheet, Wordlist abbreviations, Wordlist ordinalFollowers, Wordlist variables, SegmentationRules segmentationRules)
        {
            for (var i = 2; i <= workSheet.Dimension.End.Row; i++)
            {
                abbreviations.Add(workSheet.Cells[i, 1]?.Value?.ToString());
                ordinalFollowers.Add(workSheet.Cells[i, 2]?.Value?.ToString());
                variables.Add(workSheet.Cells[i, 3]?.Value?.ToString());

                var serializedSegmentationRule = workSheet.Cells[i, 4]?.Value?.ToString();

                if (serializedSegmentationRule == null)
                {
                    continue;
                }

                var stringReader  = new StringReader(serializedSegmentationRule);
                var xmlSerializer = new XmlSerializer(typeof(SegmentationRule));

                var segmentationRule = (SegmentationRule)xmlSerializer.Deserialize(stringReader);

                segmentationRules.AddRule(segmentationRule);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Use any of the following parameters:");
                Console.WriteLine($"-lists");
                Console.WriteLine($"-new < listName > < language 1 > < language 2 > .. < langauge n > ");
                Console.WriteLine($"-add < listName > ");
                Console.WriteLine($"-remove < listName > < language > < word 1 > < word 2 > .. < word n > ");
                Console.WriteLine($"-words < listname > < sortByLanguage > ");
                Console.WriteLine($"-count < listName > ");
                Console.WriteLine($"-practice < listName > ");
            }
            else
            {
                foreach (var arg in args)
                {
                    arg.ToLower();
                }

                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Lab4");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string s = args[0];

                switch (s)
                {
                case "-lists":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else
                    {
                        foreach (string list in Lists)
                        {
                            Console.WriteLine(list);
                        }
                    }

                    break;

                case "-new":
                    string message = "A list must contain a name and at least two languages";

                    if (args.Length <= 3)
                    {
                        Console.WriteLine(message);

                        break;
                    }
                    else
                    {
                        Wordlist newList = new Wordlist(args[1], paramsArrNew(args));
                        newList.Save();

                        goto case "-add";
                    }

                case "-add":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else if (!Lists.Contains(args[1]))
                    {
                        Console.WriteLine($"No list with listname '{args[1]}' could be found");
                    }
                    else
                    {
                        Wordlist addtranslations = Wordlist.LoadList(args[1]);

                        int  count = 0;
                        bool loop  = true;

                        Console.WriteLine();
                        Console.WriteLine("Press enter (empty line) to stop input of words");
                        Console.WriteLine();

                        while (loop)
                        {
                            string[] translation = new string[addtranslations.Languages.Length];

                            Console.Write($"Add a new word in '{addtranslations.Languages[0]}': ");
                            string firstWord = Console.ReadLine();
                            if (string.IsNullOrEmpty(firstWord))
                            {
                                loop = false;
                            }
                            else
                            {
                                translation[0] += firstWord;

                                for (int i = 1; i < addtranslations.Languages.Length; i++)
                                {
                                    Console.Write($"Translate '{firstWord}' to '{addtranslations.Languages[i]}': ");
                                    string newWord = Console.ReadLine();
                                    if (string.IsNullOrEmpty(newWord))
                                    {
                                        loop = false;
                                    }
                                    else
                                    {
                                        translation[i] += newWord;
                                    }
                                }

                                addtranslations.Add(translation);
                                translation = null;
                            }

                            count++;
                        }

                        Console.WriteLine();
                        Console.WriteLine($"{count} words was added to '{args[1]}'");
                        Console.WriteLine();

                        addtranslations.Save();
                    }

                    break;

                case "-remove":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else if (args.Length < 4)
                    {
                        Console.WriteLine("The 'remove-command' requires a listname, a language and at least one word to remove");
                    }
                    else if (!Lists.Contains(args[1]))
                    {
                        Console.WriteLine($"No list with listname '{args[1]}' could be found");
                    }
                    else
                    {
                        Wordlist removeWord = Wordlist.LoadList(args[1]);

                        if (!removeWord.Languages.Contains(args[2]))
                        {
                            Console.WriteLine($"'{args[1]}' did not contain the language 'args[2]'");
                        }
                        else
                        {
                            int      val   = 0;
                            string[] words = paramsArrRemove(args);

                            foreach (string word in words)
                            {
                                for (int i = 0; i < removeWord.Languages.Length; i++)
                                {
                                    if (removeWord.Languages[i] == args[2])
                                    {
                                        val = i;
                                    }
                                }

                                if (removeWord.Remove(val, word))
                                {
                                    Console.WriteLine($"{word} has been removed");
                                }
                                else
                                {
                                    Console.WriteLine($"{word} has not been removed because it didn't exist in given list");
                                }

                                removeWord.Save();
                            }
                        }
                    }

                    break;

                case "-words":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else if (args.Length <= 1)
                    {
                        Console.WriteLine("The 'words-command' requires at least a listname");
                    }
                    else if (!Lists.Contains(args[1]))
                    {
                        Console.WriteLine($"No list with listname '{args[1]}' could be found");
                    }
                    else
                    {
                        Wordlist listWords = Wordlist.LoadList(args[1]);

                        Action <string[]> showTranslations = (translations) =>
                        {
                            foreach (string translation in translations)
                            {
                                Console.Write($"{translation,-20}");
                            }

                            Console.WriteLine();
                        };

                        if (args.Length == 3 && listWords.Languages.Contains(args[2]))
                        {
                            foreach (string language in listWords.Languages)
                            {
                                Console.Write($"{language,-20}");
                            }

                            Console.WriteLine();
                            int num = Array.IndexOf(listWords.Languages, args[2]);
                            listWords.List(num, showTranslations);
                        }
                        else if (args.Length == 2)
                        {
                            foreach (string language in listWords.Languages)
                            {
                                Console.Write($"{language,-20}");
                            }

                            Console.WriteLine();
                            listWords.List(0, showTranslations);
                        }
                        else if (!listWords.Languages.Contains(args[2]))
                        {
                            Console.WriteLine($"'{listWords.Name}' doesn't contain any words in '{args[2]}'");
                        }
                    }

                    break;

                case "-count":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else if (args.Length <= 1)
                    {
                        Console.WriteLine("The 'count-command' requires at least a listname");
                    }
                    else if (!Lists.Contains(args[1]))
                    {
                        Console.WriteLine($"No list with listname '{args[1]}' could be found");
                    }
                    else
                    {
                        Wordlist numOfWordsInLanguage = Wordlist.LoadList(args[1]);
                        Console.WriteLine($"The number of words in your list {args[1]} is :{numOfWordsInLanguage.Count()}");
                    }

                    break;

                case "-practice":
                    Lists = Wordlist.GetLists();

                    if (Lists.Length == 0)
                    {
                        Console.WriteLine("No lists have been added");
                    }
                    else if (args.Length <= 1)
                    {
                        Console.WriteLine("The 'practice-command' requires at least a listname");
                    }
                    else if (!Lists.Contains(args[1]))
                    {
                        Console.WriteLine($"No list with listname '{args[1]}' could be found");
                    }
                    else
                    {
                        Wordlist practiceWords = Wordlist.LoadList(args[1]);

                        int correctAnswer  = 0;
                        int wordsPracticed = 0;

                        while (true)
                        {
                            Word     word   = practiceWords.GetWordToPractice();
                            string[] strArr = word.Translations;
                            string   input  = "";

                            Console.WriteLine();
                            Console.Write($"Translate {word.Translations[word.FromLanguage]} to {practiceWords.Languages[word.ToLanguage]}: ");
                            input = Console.ReadLine().ToLower();

                            if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
                            {
                                break;
                            }

                            if (input == word.Translations[word.ToLanguage])
                            {
                                Console.WriteLine("correct answer");
                                correctAnswer++;
                                wordsPracticed++;
                            }
                            else if (input != word.Translations[word.ToLanguage] && !string.IsNullOrEmpty(input) && !string.IsNullOrWhiteSpace(input))
                            {
                                Console.WriteLine("incorrect answer");
                                wordsPracticed++;
                            }
                        }

                        Console.WriteLine("\nPractice has been ended");
                        Console.WriteLine($"\nYou practiced {wordsPracticed} words in total");
                        Console.WriteLine($"You got {correctAnswer} out of {wordsPracticed} correct answers");
                    }

                    break;

                default:
                    Console.WriteLine("There was something wrong with your command");

                    break;
                }
            }
        }
Exemplo n.º 5
0
        public void Add(string[] args)
        {
            if (args.Length == 2)
            {
                string listName = args[1];
                string word     = "";

                try
                {
                    Wordlist wordlist = Wordlist.LoadList(listName);

                    do
                    {
                        Console.WriteLine($"Adding words to wordlist: {listName}.dat");
                        Console.WriteLine("Exit by type empty word!! Your current word will be lost");

                        string[] translation = new string[wordlist.Languages.Length];

                        for (int i = 0; i < wordlist.Languages.Length; i++)
                        {
                            Console.Write($"-Enter the word on {wordlist.Languages[i].ToUpper()}: ");
                            word = Console.ReadLine();

                            if (!word.Equals(""))
                            {
                                if (word.All(char.IsLetter))
                                {
                                    word           = word.ToLower();
                                    translation[i] = word;
                                }
                                else
                                {
                                    throw new Exception("This is not a word.... only use A-Z");
                                }
                            }
                            else
                            {
                                goto start;
                            }
                        }

                        translation = translation.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        wordlist.Add(translation);
                        Console.WriteLine("\n");

                        wordlist.Save();

                        start :;
                    } while (!word.Equals(""));

                    wordlist.Save();
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("List not found");
                    PrintErrorInstructionMessage();
                }
            }
            else
            {
                PrintErrorInstructionMessage();
            }
        }