/// <summary> /// Initiates Training object /// Select amount of words from dictionary to learn /// </summary> /// <param name="dictionary">Dictionary with word cards</param> /// <param name="isSwitched">Switch words in card</param> /// <param name="amount">Amount of cards to learn</param> /// <param name="maxCounter">Max counter value</param> /// <param name="type">Training type</param> /// <param name="learnedBefore">If true, Select only words that were learned in previous training type</param> public Training(WordsDictionary dictionary, bool isSwitched, int amount, int maxCounter, TrainingType type, bool learnedBefore) { this.dictionary = dictionary; this.type = type; // switch all cards if needed if (isSwitched) { foreach (var card in dictionary) card.Switched = isSwitched; } IEnumerable<WordCard> cardsList = dictionary; // get learned cards from prevois training type if (learnedBefore && type != 0) { cardsList = from c in cardsList where c.Counter1[type - 1] >= maxCounter select c; } // select cards that have counter less than maxCounter for specific training type cardsList = ( from c in cardsList where c.Counter1[type] < maxCounter orderby c.LastTrained select c) .Take(amount); cardsToLearn = cardsList.ToList(); }
private void GenerateDictionaryWords() { words.Clear(); for (int i = 0; i < wordsCount; i++) { words.Add(WordsDictionary.GetRandomWord()); } }
private static string FindFromDictionary(string command, WordsDictionary redisDictionary) { int wordStartIndex = command.IndexOf(' ') + 1; string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim(); return word + " -> " + redisDictionary[word]; }
private static void RemoveFromDictionary(string command, WordsDictionary redisDictionary) { int wordStartIndex = command.IndexOf(' ') + 1; string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim(); redisDictionary.Remove(word); Console.WriteLine("Word is removed successfully."); }
public void SetUp() { maxCards = random.Next(5, 100); dictionary = new WordsDictionary(language1, language2); for (int i = 0; i < maxCards / 2; i++) { dictionary.Add(generator.GetCard()); } }
public void SetUp() { maxCards = random.Next(3, 100); dictionary = new WordsDictionary(language1, language2); for (int i = 0; i < maxCards; i++) { dictionary.Add(generator.GetCardExtra(5)); } trainingType = trainingTypeList[random.Next(trainingTypeList.Count)]; }
/// <summary> /// Read Dictionary from xml file /// Returns Dictionary /// </summary> /// <returns>WordsDictionary</returns> public override WordsDictionary Read() { XDocument xd = XDocument.Load(pathToXml); WordsDictionary dictionary = new WordsDictionary(xd.Root.Attribute(strLang1).Value, xd.Root.Attribute(strLang2).Value); foreach (XElement cardXml in xd.Root.Elements(strCard)) { XElement word1Xml = cardXml.Element(strLang1); XElement word2Xml = cardXml.Element(strLang2); // create word card class string word1 = word1Xml.Element(strWordText).Value; string word2 = word2Xml.Element(strWordText).Value; string type = cardXml.Attribute(strWordType).Value; WordCard card = new WordCard(word1, word2, (WordType)Enum.Parse(typeof(WordType), type)); // set counter and comment for word1 foreach (XElement counter in word1Xml.Element(strCounters).Elements(strCounter)) { TrainingType trainingType = (TrainingType)Enum.Parse(typeof(TrainingType), counter.Attribute(strCounterType).Value, true); card.Counter1[trainingType] = int.Parse(counter.Attribute(strCounterValue).Value); } XElement commentXml = word1Xml.Element(strComment); if (commentXml != null) card.Comment1 = commentXml.Value; // set counter and comment for word2 foreach (XElement counter in word2Xml.Element(strCounters).Elements(strCounter)) { TrainingType trainingType = (TrainingType)Enum.Parse(typeof(TrainingType), counter.Attribute(strCounterType).Value, true); card.Counter2[trainingType] = int.Parse(counter.Attribute(strCounterValue).Value); } commentXml = word2Xml.Element(strComment); if (commentXml != null) card.Comment2 = commentXml.Value; // set common comment commentXml = cardXml.Element(strComment); if (commentXml != null) card.CommentCommon = commentXml.Value; XElement lastTrained = cardXml.Element(strLastTrained); if (lastTrained != null) { DateTime time = DateTime.Now; if (DateTime.TryParse(lastTrained.Value, out time)) card.LastTrained = time; } dictionary.Add(card); } return dictionary; }
public void SetUp() { maxCards = random.Next(5, 10); cardsToChoose = random.Next(1, maxCards - 1); dictionary = new WordsDictionary(language1, language2); for (int i = 0; i < maxCards; i++) { dictionary.Add(generator.GetCardExtra(maxCounter)); } isSwitched = random.Next(1) == 1; }
public void SetUp() { maxCards = random.Next(3, 100); dictionary = new WordsDictionary(language1, language2); for (int i = 0; i < maxCards; i++) { dictionary.Add(generator.GetCardExtra(5)); } dataLayer.Save(dictionary); }
private static void AddToDictionary(string command, WordsDictionary redisDictionary) { int wordStartIndex = command.IndexOf(' ') + 1; int wordEndIndex = command.IndexOf('-'); string word = command.Substring(wordStartIndex, wordEndIndex - wordStartIndex).Trim(); string translation = command.Substring(wordEndIndex + 1).Trim(); redisDictionary.Add(word, translation); Console.WriteLine("Word is added successfully."); }
private static void Main(string[] args) { WordsDictionary dictionary = new WordsDictionary(); dictionary.Build("words.txt"); string input; while ((input = Console.ReadLine()) != "") { Console.WriteLine(string.Join(", ", dictionary.GetWords(input))); } }
public void TestSaveReadTwice() { XmlDataLayer doc = new XmlDataLayer(pathToXml); doc.Save(dictionary); var dictionaryRead = doc.Read(); ValidatingDictionaries(dictionary, dictionaryRead); dictionary = dictionaryRead; dictionary[0].Word1 = "qwer"; dictionary[1].CommentCommon = "asdf"; doc.Save(dictionary); dictionaryRead = doc.Read(); ValidatingDictionaries(dictionary, dictionaryRead); }
private static void ListAllFromDictionary(WordsDictionary redisDictionary) { if (redisDictionary.Count > 0) { foreach (var item in redisDictionary) { Console.WriteLine("{0} -> {1}", item.Name, item.Translation); } } else { Console.WriteLine("There are no words in the dictionary."); } }
public override bool AddDictionary(string name, string lang1, string lang2) { DictionaryInfo check = GetDictionary(name); if (check != null) return false; WordsDictionary dictionary = new WordsDictionary(lang1, lang2); dictionary.Add(new WordCard("Hello", "Hello", WordType.Noun)); // HACK: DataLayer data = new XmlDataLayer(GetFullPath(name)); data.Save(dictionary); DictionaryInfo dictionaryInfo = new DictionaryInfo(name, data); Dictionaries.Add(dictionaryInfo); return true; }
public WordFrequencyList(string name, IDictionaryStream stream) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Value cannot be null or empty.", nameof(name)); } Name = name; var dictionary = WordsDictionary.Construct(stream); int index = 0; foreach (var item in dictionary.RawData.OrderByDescending(item => item.Value)) { index++; indexTable[item.Key] = new FrequencyInformation(item.Key, index, item.Value); } }
private WordTypeResolver() { conjunctiveAdverbs = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Conjunctions.ConjunctiveAdverb.txt", new EmbeddedStreamSource <WordTypeResolver>())); coordinatingConjunctions = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Conjunctions.CoordinatingConjunction.txt", new EmbeddedStreamSource <WordTypeResolver>())); subordinateConjunction = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Conjunctions.SubordinateConjunction.txt", new EmbeddedStreamSource <WordTypeResolver>())); invertingConjunction = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Conjunctions.InvertingConjunction.txt", new EmbeddedStreamSource <WordTypeResolver>())); regularConjunction = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Conjunctions.RegularConjunction.txt", new EmbeddedStreamSource <WordTypeResolver>())); adverbs = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Adverb.txt", new EmbeddedStreamSource <WordTypeResolver>())); adjective = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Adjective.txt", new EmbeddedStreamSource <WordTypeResolver>())); article = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Article.txt", new EmbeddedStreamSource <WordTypeResolver>())); noun = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Noun.txt", new EmbeddedStreamSource <WordTypeResolver>())); preposition = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Preposition.txt", new EmbeddedStreamSource <WordTypeResolver>())); pronoun = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Pronoun.txt", new EmbeddedStreamSource <WordTypeResolver>())); verb = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Verb.txt", new EmbeddedStreamSource <WordTypeResolver>())); question = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Questions.txt", new EmbeddedStreamSource <WordTypeResolver>())); stop = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.Stop.txt", new EmbeddedStreamSource <WordTypeResolver>())); invertor = WordsDictionary.Construct(new DictionaryStream(@"Resources.POS.negating.txt", new EmbeddedStreamSource <WordTypeResolver>())); }
static void Main() { const string DictionaryName = "DictionaryDb"; using (RedisClient client = new RedisClient()) { PrintMenu(); var redisDictionary = new WordsDictionary(client, DictionaryName); while (true) { Console.Write("Please enter a command: "); string command = Console.ReadLine().Trim(); if (command == "Exit") { Console.WriteLine("Goodbye. : ) "); break; } CommandExecutor.ExecuteCommand(command, redisDictionary); } } }
public static void ExecuteCommand(string command, WordsDictionary redisDictionary) { int commandEndIndex = command.IndexOf(' '); string parsedCommand = command.Substring(0, commandEndIndex).Trim(); switch (parsedCommand) { case "Add": { AddToDictionary(command, redisDictionary); break; } case "Remove": { RemoveFromDictionary(command, redisDictionary); break; } case "Find": { string result = FindFromDictionary(command, redisDictionary); Console.WriteLine(result); break; } case "List": { ListAllFromDictionary(redisDictionary); break; } default: { Console.WriteLine("Wrong command. Try again."); break; } } }
// show training setteings view // hide training view private void TrainingView_Loaded(object sender, RoutedEventArgs e) { trainingTest.Visibility = Visibility.Collapsed; trainingSetting.Visibility = Visibility.Collapsed; if (App.SelectedDictionary != null) { dictionary = App.SelectedDictionary.Dictionary; DataContext = this; languages.Clear(); languages.Add(Model.Language.Lang1, dictionary.Language1); languages.Add(Model.Language.Lang2, dictionary.Language2); SetDirectionText(dictionary); trainingSetting.Visibility = Visibility.Visible; trainingSetting.IsEnabled = true; DecreaseOnFail = true; LearnedBefore = true; } }
public void TestWordsDictionaryInitFailed1() { dictionary = new WordsDictionary(null, language2); }
private void ValidatingDictionaries(WordsDictionary expected, WordsDictionary actual) { Assert.AreEqual(expected.Count, actual.Count, "Validating read dictionary size"); Assert.AreEqual(expected.Language1, actual.Language1, "Validating Language1"); Assert.AreEqual(expected.Language2, actual.Language2, "Validating Language2"); for (int i = 0; i < expected.Count; i++) { WordCard cardExpected = expected[i]; WordCard cardActual = actual[i]; Assert.AreEqual(cardExpected, cardActual, "Validating card " + i + " words"); Assert.AreEqual(cardExpected.CommentCommon, cardActual.CommentCommon, "Validating common comment for card " + i); Assert.AreEqual(cardExpected.Comment1, cardActual.Comment1, "Validating comment1 for card " + i); Assert.AreEqual(cardExpected.Comment2, cardActual.Comment2, "Validating comment2 for card " + i); } }
public static void ReplaceWordByRandomOn(int index) { words[index] = WordsDictionary.GetRandomWord(); }
public void TestWordsDictionaryInitFailed2() { dictionary = new WordsDictionary(language1, ""); }
/// <summary> /// Save Dictionary to xml file /// </summary> /// <param name="dictionary">Dictionary to save</param> public override void Save(WordsDictionary dictionary) { XDocument xd = new XDocument(); xd.Declaration = new XDeclaration("1.0", "utf-8", ""); XElement root = new XElement(strRoot, new XAttribute(strLang1, dictionary.Language1), new XAttribute(strLang2, dictionary.Language2)); xd.Add(root); // iterate over each card and add it to xml foreach (var card in dictionary) { // switch back all cards, that could be switched during training card.Switched = false; XElement wordCard = new XElement(strCard, new XAttribute(strWordType, card.Type.ToString())); XElement word1 = GetWordNode(card.Word1, card.Comment1, card.Counter1, strLang1); wordCard.Add(word1); XElement word2 = GetWordNode(card.Word2, card.Comment2, card.Counter2, strLang2); wordCard.Add(word2); if (card.CommentCommon != null) { XElement comment = new XElement(strComment, card.CommentCommon); wordCard.Add(comment); } XElement lastTrained = new XElement(strLastTrained, card.LastTrained); wordCard.Add(lastTrained); root.Add(wordCard); } xd.Save(pathToXml); }
// set direction text on label private void SetDirectionText(WordsDictionary dictionary) { if (dictionary != null) { lbDirection.Text = languages[langFrom] + " -> " + languages[langTo]; } }
public override void Save(WordsDictionary dictionary) { this.dictionary = dictionary; }
// count amount of words with specified counter in dictionary private int CountWordsByCounter(WordsDictionary dictionary, CounterFilterType type, int counter) { int count = 0; foreach (var item in dictionary) { if (type == CounterFilterType.Equals) { if (item.Counter1[trainingType] == counter || item.Counter2[trainingType] == counter) count++; } else if (type == CounterFilterType.More) { if (item.Counter1[trainingType] > counter || item.Counter2[trainingType] > counter) count++; } else if (type == CounterFilterType.Less) { if (item.Counter1[trainingType] < counter || item.Counter2[trainingType] < counter) count++; } } return count; }
// count amount of words with specified word in dictionary private int CountWordsByWord(WordsDictionary dictionary, string word) { int count = 0; foreach (var card in dictionary) { if (card.Word1.ToLower().Contains(word.ToLower()) || card.Word2.ToLower().Contains(word.ToLower())) count++; } return count; }
public void SetUp() { maxCards = random.Next(3, 100); dictionary = new WordsDictionary(language1, language2); }
public AddNewWordToList(WordsDictionary parent) { InitializeComponent(); Parent = parent; }
// count amount of words with specified type in dictionary private int CountWordsByType(WordsDictionary dictionary, WordType type) { int count = 0; foreach (var card in dictionary) { if (card.Type == type) count++; } return count; }
abstract public void Save(WordsDictionary dictionary);
public void SetUp() { Directory.CreateDirectory(folder); dictionary = new WordsDictionary("Lang1", "Lang2"); dictionary.Add(new WordCard("Hi", "World", WordType.Noun)); }